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