Skip to content

Instantly share code, notes, and snippets.

@Ajak58a
Created June 22, 2021 02:32
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 Ajak58a/9111244336b13c1f49a95f2aad93b793 to your computer and use it in GitHub Desktop.
Save Ajak58a/9111244336b13c1f49a95f2aad93b793 to your computer and use it in GitHub Desktop.
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