Adafruit IO is an easy way to create an internet-connected...well, anything! Today I am going to show you how to use MQTTS (The secure version of MQTT) to connect Adafruit IO to a NodeMCU.
1.0 What is IoT?IoT (Internet of Things) is basically when you create an interconnected network of internet-connected devices. (Crazy right)
Ok, so what this means is that you can connect devices (like an esp8266) to the internet via WiFi or Ethernet. Were going to use a protocol called MQTT. MQTT is really fast and lightweight, perfect for what we're using it for.
For a great tutorial on IoT, Digi-Key and Adafruit made a series of videos on all the aspects of IoT: https://www.digikey.com/en/resources/iot-resource-center/videos
2.0 CodeWe'll just talk about the top part here.
#define WLAN_SSID "--username--"
#define WLAN_PASS "--password--"
#define AIO_USERNAME "your username"
#define AIO_KEY "your key"
WLAN_SSID - the name of your wifi
WLAN_PASS - the password to your wifi
AIO_USERNAME - your adafruit io username
AIO_KEY - your adafruit io api key
For username and key, go to https://io.adafruit.com/.
click on "AIO Key" in the top right corner.
A few other things to note:
#define AIO_SERVERPORT 8883
I found that using the secure port (SSL/TLS) instead of the non-secure one worked best on the NodeMCU.
In the loop, YOU MUST HAVE A DELAY!!! Otherwise, Adafruit IO will put a throttle on your account and possible block you for a minute or so depending on how much data you're sending!!!
In the code for this project, I added an automatic throttle delay so that even if your circuit accidentally sends too much data and it triggers the throttle, it will detect it and wait till the throttle stops.
if(subscription == &throttle) {
Serial.println(F("Throttle: "));
Serial.println((char *)throttle.lastread);
int waitTime = parseMsg((char*)throttle.lastread);
Serial.println(String("Waiting " + String((waitTime + 2)) + " seconds for throttle to stop..."));
delay((waitTime + 2) * 1000);
return;
3.0 Use it!Go to io.adafruit.com/feeds and create feeds for what you want. These are the feeds I used in this project:
If you need help creating feeds: https://learn.adafruit.com/adafruit-io-basics-feeds/
Then create a dashboard with all the controls you want.
Help for creating dashboards: https://learn.adafruit.com/adafruit-io-basics-dashboards
4.0 Going furtherAdafruit has many projects built with their IoT service: https://learn.adafruit.com/category/adafruit-io
So does Hackster.io: https://www.hackster.io/search?i=projects&q=adafruit%20io
Comments