ESP 32 – Simple Communication with Ada fruit IO server – Complete Code and Guide

Adafruit is a very useful platform, by using there IO server you can simply upload data in the form of text, values or make graphs, indicator and gauges very easily and free of cost.

We can give you a complete guide about the esp 32-simple communication with the Adafruit Io server: If you are working on a project using IOT with the ESP32, you might need this tutorial to send data over the WiFi using the Adafruit IO server.

ESP 32 - Simple Communication with Ada fruit IO server
Adafruit IO home page

In order to send the data, you need to install the Adafruit IO library. That library is available in the Arduino IDE library manager. If you are looking for a basic ESP32 guide, then you can find that one at gotechies‘ blog archive, where we have discussed how we can install ESP32 and start working on it.

Now to install the library simply go to tools -> Libraries and Library manager of Arduino IDE & search for Adafruit IO:

After installing the library, let`s create a dashboard on Adafruit server.

To create a dashboard, simply visit https://io.adafruit.com/

Create an Account, go to dashboard and create one.

In your dashboard now you need to add some blocks, create two blocks one to send the value and other one to receive the value:

Dashboard of Adafruit

If you are confused, a simple tutorial is available to guide you through the process of dashboard and feeds creation here:

Now that you have created a dashboard and your Arduino IDE is ready. It is time to upload the code.

There is zip file available for you to download in the exact manner (2 files in it) as explained in the video. Or you can copy the code from here:

// Config data 


// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "Creativoedu"
#define IO_KEY "aio_airk052SEeSY4er6ubqM0Rflp8Qk"



#define WIFI_SSID "Creativo"
#define WIFI_PASS "Creativo123"


#include "AdafruitIO_WiFi.h"
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) ||         \
    defined(ADAFRUIT_PYPORTAL)

#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant

#define SPIWIFI SPI
#define SPIWIFI_SS 10  // Chip select pin
#define SPIWIFI_ACK 9  // a.k.a BUSY or READY pin
#define ESP32_RESETN 6 // Reset pin
#define ESP32_GPIO0 -1 // Not connected
#endif
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
                   SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
#else
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif


// ******************************************** End of Config file ******************************************** //


AdafruitIO_Feed *feed1 = io.feed("Feed1Creativo");
AdafruitIO_Feed *feed2 = io.feed("Feed2Creativo");


void handleMessage(AdafruitIO_Data *data) {
  
  
  digitalWrite(17, data->toPinLevel());
   
  Serial.print("received <- ");
 
 
}

void setup() {
 Serial.begin(115200);
  
  pinMode(17,OUTPUT);
  pinMode(16,INPUT);
  while(! Serial);
  Serial.print("Connecting to Adafruit IO");
  io.connect();



  feed1->onMessage(handleMessage);

  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }


  Serial.println();
  Serial.println(io.statusText());

  feed1->get();
}


String message="Hello";

void loop() {
  int IR=digitalRead(16);
  io.run();
  feed2->save(IR);
  delay(3000);

}

If you want to learn about ESP-32 Wi-Fi communication via a local server, please read this article.

Keep following gotechies for more 🙂

Leave a Comment

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