diff --git a/1-getting-started/lessons/4-connect-internet/code-commands/server/app.py b/1-getting-started/lessons/4-connect-internet/code-commands/server/app.py index e6b46379..8c506d93 100644 --- a/1-getting-started/lessons/4-connect-internet/code-commands/server/app.py +++ b/1-getting-started/lessons/4-connect-internet/code-commands/server/app.py @@ -5,8 +5,9 @@ import paho.mqtt.client as mqtt id = '' -client_telemetry_topic = id + '/telemetry' -client_name = id + '_nightlight_server' +lient_telemetry_topic = id + '/telemetry' +client_name = id + 'nightlight_server' +server_command_topic = id + '/commands' mqtt_client = mqtt.Client(client_name) mqtt_client.connect('test.mosquitto.org') @@ -16,7 +17,10 @@ mqtt_client.loop_start() def handle_telemetry(client, userdata, message): payload = json.loads(message.payload.decode()) 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.on_message = handle_telemetry