All Collections
Connect your Devices
Connect an Adafruit Feather HUZZAH ESP8266 to Ubidots over HTTP
Connect an Adafruit Feather HUZZAH ESP8266 to Ubidots over HTTP

Learn how to setup your Adafruit Feather HUZZAH ESP8266 with Ubidots

Isabel Lopez avatar
Written by Isabel Lopez
Updated over a week ago

The Adafruit Feather HUZZAH ESP8266 is an 'all-in-one' ESP8266 WiFi development board with built in USB and battery power supplies, including a battery charging port.

The Feather HUZZAH has an 80 MHz ESP8266 WiFi microcontroller with 3.3V logic and is simply programmed using the Arduino IDE; click here for additional specs on the Adafruit Feather HUZZAH ESP8266.

In the following tutorial, Ubidots will demonstrate how to setup and program the Adafruit Feather HUZZAH with ESP8266 using the Arduino IDE and POST and GET data to/from Ubidots cloud to be utilized in your Ubidots powered App. 

Requirements  

Step-By-Step

  1. Feather HUZZAH Setup using the Arduino IDE

  2. Sending (POST) Data to Ubidots

  3. Receiving (GET) Data from Ubidots

  4. Summary

1. Feather HUZZAH Setup using the Arduino IDE

To begin working with the Adafruit Feather HUZZAH ESP8266 you need to setup the board using the Arduino IDE. For this, please refer to the step "3. Board & Platform Management" of the following guide:

1. Now with everything configured, UPLOAD the Blink Sketch to verify that everything is working properly. Go to File > Examples > Basics > Blink and compile the code. 

2. Once the code is properly updated the builtin red LED will start blinking. If the red LED does not start blinking you can know you need to reinstall the board.

3. Download and install the Ubidots library. For a detailed explanation of how to install libraries using the Arduino IDE, refer to this guide.  

2. Sending (POST) Data to Ubidots

With the following example, you will be able to simulate random readings taken from the Feather HUZZAH ESP8266 to Ubidots

1. To begin posting values to Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, be sure to assign the following parameters:

  • SSID (WiFi Name) & Password of the available network connection.

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Instances and Constants
 ****************************************/

const char* UBIDOTS_TOKEN = "...";  // Put here your Ubidots TOKEN
const char* WIFI_SSID = "..."; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "..."; // Put here your Wi-Fi password

Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);

/****************************************
 * Auxiliar Functions
 ****************************************/

// Put here your auxiliar functions

/****************************************
 * Main Functions
 ****************************************/

void setup() {
  Serial.begin(115200);
  ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);

  // ubidots.setDebug(true);  // Uncomment this line for printing debug messages
}

void loop() {
  float value1 = random(0, 9) * 10;
  float value2 = random(0, 9) * 100;
  float value3 = random(0, 9) * 1000;
  ubidots.add("Variable_Name_One", value1);  // Change for your variable name
  ubidots.add("Variable_Name_Two", value2);
  ubidots.add("Variable_Name_Three", value3);

  bool bufferSent = false;
  bufferSent = ubidots.send();  // Will send data to a device label that matches the device Id

  if (bufferSent) {
    // Do something if values were sent properly
    Serial.println("Values sent by the device");
  }

  delay(5000);
}

2. Verify your code within the Arduino IDE. To do this, in the top left corner of our Arduino IDE you will see the "Check Mark" icon press it to verify your code. 

3. Upload the code into your  Feather HUZZAH ESP8266. To do this, choose the "right-arrow"icon beside the check mark icon. 

4. To verify the connectivity of the device, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of our Arduino IDE. 

5. Confirm your data in Ubidots. Now you should see the published data in your Ubidots account.

3. Receiving (GET) Data from Ubidots

With the following sample code you will be able to get a value from Ubidots to start controlling any asset you desire. 

1. To begin getting values from Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, be sure to assign the following parameters:

NOTE: The device and variable label should be defined in the following line of code:

ubidots.get("a020a6133e21", "variable_name_one")

Where the first argument defines the device's label, and the second argument the variable's label.

get(const char* device_label, const char* variable_label)
  • Sample code:

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Constants
 ****************************************/

const char* UBIDOTS_TOKEN = "...";  // Put here your Ubidots TOKEN
const char* WIFI_SSID = "..."; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "..."; // Put here your Wi-Fi password

Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);

/****************************************
 * Auxiliar Functions
 ****************************************/

// Put here your auxiliar functions

/****************************************
 * Main Functions
 ****************************************/

void setup() {
  Serial.begin(115200);
  ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);
  // ubidots.setDebug(true); //Uncomment this line for printing debug messages
}

void loop() {
  /* Obtain last value from a variable as float using HTTP */
  float value = ubidots.get("a020a6133e21", "variable_name_one");

  // Evaluates the results obtained
  if (value != ERROR_VALUE) {
    Serial.print("Value:");
    Serial.println(value);
  }
  delay(5000);
}

2. Verify & Upload the code into the board following the same steps provided in the POST step above.

3. To verify the connectivity of the device and the data which is being received, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs. 

NOTE: If no response is seen, try unplugging the NodeMCU and then plugging it again. Make sure the baud rate of the Serial monitor is set to the same one specified in your code 115200.

4. In the serial monitor, you will be able to see the last value received in Ubidots of the variable specified in the firmware.

4. Summary

With this simple tutorial we are able to POST and GET data to/from Ubidots with the ease of the Arduino IDE and a Feather HUZZAH with an ESP8266. If your wish to find more examples to handle context or timestamp values in your request checkout Ubidots documentation with the ESP8266 by clicking here

Now its time to create Ubidots Dashboards to visualize your data and deploy your internet connected monitoring solution!  

Other readers have found useful...

Did this answer your question?