All Projects → miketeachman → micropython-adafruit-mqtt-esp8266

miketeachman / micropython-adafruit-mqtt-esp8266

Licence: other
Using MQTT to Publish/Subscribe to adafruit io. MicroPython/CircuitPython implementation on ESP8266/ESP32

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to micropython-adafruit-mqtt-esp8266

pg-pubsub
Reliable PostgreSQL LISTEN/NOTIFY with inter-process lock support
Stars: ✭ 50 (-5.66%)
Mutual labels:  publish, subscribe
fastapi websocket pubsub
A fast and durable Pub/Sub channel over Websockets. FastAPI + WebSockets + PubSub == ⚡ 💪 ❤️
Stars: ✭ 255 (+381.13%)
Mutual labels:  publish, subscribe
awesome-macropad
A curated list of awesome applications, macros, 3d printed cases, guides, and more for the Adafruit CircuitPython rp2040 Macropad.
Stars: ✭ 26 (-50.94%)
Mutual labels:  adafruit, circuitpython
dead-simple
💀💡 Dead simple PubSub and EventEmitter in JavaScript
Stars: ✭ 21 (-60.38%)
Mutual labels:  publish, subscribe
angular-PubSub
Angular 1.x implementation of the Publish–Subscribe pattern.
Stars: ✭ 32 (-39.62%)
Mutual labels:  publish, subscribe
micropython-thingspeak-mqtt-esp8266
Publish and Subscribe to Thingspeak using MQTT with Micropython
Stars: ✭ 26 (-50.94%)
Mutual labels:  putty, ampy
Adafruit CircuitPython SD
SD card drivers for Adafruit CircuitPython
Stars: ✭ 24 (-54.72%)
Mutual labels:  circuitpython
win-gpg-agent
[DEPRECATED] Windows helpers for GnuPG tools suite
Stars: ✭ 214 (+303.77%)
Mutual labels:  putty
TokamakPublish
Use Tokamak in your Publish themes.
Stars: ✭ 19 (-64.15%)
Mutual labels:  publish
Big Honking Button
A simple Eurorack sampler and performance module in a silly package.
Stars: ✭ 45 (-15.09%)
Mutual labels:  circuitpython
dart-package-publisher
Action to Publish Dart / Flutter Package To https://pub.dev When you need to publish a package, just bump the version in pubspec.yaml
Stars: ✭ 45 (-15.09%)
Mutual labels:  publish
foster
An easy way to publish your python packages.
Stars: ✭ 31 (-41.51%)
Mutual labels:  publish
xyz
Publish npm packages with fewer screw-ups
Stars: ✭ 101 (+90.57%)
Mutual labels:  publish
can-npm-publish
A command line tool that check to see if `npm publish` is possible.
Stars: ✭ 61 (+15.09%)
Mutual labels:  publish
Kitty-Session-Manager
KiTTy Session Manager (KSM) is a tool that allows system adminstrators to organise their KiTTy sessions into folders and assign hotkeys to their favourite sessions. This is designed for MS Windows and requires the .NET Framework 4.0.3
Stars: ✭ 42 (-20.75%)
Mutual labels:  putty
rollit
🌯 Zero config js library bundling using rollup with support for Vue
Stars: ✭ 24 (-54.72%)
Mutual labels:  publish
Adafruit CircuitPython AMG88xx
circuit python driver from AMG88xx GRID-EYE 8x8 IR sensor
Stars: ✭ 33 (-37.74%)
Mutual labels:  circuitpython
kerntroller
No description or website provided.
Stars: ✭ 31 (-41.51%)
Mutual labels:  circuitpython
wisdom
🎁 Tool for publishing releases to github and npm
Stars: ✭ 16 (-69.81%)
Mutual labels:  publish
Adafruit CircuitPython BNO055
CircuitPython driver for BNO055 absolute orientation sensor
Stars: ✭ 70 (+32.08%)
Mutual labels:  circuitpython

MQTT protocol with Adafruit IO using MicroPython and CircuitPython

MicroPython and CircuitPython examples showing how to use the MQTT protocol with the Adafruit IO cloud service. The example code shows how a Heap statistic (free heap size in bytes) can be used with MQTT at Adafruit IO. This heap statistic provides a convenient means to show the MQTT capabilities. The implementation can be changed to use MQTT Publish/Subscribe with sensor data or any other data.

Three example code files:

  1. Publish the free heap statistics to Adafruit IO
  2. Subscribe to the free heap statistics from Adafruit IO
  3. Publish and Subscribe in the same program

publish/subscribe

Hardware Support

  • example code tested with 3 boards
    • Adafruit Feather HUZZAH ESP8266
    • Adafruit Feather HUZZAH ESP32
    • WeMos D1 Mini

Adafruit IO configuration

  1. Create an Adafruit IO account at Adafruit IO and sign in
  2. Gather the following Adafruit IO information
    • AIO Key (select "View AIO Key" in Adafruit IO)
    • Adafruit UserName (shown on the same page as the AIO Key)

