energenie.loop() written with FSK receiver connected to fsk_router
1 parent ebbc48d commit b5a7e7a85d4a9e32a55b9e63976966bdccb513b3
@David Whale David Whale authored on 24 May 2016
Showing 2 changed files
View
4
src/energenie/Registry.py
print("ignored payload: %s" % payload)
 
 
fsk_router = Router("fsk")
ook_router = Router("ook")
#OOK receive not yet written
##ook_router = Router("ook")
 
 
 
# END
View
31
src/energenie/__init__.py
# At the moment, this just hides the fact that the radio module needs to be initialised
# at the start and cleaned up at the end.
#
# Future versions of this *might* also start receive monitor or scheduler threads.
 
import time
 
try:
# Python 3
from . import radio
radio.init()
OpenThings.init(Devices.CRYPT_PID)
 
 
def loop(receive_time=1):
"""Handle receive processing"""
radio.receiver(fsk=True)
timeout = time.time() + receive_time
handled = False
 
while True:
if radio.is_receive_waiting():
payload = radio.receive_cbp()
now = time.time()
try:
msg = OpenThings.decode(payload, receive_timestamp=now)
hdr = msg["header"]
mfr_id = hdr["mfrid"]
product_id = hdr["productid"]
device_id = hdr["sensorid"]
address = (mfr_id, product_id, device_id)
 
Registry.fsk_router.handle_message(address, payload)
handled = True
except OpenThings.OpenThingsException:
print("Can't decode payload:%s" % payload)
 
now = time.time()
if now > timeout: break
 
return handled
 
 
def finished():
"""Cleanly close the Energenie system when finished"""
radio.finished()