Ubidots-Arduino is an Arduino library for interacting with Ubidots through its API. The library also contains the code to connect to your WiFi network.

Requiremets

Make sure the firmware of your WiFi shield is up to date! See Arduino’s firmware update guide for more information.

This product is currently retired by Arduino. Though we invest time and resources to make this open source library work, we can’t guarantee its stability since it runs on third-party products. Please contact the hardware manufacturer directly for any device-related inquiries.

Setup

  1. Download the ubidots-arduino-wifi library.
  2. Go to the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library
  3. Select the downloaded .ZIP file and then “Accept” or “Choose
  4. Close the Arduino IDE and open it again.

To use this library, put your Ubidots token and variable ID where indicated, as well as the WiFi settings. After uploading each example to your Arduino, 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.

Send values to Ubidots

To send multiple values to Ubidots, go to Sketch -> Examples -> UbidotsArduino library and select the “saveValues” example.

#include <SPI.h>
#include <WiFi.h>
#include <UbidotsArduino.h>

#define TOKEN  "Your_ubidots_token_here"
#define VARLABEL_1  "Your_variable_ID_here"
#define VARLABEL_2  "Your_variable_ID_here"
#define VARLABEL_3  "Your_variable_ID_here"

char ssid[] = "yourNetwork";    // your network SSID (name)
char pass[] = "secretPassword"; // your network password
int keyIndex = 0;               // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

Ubidots client(TOKEN);

void setup(){
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }

    // check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present");
        // don't continue:
        while (true);
    }

    String fv = WiFi.firmwareVersion();
    if (fv != "1.1.0") {
        Serial.println("Please upgrade the firmware");
    }

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to SSID: ");
        Serial.println(ssid);
        // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
        status = WiFi.begin(ssid, pass);

        // wait 10 seconds for connection:
        delay(10000);
    }

}
void loop() {
  float value = analogRead(A0);
  float value2 = analogRead(A1);
  float value3 = analogRead(A2);
  client.add(VARLABEL_1,value);
  client.add(VARLABEL_2,value2);
  client.add(VARLABEL_3,value3);
  client.sendAll();
}

Get one value from Ubidots

To get the last value of a variable from Ubidots, go to Sketch -> Examples -> UbidotsArduino library and select the “getValue” example.

#include <SPI.h>
#include <WiFi.h>
#include <UbidotsArduino.h>

#define VARLABEL  "Your_variable_label_here"
#define TOKEN  "Your_ubidots_token_here"

char ssid[] = "yourNetwork";    // your network SSID (name)
char pass[] = "secretPassword"; // your network password
int keyIndex = 0;               // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

Ubidots client(TOKEN);

void setup(){
    Serial.begin(9600);
    while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
    }

    // check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present");
        // don't continue:
        while (true);
    }

    String fv = WiFi.firmwareVersion();
    if (fv != "1.1.0") {
        Serial.println("Please upgrade the firmware");
    }

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to SSID: ");
        Serial.println(ssid);
        // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
        status = WiFi.begin(ssid, pass);

        // wait 10 seconds for connection:
        delay(10000);
    }

}
void loop(){
        float value = client.getValue(VARLABEL);
}

Did this answer your question?