Publishing data to Adafruit IO feeds

Usage

  1. Install the UMQTT Package (if needed) See section below Installing UMQTT Package
  2. Configure parameters in file publishAdafruit.py"
    • <ENTER_WIFI_SSID>
    • <ENTER_WIFI_PASSWORD>
    • <ENTER_ADAFRUIT_USERNAME>
    • <ENTER_ADAFRUIT_IO_KEY>
  3. Copy the file publishAdafruit.py to your device, using ampy, rshell, webrepl
$ ampy -pCOMx -d1 put publishAdafruit.py main.py
  1. Reset the board
  2. Navigate to Adafruit IO to see if a new feed has been created called "freeHeap"
  3. In the example code freeHeap data is published every 10s
  4. Make a dashboard to better visualize the free space on the heap

free heap plot

Subscribing to Adafruit IO feeds

Usage

  1. Install the UMQTT Package (if needed) See section below Installing UMQTT Package
  2. Configure parameters in file subscribeAdafruit.py"
    • <ENTER_WIFI_SSID>
    • <ENTER_WIFI_PASSWORD>
    • <ENTER_ADAFRUIT_USERNAME>
    • <ENTER_ADAFRUIT_IO_KEY>
  3. Copy the file subscribeAdafruit.py to your device, using ampy, rshell, webrepl
$ ampy -pCOMx -d1 put subscribeAdafruit.py main.py
  1. Configure a 2nd device to publish the freeHeap data (see above)
  2. Reset the board
  3. Connect to the REPL with Putty (or simlar) to observe subscribed feed data being received (every 10s in the example code)

Publishing and Subscribing on the same device

The file pubAndSub.py shows how a single device can both publish and subscribe. The method of Subscribing changes in this example. The non-blocking call client.check_msg() is used rather than the blocking call client.wait_msg(). The debug print output shows the subscription receiving the published data.

publish and subscribe


Limitations

  • CircuitPython 3.0.0 will continually reset if a secure data connection is enabled

Tested with these MicroPython Releases

  • MicroPython 1.9.3
  • MicroPython 1.9.4
  • MicroPython 1.10

Tested with these CircuitPython Releases

  • CircuitPython 2.3.1
  • CircuitPython 3.0.0

Recommended Tools for Windows

  • Adafruit Ampy to copy files to the filesystem
    • install version 1.0.3 or newer which has the -d option (use -d1 to avoid USB connection issues in Windows)
  • Putty to interact with the REPL
    • set Serial speed to 115200 and Flow control to None

Installing UMQTT Package

The example code requires the MicroPython MQTT (UMQTT) Package. Some firmware releases have this package built-in, others don't.

Firmware Release umqtt built-in? GitHub Library
MicroPython 1.9.3 for ESP8266 Yes n/a
MicroPython 1.9.4 for ESP8266 Yes n/a
MicroPython 1.10 for ESP8266 Yes n/a
MicroPython 1.9.4 for ESP32 No Micropython lib
MicroPython 1.10 for ESP32 Yes n/a
CircuitPython 2.3.1 for ESP8266 No CircuitPython lib
CircuitPython 3.0.0 for ESP8266 No CircuitPython lib
How to install the UMQTT package (if "No" is indicated in the table above)
  1. Navigate to the GitHub library indicated in the table
  2. Select the "Clone or download" button
  3. Select "Download ZIP"
  4. Extract the ZIP. Should see folder called "micropython-lib-master"
  5. Two files need to be copied to the MicroPython filesystem
    • micropython-lib-master\umqtt.robust\umqtt\simple.py
    • micropython-lib-master\umqtt.robust\umqtt\robust.py

Copy these two files to the MicroPython filesystem with the directory structure shown below.

boot.py
lib
  |
  umqtt
     simple.py
     robust.py

Example with Ampy:

>ampy -pCOM27 -d1 ls
boot.py
>ampy -pCOM27 -d1 mkdir lib
>ampy -pCOM27 -d1 mkdir lib/umqtt
>ampy -pCOM27 -d1 put simple.py lib/umqtt/simple.py
>ampy -pCOM27 -d1 put robust.py lib/umqtt/robust.py
>ampy -pCOM27 -d1 ls
boot.py
lib
>ampy -pCOM27 -d1 ls lib
umqtt
>ampy -pCOM27 -d1 ls lib/umqtt
simple.py
robust.py
Validating the UMQTT package install

From the REPL (using Putty, etc) execute the following commands and observe similar output

>>> from umqtt.robust import MQTTClient

>>> dir(MQTTClient)
['reconnect', 'log', 'publish', '__module__', 'wait_msg', 'delay', '__qualname__', 'DELAY', 'DEBUG']

If you see this result you have successfully installed the umqtt package. 🎉 😌

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].