Saturday, April 20, 2024
ExplainerInternet of ThingsIoT Software&ToolsTech/Web

Adafruit IO ? | Adafruit IO Arduino Library | Adafruit MQTT

What is Adafruit IO?

Adafruit.io is a cloud service – that just means adafruit run it for you and you don’t have to manage it. Adafruit IO is a system that makes data useful. Adafruit focus on ease of use, and allowing simple data connections with little programming required. IO includes client libraries that wrap our REST and MQTT APIs. IO is built on Ruby on Rails, and Node.js.

You can connect to it over the Internet. It’s meant primarily for storing and then retrieving data but it can do a lot more than just that!

What can Adafruit IO do for me?

  • Display your data in real-time, online
  • Make your project internet-connected: Control motors, read sensor data, and more!
  • Connect projects to web services like Twitter, RSS feeds, weather services, etc.
  • Connect your project to other internet-enabled devices
  • The best part? All of the above is do-able for free with Adafruit IO

Dashboards

Adafruit.io can handle and visualize multiple feeds of data. Want to display data from a temperature-humidity sensor alongside data from an air quality sensor and add a button to turn on the air-conditioner in your room?

No problem! Dashboards are a feature integrated into Adafruit IO which allow you to chart, graph, gauge, log, and display your data. You can view your dashboards from anywhere in the world.

Triggers

Use triggers in AdafruitIO to control and react to your data. Configure triggers to email you when your system goes offline, react to a temperature sensor getting too hot, and publish a message to a new feed.

Feeds

Feeds are the core of the Adafruit IO system. The feed holds metadata about the data you push to Adafruit IO. This includes settings for whether the data is public or private, what license the stored sensor data falls under, and a general description of the data. The feed also contains the sensor data values that get pushed to Adafruit IO from your device.

You will need to create one feed for each unique source of data you send to the system. For example, if you have a project with one temperature sensor and two humidity sensors, you would need to create three feeds. One feed for the temperature sensor, and one feed for each humidity sensor.

Integration with IFTTT and Zapier

Want to make your project react to an email, display trending tweets, or turn on the front lights when your pizza is on the way? We baked in integrations with IFTTT and Zapier to connect your project’s sensors to hundreds of web services.

Adafruit IO Arduino Library

This library provides a simple device independent interface for interacting with Adafruit IO using Arduino. It allows you to switch beween WiFi (ESP8266, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing) with only a two line change in your sketch.

Installation

You can install the library through the Arduino Library Manager (click: Sketch -> Include Library -> Manage Libraries…) and search Adafruit io arduino.

Alternatively, you can download the Adafruit IO Arduino Library from GitHub and install it manually.

Usage

The included examples sketches will walk you through all of the features of the library. They can be used on all platforms, but they default to WiFi. Most of the sketches have companion projects on the Adafruit Learning system.

To change between platforms, you will need to change two lines of code in the config.h tab of the example. It is recommended that you start with one of the Adafruit WiFi feathers before moving on to cellular or ethernet.

For all examples, you will need to set IO_USERNAME and IO_KEY in the config.h tab:

To find your IO_USERNAME, navigate to your profile on Adafruit IO and click View AIO Key. Copy the Username field (ctrl+c or command+c)

Then, in the config.h tab, replace the "your_username" text with your the username from your profile:

To find your IO_Key, navigate to your profile, click View AIO Key, and copy the ACTIVE KEY field to your clipboard (ctrl+c or command+c).

In config.h, replace the IO_KEY with the IO Key copied to your clipboard.

Using the Adafruit IO Arduino Library with WiFi

If you are using the included examples, you do not need to change anything for the Adafruit WiFi Feathers. All WiFi based Feathers (ESP8266, M0 WiFi, WICED) will work with the examples out of the box once you add your WiFi SSID and Password to the config.h file.

In the config.h tab, replace "your_ssid" with your WiFi’s SSID and "your_pass" with your WiFi’s password

Using the Adafruit IO Arduino Library with Ethernet

For Ethernet, you will only need to change from the default WiFi constructor to the Ethernet specific constructor in the config.h tab. The rest of the sketch remains the same.

You will need to comment out these WiFi lines in config.h:

#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);

and uncomment the Ethernet lines in config.h:

#include "AdafruitIO_Ethernet.h"
AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

Using the Adafruit IO Arduino Library with Cellular (32u4 FONA)

For FONA, you will only need to change from the default WiFi constructor to the FONA specific constructor in the config.h tab. The rest of the sketch remains the same.

You will need to comment out these WiFi lines in config.h:

#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);

and uncomment the FONA lines in config.h:

#include "AdafruitIO_FONA.h"
AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

If your carrier requires APN info, you can set it by adding a call to io.setAPN() after io.connect() in the setup()function of the sketch.

void setup() {
  // start the serial connection
  Serial.begin(115200);
  // connect to io.adafruit.com
  io.connect();
  io.setAPN(F("your_apn"), F("your_apn_user"), F("your_apn_pass"));
}

Adafruit MQTT Arduino Library

Adafruit also have a library to provide support for accessing Adafruit IO using MQTT. This is a general-purpose MQTT library for Arduino that’s built to use as few resources as possible so that it can work with platforms like the Arduino Uno.  Unfortunately platforms like the Trinket 3.3V or 5V (based on the ATtiny85) have too little program memory to use the library–stick with a Metro 328p or better!

The MQTT library supports the following network platforms and hardware:

Installation

You can install the library through the Arduino Library Manager (click: Sketch -> Include Library -> Manage Libraries…) and serach Adafruit MQTT

Alternatively, you can download the MQTT library from GitHub and manually install it.

If you’re using an Adafruit FONA, you’ll need to install an additional two libraries for the MQTT Library to work properly:

Connection Details

You will want to use the following details to connect a MQTT client to Adafruit IO:

  • Host: io.adafruit.com
  • Port: 1883 or 8883 (for SSL encrypted connection)
  • Username: your Adafruit account username (see the accounts.adafruit.com page here to find yours)
  • Password: your Adafruit IO key (click the AIO Key button on a dashboard to find the key)

Want to use Adafruit IO with your computer or a Raspberry Pi?

The Adafruit IO Python library provides two clients for accessing Adafruit IO (MQTT and HTTP) and lots of examples. It’s compatible with any system running CPython3 and also compatible with Single-Board computers like the Raspberry Pi.


Recommended:


Buy now : Raspberry PI 3 Model B+ Motherboard

I hope you like this post. Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

One thought on “Adafruit IO ? | Adafruit IO Arduino Library | Adafruit MQTT

Leave a Reply

Your email address will not be published. Required fields are marked *