Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tools:mqtt_as [2020/08/18 06:32] darrontools: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.
  
 <code> <code>
Line 10: Line 13:
 config.py config.py
 mqtt_as.py mqtt_as.py
 +test.py
 +</code>
 +
 +==Shell==
 +
 +These scripts to interact with the mosquitto MQTT broker.
 +
 +<code>
 pubtest pubtest
 subtest subtest
-test.py 
 </code> </code>
  
 +===boot.py===
 +
 +The ESP32 startup file which run our test after a short boot delay.
  
-boot.py 
 <code> <code>
 # 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:
 </code> </code>
  
-test.py+===test.py=== 
 + 
 +Main executable called from startup. This demo is pulled from the README documentation with local changes. 
 + 
 +Configure SERVER here. 
 <code> <code>
 from mqtt_as import MQTTClient from mqtt_as import MQTTClient
Line 65: Line 82:
 </code> </code>
  
-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. 
 <code> <code>
 # config.py Local configuration for mqtt_as demo programs. # config.py Local configuration for mqtt_as demo programs.
Line 104: Line 127:
 </code> </code>
  
-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.
  
 <code> <code>
Line 110: Line 135:
 </code> </code>
  
-Run+===Run=== 
 + 
 +==ESP32==
  
 <code> <code>
Line 182: Line 209:
 publish 0 publish 0
 publish 1 publish 1
 +</code>
  
-Terminating... +===subtest=== 
-Skipping tty reset... + 
-Thanks for using picocom+==script== 
 + 
 +Subscribe to the topic named 'result' published by the ESP32 module and display it. 
 + 
 +<code> 
 +#! /bin/bash 
 +mosquitto_sub -h 192.168.0.13 -t result 
 +</code> 
 + 
 +==Shell output== 
 + 
 +Running status for the result topic. 
 + 
 +<code> 
 +
 +
 +</code> 
 + 
 +===pubtest=== 
 + 
 +==script== 
 + 
 +Publish two messages to the topic named 'foo_topic' which the ESP32 device is subscribed to, 
 + 
 +<code> 
 +#! /bin/bash 
 +# mosquitto_sub -h 192.168.0.10 -t result 
 +while : 
 +do 
 +    mosquitto_pub -h 192.168.0.13 -t foo_topic -m "gordon bennett" -q 1 
 +    sleep 5 
 +    mosquitto_pub -h 192.168.0.13 -t foo_topic -m "pete was here" -q 1 
 +    sleep 5 
 +done 
 +</code> 
 + 
 +==ESP32 output== 
 + 
 +Show running status on the ESP32 and incoming subscription topics. 
 + 
 +<code> 
 +publish 103 
 +(b'foo_topic', b'gordon bennett', False) 
 +RAM free 94032 alloc 17136 
 +publish 104 
 +(b'foo_topic', b'pete was here', False) 
 +publish 105
 </code> </code>
  
Line 193: Line 267:
  
 [[https://github.com/peterhinch/micropython-mqtt/blob/master/mqtt_as/README.md|Documentation]] [[https://github.com/peterhinch/micropython-mqtt/blob/master/mqtt_as/README.md|Documentation]]
 +