Ubidots-Arduino-YUN is an Arduino library for interacting with Ubidots through its API.
The Arduino Yún is a microcontroller board based on the ATmega32u4 and the Atheros AR9331. The Atheros processor supports a Linux distribution based on OpenWrt named OpenWrt-Yun. The board has built-in Ethernet and WiFi support, a USB-A port, micro-SD card slot, 20 digital input/output pins, a 16 MHz crystal oscillator, and a micro USB connection.
In this code when you save the value the library will save that value in a default data source name, named YUN. If you want to change that please go to the library and use the setDataSourceName function.- Connect your Arduino Yún to the power supply.
- Check for an unsecure wifi network starting with “Arduino Yun”
- Connect to this network and enter 192.168.240.1 into a web broswer to see the configuration page of the Arduino Yún. The default password is “arduino”
- Once you’re connected click on “system”
- Specify the Wireless Parameters of your Wi-Fi connection, then press “configure & restart”. This may take several minutes.
- Download the UbidotsYUN library here
- Go to the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library
- Select the .ZIP file of Ubidots_FONA and then "Accept" or "Choose"
- Do the same to add the Adafruit_FONA library.
- Close the Arduino IDE and open it again.
To send a value to Ubidots, go to Sketch -> Examples -> UbidotsYUN library and select the "saveValue" example. Set your Ubidots personal TOKEn
#include <UbidotsYUN.h>
#define TOKEN "YOUR_TOKEN_HERE"
Ubidots client(TOKEN);
void setup() {
client.init();
Serial.begin(9600);
}
void loop() {
float value = analogRead(A0);
client.add("Variable_Name", value);
client.sendAll();
}
To get the last value of a variable from Ubidots, go to Sketch -> Examples -> UbidotsYUN library and select the "getValue" example. Put your Ubidots token and variable ID where indicated, as well as the WiFi settings. Upload the code, open the Serial monitor to check the results. If no response is seen, try unplugging your Arduino and then plugging it again. Make sure the baud rate of the Serial monitor is set to the same one specified in your code.
#include <UbidotsYUN.h>
#define TOKEN "YOUR_TOKEN_HERE"
#define ID "YOUR_ID_HERE"
Ubidots client(TOKEN);
void setup() {
client.init();
Serial.begin(9600);
}
void loop() {
float value = client.getValue(ID);
}
To send multiple values you can use our example in our library or copy the next code and do not forget to change set there your TOKEN
#include <UbidotsYUN.h>
#define TOKEN "YOUR_TOKEN_HERE"
Ubidots client(TOKEN);
void setup() {
client.init();
Serial.begin(9600);
}
void loop() {
float value = analogRead(A0);
float value1 = analogRead(A1);
float value2 = analogRead(A2);
client.add("Variable_Name", value);
client.add("Variable_Name_2", value1);
client.add("Variable_Name_3", value2);
client.sendAll();
}