From 5900a8384e8020c03417bde99973d4f44cad9203 Mon Sep 17 00:00:00 2001 From: bzi Date: Mon, 18 Feb 2019 22:01:59 +0100 Subject: [PATCH] Add scripts for local broker and subscriber for debugging to repo --- scripts/run_broker.sh | 9 +++++++++ scripts/simple_subscriber.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 scripts/run_broker.sh create mode 100644 scripts/simple_subscriber.py diff --git a/scripts/run_broker.sh b/scripts/run_broker.sh new file mode 100755 index 0000000..4945671 --- /dev/null +++ b/scripts/run_broker.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# ESP8266 environmental sensor project +# +# This script provides an example on how to call the mosquitto_sub MQTT broker to deal with sensor topic MQTT requests. +# +# (C) 2019 Macrocell - Environmental sensing solutions +# proudly presented by Macrocell - FPGA Innovators + +mosquitto_sub -h localhost -v -t sensor diff --git a/scripts/simple_subscriber.py b/scripts/simple_subscriber.py new file mode 100644 index 0000000..88a7546 --- /dev/null +++ b/scripts/simple_subscriber.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +''' +/* ESP8266 environmental sensor project + * + * This script provides a very simplistic MQTT subscriber that subscribes to any topic of an MQTT broker running on localhost. + * It can be used perfectly for debugging sensors with a local broker like mosquitto_sub. + * + * Developed on and tested with Python 3.5. + * + * (C) 2019 Macrocell - Environmental sensing solutions + * proudly presented by Macrocell - FPGA Innovators + */ ''' + +import paho.mqtt.client as mqtt +import datetime + +def on_connect(client, userdata, flags, rc): + print("Connected with result code " + str(rc)) + + client.subscribe("#") + +def on_message(client, userdata, msg): + print(str(datetime.datetime.now()) + " : " + msg.topic + " " + str(msg.payload)) + +client = mqtt.Client() +client.on_connect = on_connect +client.on_message = on_message + +client.connect("localhost", 1883, 60) + +client.loop_forever()