All Collections
Connect your Devices
Connect the Arduino MKR WIFI 1010 with Ubidots over HTTP
Connect the Arduino MKR WIFI 1010 with Ubidots over HTTP

Learn how to connect the Arduino MKR WIFI 1010 to Ubidots Application Development Platform over HTTP

Sergio M avatar
Written by Sergio M
Updated over a week ago


The MKR WIFI 1010 is a significant improvement on the MKR 1000 WIFI. It's equipped with an ESP32 module. This board aims to speed up and simplify the prototyping of WiFi based IoT applications thanks to the flexibility of the ESP32 module and its low power consumption.

By following this guide you will be able to make POST and GET HTTP request to Ubidots in just a couple of minutes!    

Requirements

Step-by-Step

1. Setting up the Arduino IDE

  • Download the latest version of the Arduino IDE if you do not already have it.

  • In the Arduino IDE, click on Sketch -> Include Library -> Manage Libraries.

Search for WiFiNINA library and install the latest version available on your computer. Make sure the firmware version of the board matches with the library. If the firmware needs an update, please use the following utilities : 

  • CheckWiFiNINAFirmwareVersion : Reads the required firmware number required from library and matches with the one installed on the board or the shield.

  • WiFiNINAFirmwareUpdater : The sketch that must be loaded to allow the firmware and certificates update process through the integrated plugin of Arduino Software (IDE) rel. 1.8.5 or later.

Download the Ubidots library and click on Sketch -> Include Library -> Add .ZIP Library. Then, select the .ZIP file of Ubidots and then click on "Accept". Finally, close the Arduino IDE and open it again.

2. Sending (POST) Data to Ubidots

In order to POST data to Ubidots, first you have to select the board and port in the options Tools of the Arduino IDE bar.

After make sure your board is successfully connected with the computer, open the Arduino IDE and paste the sample code below. Once you have pasted the code, you will need to assign your Ubidots TOKEN, SSID (WiFi Name) and Password of the available network.

// This example sends data to multiple variables to
// Ubidots through HTTP protocol.

/****************************************
* 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);
}

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. 

UPLOAD the code into your “Arduino MKR WIFI 1010”. To do this, choose the "right-arrow" icon beside the "check mark" icon. 

To verify the device's connectivity and the server response, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to check if the data is being send correctly.

After you follow the above steps, you would be able to see a response in the serial monitor like the one below.

Finally in your Ubidots account you will be able to see the data posted in your  device.

3. Retrieve (GET) Data from Ubidots

With the following sample code you will be able to GET the last values of a variable. Be sure to assign your Ubidots TOKEN, SSID (WiFi Name), Password, Device Label and Variable Label  that want to GET 

// This example retrieves last value of a variable from the Ubidots API
// using HTTP protocol.

/****************************************
* 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
const char* DEVICE_LABEL_TO_RETRIEVE_VALUES_FROM = "weather-station"; // Replace with your device label
const char* VARIABLE_LABEL_TO_RETRIEVE_VALUES_FROM = "humidity"; // Replace with your variable label

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(DEVICE_LABEL_TO_RETRIEVE_VALUES_FROM, VARIABLE_LABEL_TO_RETRIEVE_VALUES_FROM);

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


After pasting the code, verify that you do not have any errors and upload the code to the device. Once the code is successfully uploaded, open the serial monitor to see the response of the server and obtain the last values of the variable. You should get a response similar to the one below.

4. Summary

With this simple tutorial you are able to POST & GET data to/from Ubidots, now it's time to create Ubidots Dashboards to visualize your data and deploy your IoT solution.

Other readers have also found useful...

  

Did this answer your question?