diff --git a/src/energenie/OpenThings.py b/src/energenie/OpenThings.py index 7dc3862..a8516f6 100644 --- a/src/energenie/OpenThings.py +++ b/src/energenie/OpenThings.py @@ -3,6 +3,7 @@ # Implement OpenThings message encoding and decoding import crypto +import time class OpenThingsException(Exception): def __init__(self, value): @@ -570,7 +571,7 @@ return rem -def showMessage(msg): +def showMessage(msg, timestamp=None): """Show the message in a friendly format""" # HEADER @@ -578,6 +579,8 @@ mfrid = header["mfrid"] productid = header["productid"] sensorid = header["sensorid"] + if timestamp != None: + print("receive-time:%s" % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))) print("mfrid:%s prodid:%s sensorid:%s" % (hex(mfrid), hex(productid), hex(sensorid))) # RECORDS diff --git a/src/monitor.py b/src/monitor.py index 9dbf3ce..dcaff84 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -10,7 +10,7 @@ # to a CSV log file, so could be the basis for a non-controlling energy logging app. from energenie import Registry, Devices, Messages, OpenThings, radio - +import time import Logger def warning(msg): @@ -35,11 +35,12 @@ payload = radio.receive() try: decoded = OpenThings.decode(payload) + now = time.time() except OpenThings.OpenThingsException as e: warning("Can't decode payload:" + str(e)) continue - OpenThings.showMessage(decoded) + OpenThings.showMessage(decoded, timestamp=now) # Any device that reports will be added to the non-persistent directory Registry.update(decoded) ##trace(decoded) diff --git a/src/switch.py b/src/switch.py index 2c6c2ef..2fece13 100644 --- a/src/switch.py +++ b/src/switch.py @@ -10,6 +10,7 @@ # Don't expect this to be a good starting point for an application. # Consider waiting for me to finish developing the device object interface first. +import time from energenie import Devices, Messages, Registry, OpenThings, radio from Timer import Timer @@ -39,11 +40,12 @@ payload = radio.receive() try: decoded = OpenThings.decode(payload) + now = time.time() except OpenThings.OpenThingsException as e: warning("Can't decode payload:" + str(e)) return - OpenThings.showMessage(decoded) + OpenThings.showMessage(decoded, timestamp=now) # Any device that reports will be added to the non-persistent directory Registry.update(decoded) ##trace(decoded)