[go: nahoru, domu]

Skip to content

Commit

Permalink
Option of pre-timestamped data
Browse files Browse the repository at this point in the history
Currently only implemented fully in the socket interfacer. There is now
the option to override the default behaviour of automatically adding a
timestamp on arrival by using "timestamped = True" ("False" by default
when omited). This enables pre-timestamped data retrieved from modbus
devices etc to retain an existing timestamp or for historitc data to be
input via a websocket etc. Any custon interfacers can implement their
own "timestamping" or leave it to emonhub to timestamp with current
time.
  • Loading branch information
pb66 committed Nov 2, 2014
1 parent 9cb0a18 commit ece846e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/emonhub_interfacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, name):
# Initialise settings
self.name = name
self.init_settings = {}
self._defaults = {'pause': 'off', 'interval': 0, 'datacode': '0'}
self._defaults = {'pause': 'off', 'interval': 0, 'datacode': '0', 'timestamped': 'False'}
self._settings = {}
self._packet_counter = 0

Expand Down Expand Up @@ -258,6 +258,8 @@ def set(self, **kwargs):
pass
elif key == 'datacode' and str(setting) in ['0', 'b', 'B', 'h', 'H', 'L', 'l', 'f']:
pass
elif key == 'timestamped' and str(setting).lower() in ['true', 'false']:
pass
else:
self._log.warning("'%s' is not a valid setting for %s: %s" % (str(setting), self.name, key))
continue
Expand Down Expand Up @@ -670,7 +672,13 @@ def read(self):
if '\r\n' in self._sock_rx_buf:
# Process and return first frame in buffer:
f, self._sock_rx_buf = self._sock_rx_buf.split('\r\n', 1)
return self._process_frame(f)
if str(self._settings['timestamped']).lower() == "true":
f = f.split(" ")
t = float(f[0])
f = ' '.join(map(str, f[1:]))
return self._process_frame(f, t)
else:
return self._process_frame(f)

"""class EmonHubInterfacerInitError
Expand Down

0 comments on commit ece846e

Please sign in to comment.