Skip to content

Instantly share code, notes, and snippets.

@niektemme
Created July 31, 2015 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niektemme/24b89e849ea2d98f6f9a to your computer and use it in GitHub Desktop.
Save niektemme/24b89e849ea2d98f6f9a to your computer and use it in GitHub Desktop.
Smart Thermostat Raspberry PI - part XBee send
def xinsert():
"""
Receives and sends data from and to the XBee.
Sending and receiving combined in one thread because only one tread can use GPIO port.
Recieving is done as fast as possible.
Sinding only at 1 second interval.
Runs as a sperate thread.
"""
ficurtime = 0
fivepoch = 0
fiprevepcoh = 0
ficursource = '40b5af01' #device id of raspberry pi only used for logging
DEST_ADDR_LONG = "\x00\x13\xA2\x00@\xB5\xAF\x00" #destination adress currently fixed value
while True:
logging.debug("insert started")
logging.debug(datetime.datetime.utcnow())
try:
...
#send at 1 second interval
if fivepoch > fiprevepcoh:
fiprevepcoh = fivepoch
dbd11 = dbc.cursor()
dbd11.execute("SELECT vsendmes from sendmes where vepoch > %i order by vepoch desc,vsub desc LIMIT 1" % fimintime)
rows = dbd11.fetchall()
for row in rows:
fipayload = row[0]
xbee.tx(dest_addr='\x00\x00',dest_addr_long=DEST_ADDR_LONG,data=str(fipayload),frame_id='\x01') #send trought XBee
fins(ficurtime,ficursource,'rx000B04',int('9'+str(fipayload))) #logging of send message in hsensvals table
dbd11.close()
except Exception:
logging.exception("fxinsert")
time.sleep(0.001)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment