fixed up the apps

pull/38/head
Lateefah Bello 4 years ago
parent 1ca651d70b
commit c3a6c9075f

@ -6,8 +6,8 @@ import paho.mqtt.client as mqtt
id = '<ID>' id = '<ID>'
client_telemetry_topic = id + '/telemetry' client_telemetry_topic = id + '/telemetry'
client_name = id + 'nightlight_server'
server_command_topic = id + '/commands' server_command_topic = id + '/commands'
client_name = id + 'nightlight_server'
mqtt_client = mqtt.Client(client_name) mqtt_client = mqtt.Client(client_name)
mqtt_client.connect('test.mosquitto.org') mqtt_client.connect('test.mosquitto.org')
@ -17,8 +17,10 @@ mqtt_client.loop_start()
def handle_telemetry(client, userdata, message): def handle_telemetry(client, userdata, message):
payload = json.loads(message.payload.decode()) payload = json.loads(message.payload.decode())
print("Message received:", payload) print("Message received:", payload)
command = { 'led_on' : payload['light'] < 200 } command = { 'led_on' : payload['light'] < 200 }
print("Sending message:", command) print("Sending message:", command)
client.publish(server_command_topic, json.dumps(command)) client.publish(server_command_topic, json.dumps(command))
mqtt_client.subscribe(client_telemetry_topic) mqtt_client.subscribe(client_telemetry_topic)

@ -6,8 +6,7 @@ import paho.mqtt.client as mqtt
id = '<ID>' id = '<ID>'
client_telemetry_topic = id + '/telemetry' client_telemetry_topic = id + '/telemetry'
server_command_topic = id + '/commands' client_name = id + '_nightlight_server'
client_name = id + 'nightlight_server'
mqtt_client = mqtt.Client(client_name) mqtt_client = mqtt.Client(client_name)
mqtt_client.connect('test.mosquitto.org') mqtt_client.connect('test.mosquitto.org')
@ -18,11 +17,6 @@ def handle_telemetry(client, userdata, message):
payload = json.loads(message.payload.decode()) payload = json.loads(message.payload.decode())
print("Message received:", payload) print("Message received:", payload)
command = { 'led_on' : payload['light'] < 200 }
print("Sending message:", command)
client.publish(server_command_topic, json.dumps(command))
mqtt_client.subscribe(client_telemetry_topic) mqtt_client.subscribe(client_telemetry_topic)
mqtt_client.on_message = handle_telemetry mqtt_client.on_message = handle_telemetry

Loading…
Cancel
Save