Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fn_callbacks.py
from devices import *
def Device_1(client, userdata, msg):
#print "device1:"+str(msg.payload)
global devices_names_live
global devices_names_debug
global devices_names_sensor
message = str(msg.payload)
#print message
if("on" in message.lower()):
devices_names_live[0] = "ONLINE"
if("off" in message.lower()):
devices_names_live[0] = "OFFLINE"
if("debug:" in message):
command = message.replace("debug:","")
devices_names_debug[0] = command
if("sensor:" in message):
command = message.replace("sensor:","")
devices_names_sensor[0] = command
def Device_2(client, userdata, msg):
global devices_names_live
global devices_names_debug
global devices_names_sensor
#print "device2:"+str(msg.payload)
message = str(msg.payload)
#print message
if("on" in message.lower()):
devices_names_live[1] = "ONLINE"
if("off" in message.lower()):
devices_names_live[1] = "OFFLINE"
if("debug:" in message):
command = message.replace("debug:","")
devices_names_debug[1] = command
if("sensor:" in message):
command = message.replace("sensor:","")
devices_names_sensor[1] = command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment