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

Requiremets

Setup

  1. Download the UbidotsEthernet library here
  2. Go to the Arduino IDE, click on Sketch -> Include Library -> Add .ZIP Library
  3. Select the .ZIP file of UbidotsEthernet 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 Ethernet settings like MAC address and IP. 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.

NOTE: On the following link you'll find a guide that help you to get the variable ID. 

Send values to Ubidots

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

#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>

#define ID_1  "Your_variable_ID_here"  // Put here your Ubidots variable ID
#define ID_2  "Your_variable_ID_here"  // Put here your Ubidots variable ID
#define ID_3  "Your_variable_ID_here"  // Put here your Ubidots variable ID

#define TOKEN  "Your_token_here"  // Put here your Ubidots TOKEN

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);

Ubidots client(TOKEN);

void setup(){
    Serial.begin(9600);
    // start the Ethernet connection:
    if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to configure Ethernet using DHCP");
      // try to congifure using IP address instead of DHCP:
      Ethernet.begin(mac, ip);
    }
    // give the Ethernet shield a second to initialize:
    delay(1000);
}
void loop(){
    float value = analogRead(A0);
    float value2 = analogRead(A1);
    float value3 = analogRead(A2);
    client.add(ID_1, value);
    client.add(ID_2, value2);
    client.add(ID_3, value3);
    client.sendAll();
}

Get one value from Ubidots

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

#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>

#define ID  "Your_variable_ID_here"  // Put here your Ubidots variable ID
#define TOKEN  "Your_token_here"  // Put here your Ubidots TOKEN


// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);

Ubidots client(TOKEN);

void setup(){
    Serial.begin(9600);
    // start the Ethernet connection:
    if (Ethernet.begin(mac) == 0) {
      Serial.println("Failed to configure Ethernet using DHCP");
      // try to congifure using IP address instead of DHCP:
      Ethernet.begin(mac, ip);
    }
    // give the Ethernet shield a second to initialize:
    delay(1000);

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

Did this answer your question?