The Autonomo is a compact Arduino-compatible board that uses the Atmel Cortex M0+ 32bit microcontroller. It was designed to be autonomously powered by a solar panel.
This guide explains how to send and receive data to/from Ubidots from the SODAQ Autonomo over WiFi using the RN171 chip, also known as WiFibee.
Requirements
1. Setting up Arduino IDE
1. To be able to work with the SODAQ platform in the Arduino IDE, you will need to install the SODAQ platform using the preconfigured Arduino Board Manager. If you are not familiar with adding a board with the Arduino IDE, refer to this article for additional guidance.
The Board Manager URL for the SODAQ is:
http://downloads.sodaq.net/package_sodaq_index.json
2. With the SODAQ platform installed, select the SODAQ device you are working with. In this tutorial, we are working with a “SODAQ Autonomo”. To select your board from the Arduino IDE, select Tools –> Board “SODAQ Autonomo”.
3. Download the Ubidots SODAQ WiFiBee library and install it. 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 sample code you will be able to post the readings taken from ANALOG pin A0 of the SODAQ Autonomo.
1. To POST your first value in Ubidots, open the Arduino IDE and paste the sample code below. Once you have pasted the code, you will need to assign your unique Ubidots TOKEN, SSID (WiFi Name) and Password of the available network
#include <SODAQWiFibee.h>
/* Change the AUTH according to your network settings
If is open change to WIFLY_AUTH_OPEN
If is WPA1 change to WIFLY_AUTH_WPA1
If is WPA1_2 change to WIFLY_AUTH_WPA1
If is WPA2 change to WIFLY_AUTH_WPA1
*/
// To add space in RN171 you just put "$" instead of " "
#define SSID "xxxxxxxxxx"
#define KEY "xxxxxxxxxx"
#define AUTH WIFLY_AUTH_WPA2_PSK
#define TOKEN "xxxxxxxxxx" // Replace it with your Ubidots token
Ubidots client(TOKEN);
void setup() {
client.wifiConnection(SSID, KEY, AUTH);
}
void loop() {
float value = analogRead(A0);
client.add("Temperature", value);
client.sendAll();
delay(1000);
}
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 “SODAQ Autonomo”. To do this, choose the "right-arrow" icon beside the "check mark" icon.
4. To verify the connectivity of the device and the data sent, open the serial monitor by selecting the "magnifying glass" icon in the top right corner of the Arduino IDE to see the connectivity logs.
5. Confirm your data in Ubidots. Now you should see the posted data in your Ubidots account, located the device called "SODAQWiFly".
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 start 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:
The SSID of the WiFi and the Password of the network
Your unique Ubidots TOKEN
The Variable ID of the variables you will retrieve data. If you do not have the variable IDs, simply create a shell variables and then update your firmware to contain the correct Variable IDs. To locate the variable IDs, simply click here.
#include <SODAQWiFibee.h>
/* Change the AUTH according to your network settings
If is open change to WIFLY_AUTH_OPEN
If is WPA1 change to WIFLY_AUTH_WPA1
If is WPA1_2 change to WIFLY_AUTH_WPA1
If is WPA2 change to WIFLY_AUTH_WPA1
*/
// To add space in RN171 you just put "$" instead of " "
#define SSID "xxxxxxxxx"
#define KEY "xxxxxxxxx"
#define AUTH WIFLY_AUTH_WPA2_PSK
#define TOKEN "xxxxxxxxx" // Replace it with your Ubidots token
#define ID "xxxxxxxxx"
Ubidots client(TOKEN);
void setup() {
client.wifiConnection(SSID, KEY, AUTH);
}
void loop() {
float value = client.getValue(ID);
Serial.print("The last value is: ");
Serial.println(value);
delay(1000);
}
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.
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 & GET data to/from Ubidots with the ease of the Arduino IDE and a SODAQ Autonomo over WiFi.
Now its time to create Ubidots Dashboards to visualize your data and deploy your IoT solution!
Other readers have also found useful...