Libraries

Before you get started using Adafruit IO with your Arduino, you'll need to select a library. We provide and support both of these libraries, but try starting with the Adafruit IO Arduino Library below:

Adafruit IO Arduino Library (REST-based)

The Adafruit IO Arduino Library is a simple library to send and receive feed data using the Adafruit IO REST API. We suggest using it before moving onto the more advanced features of the MQTT Library.

The 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...)

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  

We 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...)

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

This guide was first published on Jun 13, 2018. It was last updated on Jun 13, 2018. This page (Libraries ) was last updated on Jul 12, 2018.