From c3a6c9075fe867aa784d9a5d6ea2599d21de7654 Mon Sep 17 00:00:00 2001 From: Lateefah Bello <2019cinnamon@gmail.com> Date: Wed, 2 Jun 2021 12:40:47 +0100 Subject: [PATCH] fixed up the apps --- .../4-connect-internet/code-commands/server/app.py | 6 ++++-- .../lessons/4-connect-internet/code-server/server/app.py | 8 +------- 2 files changed, 5 insertions(+), 9 deletions(-) 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 99a3c888..01b6a0f2 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 @@ -6,8 +6,8 @@ import paho.mqtt.client as mqtt id = '' client_telemetry_topic = id + '/telemetry' -client_name = id + 'nightlight_server' server_command_topic = id + '/commands' +client_name = id + 'nightlight_server' mqtt_client = mqtt.Client(client_name) mqtt_client.connect('test.mosquitto.org') @@ -17,10 +17,12 @@ 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 diff --git a/1-getting-started/lessons/4-connect-internet/code-server/server/app.py b/1-getting-started/lessons/4-connect-internet/code-server/server/app.py index 01b6a0f2..e6b46379 100644 --- a/1-getting-started/lessons/4-connect-internet/code-server/server/app.py +++ b/1-getting-started/lessons/4-connect-internet/code-server/server/app.py @@ -6,8 +6,7 @@ import paho.mqtt.client as mqtt id = '' 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.connect('test.mosquitto.org') @@ -18,11 +17,6 @@ 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