Add scripts for local broker and subscriber for debugging to repo
This commit is contained in:
parent
b07b6fde6f
commit
5900a8384e
9
scripts/run_broker.sh
Executable file
9
scripts/run_broker.sh
Executable file
@ -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
|
31
scripts/simple_subscriber.py
Normal file
31
scripts/simple_subscriber.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user