Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tools:mqtt_as [2020/08/18 06:34] – [MicroPython Asynchronous MQTT] darron | tools:mqtt_as [2020/08/18 23:41] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
MQTT library for MicroPython on the ESP8266 and ESP32 | MQTT library for MicroPython on the ESP8266 and ESP32 | ||
+ | ===Files=== | ||
- | Files | + | ==ESP32== |
+ | |||
+ | boot.py is the MicroPython startup. The others are the MQTT demo. | ||
< | < | ||
Line 10: | Line 13: | ||
config.py | config.py | ||
mqtt_as.py | mqtt_as.py | ||
+ | test.py | ||
+ | </ | ||
+ | |||
+ | ==Shell== | ||
+ | |||
+ | These scripts to interact with the mosquitto MQTT broker. | ||
+ | |||
+ | < | ||
pubtest | pubtest | ||
subtest | subtest | ||
- | test.py | ||
</ | </ | ||
+ | ===boot.py=== | ||
+ | |||
+ | The ESP32 startup file which run our test after a short boot delay. | ||
- | boot.py | ||
< | < | ||
# This file is executed on every boot (including wake-boot from deepsleep) | # This file is executed on every boot (including wake-boot from deepsleep) | ||
Line 28: | Line 40: | ||
</ | </ | ||
- | test.py | + | ===test.py=== |
+ | |||
+ | Main executable called from startup. This demo is pulled from the README documentation with local changes. | ||
+ | |||
+ | Configure SERVER here. | ||
< | < | ||
from mqtt_as import MQTTClient | from mqtt_as import MQTTClient | ||
Line 65: | Line 82: | ||
</ | </ | ||
- | config.py | + | ===config.py=== |
+ | |||
+ | mqtt_as configuration as found in distribution directory with mosquitto MQTT broker and wifi | ||
+ | changes. | ||
+ | |||
+ | Configure MQTT broker, ssid and password. | ||
< | < | ||
# config.py Local configuration for mqtt_as demo programs. | # config.py Local configuration for mqtt_as demo programs. | ||
Line 104: | Line 127: | ||
</ | </ | ||
- | mqtt_as.py | + | ===mqtt_as.py=== |
+ | |||
+ | mqtt_as excecutable. This is the main logic which maintains a Wifi connection and publishes and subscribes to topics. | ||
< | < | ||
Line 110: | Line 135: | ||
</ | </ | ||
- | Run | + | ===Run=== |
+ | |||
+ | ==ESP32== | ||
< | < | ||
Line 182: | Line 209: | ||
publish 0 | publish 0 | ||
publish 1 | publish 1 | ||
+ | </ | ||
- | Terminating... | + | ===subtest=== |
- | Skipping tty reset... | + | |
- | Thanks for using picocom | + | ==script== |
+ | |||
+ | Subscribe to the topic named ' | ||
+ | |||
+ | < | ||
+ | #! /bin/bash | ||
+ | mosquitto_sub -h 192.168.0.13 -t result | ||
</ | </ | ||
- | subtest | + | ==Shell output== |
+ | |||
+ | Running status for the result topic. | ||
< | < | ||
- | ./subtest | ||
0 | 0 | ||
1 | 1 | ||
</ | </ | ||
- | pubtest | + | ===pubtest=== |
+ | |||
+ | ==script== | ||
+ | |||
+ | Publish two messages to the topic named ' | ||
+ | |||
+ | < | ||
+ | #! /bin/bash | ||
+ | # mosquitto_sub -h 192.168.0.10 -t result | ||
+ | while : | ||
+ | do | ||
+ | mosquitto_pub -h 192.168.0.13 -t foo_topic -m " | ||
+ | sleep 5 | ||
+ | mosquitto_pub -h 192.168.0.13 -t foo_topic -m "pete was here" -q 1 | ||
+ | sleep 5 | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | ==ESP32 output== | ||
+ | |||
+ | Show running status on the ESP32 and incoming subscription topics. | ||
< | < | ||
Line 211: | Line 267: | ||
[[https:// | [[https:// | ||
+ |