Fix pulse output
This commit is contained in:
parent
605b8c2c4a
commit
67ce0f4352
|
|
@ -1,7 +1,7 @@
|
|||
"""
|
||||
|
||||
This code is released under the GNU Affero General Public License.
|
||||
|
||||
|
||||
OpenEnergyMonitor project:
|
||||
http://openenergymonitor.org
|
||||
|
||||
|
|
@ -18,12 +18,12 @@ import ssl
|
|||
import base64
|
||||
|
||||
import emonhub_buffer as ehb
|
||||
|
||||
|
||||
"""class EmonHubReporter
|
||||
|
||||
Stores server parameters and buffers the data between two HTTP requests
|
||||
|
||||
This class is meant to be inherited by subclasses specific to their
|
||||
This class is meant to be inherited by subclasses specific to their
|
||||
destination server.
|
||||
|
||||
"""
|
||||
|
|
@ -62,7 +62,7 @@ class EmonHubReporter(threading.Thread):
|
|||
# number of items posted is the lower of this item limit, buffer_size, or the
|
||||
# batchsize, as set in reporter settings or by the default value.
|
||||
self._item_limit = buffer_size
|
||||
|
||||
|
||||
self._log.info("Set up reporter '%s' (buffer: %s | size: %s)"
|
||||
% (reporterName, buffer_type, buffer_size))
|
||||
|
||||
|
|
@ -73,12 +73,12 @@ class EmonHubReporter(threading.Thread):
|
|||
# Initialise a thread and start the reporter
|
||||
self.stop = False
|
||||
self.start()
|
||||
|
||||
|
||||
def set(self, **kwargs):
|
||||
"""Update settings.
|
||||
|
||||
|
||||
**kwargs (dict): runtime settings to be modified.
|
||||
|
||||
|
||||
url (string): eg: 'http://localhost/emoncms' or 'http://emoncms.org' (trailing slash optional)
|
||||
apikey (string): API key with write access
|
||||
pause (string): pause status
|
||||
|
|
@ -86,7 +86,7 @@ class EmonHubReporter(threading.Thread):
|
|||
'pause' = in pauses the input only, no add to buffer but flush still functional
|
||||
'pause' = out pauses output only, no flush but data can accumulate in buffer
|
||||
'pause' = off pause is off and reporter is fully operational
|
||||
|
||||
|
||||
"""
|
||||
|
||||
for key, setting in self._defaults.iteritems():
|
||||
|
|
@ -186,7 +186,7 @@ class EmonHubReporter(threading.Thread):
|
|||
|
||||
def flush(self):
|
||||
"""Send oldest data in buffer, if any."""
|
||||
|
||||
|
||||
# Buffer management
|
||||
# If data buffer not empty, send a set of values
|
||||
if self.buffer.hasItems():
|
||||
|
|
@ -234,7 +234,7 @@ class EmonHubReporter(threading.Thread):
|
|||
if post_header is not None:
|
||||
base64string = base64.encodestring('simon:bajsa').replace('\n', '')
|
||||
request.add_header("Authorization", "Basic %s" % base64string)
|
||||
|
||||
|
||||
try:
|
||||
response = urllib2.urlopen(request, timeout=60, context=self._ctx)
|
||||
except urllib2.HTTPError as e:
|
||||
|
|
@ -304,11 +304,11 @@ class EmonHubDomoticzReporter(EmonHubReporter):
|
|||
continue
|
||||
else:
|
||||
self._log.warning("'%s' is not valid for %s: %s" % (setting, self.name, key))
|
||||
|
||||
|
||||
|
||||
def _process_post(self, databuffer):
|
||||
"""Send data to server."""
|
||||
|
||||
|
||||
# databuffer is of format:
|
||||
# [[timestamp, nodeid, datavalues][timestamp, nodeid, datavalues]]
|
||||
# [[1399980731, 10, 150, 250 ...]]
|
||||
|
|
@ -317,20 +317,20 @@ class EmonHubDomoticzReporter(EmonHubReporter):
|
|||
status = False
|
||||
post_body = None
|
||||
post_header = "%s:%s" %('simon', 'bajsa')
|
||||
|
||||
|
||||
|
||||
for data in databuffer:
|
||||
data = data[2:]
|
||||
data = data[2:]
|
||||
#valid = False
|
||||
#[ext_temp, temp, hum, batteri, pulse, rssi]
|
||||
self._log.debug(self.name + "data %s" %data)
|
||||
ext_temp = data[0] * 0.1
|
||||
temp = data[1] * 0.1
|
||||
hum = data[2] * 0.1
|
||||
batteri = data[3]
|
||||
pulse = data[4]
|
||||
rssi = abs(data[5])
|
||||
|
||||
batteri = data[3]
|
||||
pulse = data[4]
|
||||
rssi = abs(data[5])
|
||||
|
||||
domoAddParam = '&battery=%s' %(batteri)
|
||||
if temp < 84:
|
||||
domoTempHum = '/json.htm?type=command¶m=udevice&idx=56&nvalue=0&svalue=%s;%s;%s' %(temp,hum,0)
|
||||
|
|
@ -346,10 +346,10 @@ class EmonHubDomoticzReporter(EmonHubReporter):
|
|||
self._log.info(self.name + " sending: " + post_url_temp)
|
||||
reply = self._send_post(post_url_temp, post_body, post_header)
|
||||
|
||||
domoPulse = '/json.htm?type=command¶m=udevice&idx=54&svalue=%s' %(pulse)
|
||||
post_url_pulse = self._settings['url'] + domoPulse + domoAddParam
|
||||
self._log.info(self.name + " sending: " + post_url_pulse)
|
||||
|
||||
if domoPulse > 100:
|
||||
domoPulse = '/json.htm?type=command¶m=udevice&idx=54&svalue=%s' %(pulse)
|
||||
post_url_pulse = self._settings['url'] + domoPulse + domoAddParam
|
||||
self._log.info(self.name + " sending: " + post_url_pulse + " pulse: " + pulse)
|
||||
|
||||
# The Develop branch of emoncms allows for the sending of the apikey in the post
|
||||
# body, this should be moved from the url to the body as soon as this is widely
|
||||
|
|
@ -357,11 +357,11 @@ class EmonHubDomoticzReporter(EmonHubReporter):
|
|||
|
||||
reply = self._send_post(post_url_pulse, post_body, post_header)
|
||||
|
||||
status = True
|
||||
status = True
|
||||
|
||||
self._log.debug(self.name + " Next return" )
|
||||
if status:
|
||||
return True
|
||||
return True
|
||||
self._log.debug(self.name + " After return" )
|
||||
|
||||
"""class EmonHubEmoncmsReporter
|
||||
|
|
@ -434,7 +434,7 @@ class EmonHubEmoncmsReporter(EmonHubReporter):
|
|||
|
||||
def _process_post(self, databuffer):
|
||||
"""Send data to server."""
|
||||
|
||||
|
||||
# databuffer is of format:
|
||||
# [[timestamp, nodeid, datavalues][timestamp, nodeid, datavalues]]
|
||||
# [[1399980731, 10, 150, 250 ...]]
|
||||
|
|
@ -444,7 +444,7 @@ class EmonHubEmoncmsReporter(EmonHubReporter):
|
|||
return
|
||||
|
||||
data_string = json.dumps(databuffer, separators=(',', ':'))
|
||||
|
||||
|
||||
# Prepare URL string of the form
|
||||
# http://domain.tld/emoncms/input/bulk.json?apikey=12345
|
||||
# &data=[[0,10,82,23],[5,10,82,23],[10,10,82,23]]
|
||||
|
|
|
|||
Loading…
Reference in New Issue