[SOLVED] Help Needed with Ubidots Get example code - Ethernet

Hey guys! @aguspg @woakas

I have used Agustin’s demo code he emailed me to send 10 variables to a Ubidots account.

This code is working pretty good for me.

Next I tried to add switch to the dashboard that would control a Ubidots Variable when it was switches. I tried to integrate the Ubidots GET example code along with my working code below but I get compile errors about having EthernetClient & Ubidots Client in the same code.

I’ve spent hours trying to figure it out myself but with no luck.

I tried you new library that was just uploaded to Git 3 days ago but I can’t get that to work at all.

So I figured it may be best to see if you guys can easily add a GET request to the code that I have working below:

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

#define ID  "56dc7b147625422fb6ec085d"  // Put here your Ubidots variable ID
#define TOKEN  "ZCZxcFGzfyB1mFTztUFnUaj8K0ZIt4"  // 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, 0x01 }; 

  

   EthernetClient client;

   String idvariable = "56dbd26276254207a77f17dc"; //
   String idvariable_current = "56dbd265762542088bd9353e"; //
   String idvariable_power = "56dbd23776254207d8704fcd"; //
   String idvariable_soc = "56dbd22476254206ffac0bbc"; //
   String idvariable_ce = "56dbd25f762542088bd93536"; //
   String idvariable_ttg = "56dbd26976254208af6ba4b3"; //
   String idvariable_h2 = "56dbd26a7625420869504855"; //
   String idvariable_h4 = "56dbd26776254207a77f17e5"; //
   String idvariable_h6 = "56dbd27576254208441ef594"; //
   String idvariable_h9 = "56dbd9207625422dff9d9600"; //
  
   String token = "ZCZxcFGzfyB1mFTztUFnUaj8K0ZIt4";  //Omers Account
  


int Relay = 2;



void setup() {
   
  pinMode(Relay, OUTPUT);      //Set's Digital Pin 2 to a Output Pin
  digitalWrite(Relay, LOW);    // Turns off relay.
  
  // disable SD SPI
   pinMode(4,OUTPUT);
   digitalWrite(4,HIGH);
  
  //Baud is set to 19200 because this is the baud that the BMV-600 transmits at.
   Serial.begin(19200);
  
  //Serial.println("BMV Battery Monitor");
  //Serial.println("==========================");
  
  delay(1000);
  
  
  // start the Ethernet connection:
     
     if (Ethernet.begin(mac) == 0) {
       Serial.println("Failed to configure Ethernet using DHCP");
       // no point in carrying on, so do nothing forevermore:
       for(;;);
     
       // give the Ethernet shield a second to initialize:
       delay(1000);
       Serial.println("connecting...");
     }
  
  delay(3000);
  
}





void loop() {
  
  // main program loop
  
  


 Serial.flush();
 Serial.begin(19200); 
 
 
    
     while (Serial.available() == 0);
      {
        char ch = Serial.read();
        if(ch == 'V') // Wait for the capital V and ignore any detritus before it. The capital V (Voltage) marks the beginning of the data thats what we actually want.
        {
   
   int V = Serial.parseInt(); //Battery Voltage
   
   int I = Serial.parseInt(); //Current in or out of the battery
   
   int P = Serial.parseInt(); //W Instantaneous power
   
   long CE = Serial.parseInt(); //Consumed Energy
   
   unsigned int SOC = Serial.parseInt(); //State of charge
   
   long TTG = Serial.parseInt(); //Time to Go
   
   long AR = Serial.parseInt(); //Alarm relay state
   
   long BMV = Serial.parseInt(); //The 600 part of 600S gets parsed as it is an integer
   
   long FW = Serial.parseInt(); //Firmware version gets parsed as it is an integer
  
   long Ha = Serial.parseInt(); // This parses the "1" integer from "H1" The next line will parse actual the value of H1
   long H1 = Serial.parseInt(); //Depth of Deepest Discharge mAh
   
   long Hb = Serial.parseInt(); // This parses the "2" integer from "H2" The next line will parse the actual value of H2 etc.
   long H2 = Serial.parseInt(); //Depth of Last Discharge (mAh)
   
   long Hc = Serial.parseInt();
   long H3 = Serial.parseInt(); //Depth of Average Discharge (mAh)
   
   long Hd = Serial.parseInt();
   unsigned long H4 = Serial.parseInt(); //Number of Charge cycles
   
   long He = Serial.parseInt();
   unsigned long H5 = Serial.parseInt(); //Number of full discharges
   
   long Hf = Serial.parseInt();
   long H6 = Serial.parseInt(); //Cumulative Ah from battery (mAh)
   
   long Hg = Serial.parseInt();
   unsigned int H7 = Serial.parseInt(); //Minimum battery voltage (mV)
   
   long Hh = Serial.parseInt();
   unsigned int H8 = Serial.parseInt(); //Maximum battery voltage (mV)
   
   long Hi = Serial.parseInt();
   unsigned long H9 = Serial.parseInt(); //Hours since last full charge.
   
  // long Hj = Serial.parseInt();
   // unsigned long H10 = Serial.parseInt(); //Number of times BMV automatically synchronised
   
   //long Hk = Serial.parseInt();
   //unsigned long H11 = Serial.parseInt(); //Number of Low voltage alarms
   
   //long Hl = Serial.parseInt();
   //unsigned long H12 = Serial.parseInt(); //Number of High voltage alarms
   
  // long Hm = Serial.parseInt();
   //unsigned long H17 = Serial.parseInt(); //Amount of discharged energy
   
   //long Hn = Serial.parseInt();
   //unsigned long H18 = Serial.parseInt(); //Amount of charged energy
  



  
  if ((V /1000.00) > 8)
{
 // Serial.println("");
 // Serial.println("---------------------------------------"); 
 // Serial.println ("Voltage Above 8V - Send Data");
 // Serial.println("---------------------------------------"); 
 // Serial.println("");
 
   //Code to send variable to Ubidots
  
   float value = (V /1000.00);
   float value_current = (I /1000.00);
   int  value_power = P;
   int value_soc = (SOC / 10);
   float value_ce = (CE /1000.000);
   float value_ttg = (TTG /60.00);
   float value_h2 = (H2 /1000.00);
   float value_h4 = H4;
   float value_h6 = (H6 /1000.00);
   float value_h9 = (H9 /86400.00);
   
   save_value(String(value)); 
   save_value_current(String(value_current)); 
   save_value_power(String(value_power)); 
   save_value_soc(String(value_soc)); 
   save_value_ce(String(value_ce));
   save_value_ttg(String(value_ttg));
   save_value_h2(String(value_h2));
   save_value_h4(String(value_h4));
   save_value_h6(String(value_h6));
   save_value_h9(String(value_h9));
  
 // Serial.println("");
 // Serial.println("---------------------------------------");
 // Serial.println("All Send Functions Complete");
 // Serial.println("---------------------------------------");
  //Serial.println("");
  
 
  
  Serial.end(); 
  delay(1000 * 30);
  
}
else
{
  
 
  // Do Nothing. Wait till next reading. 
  
 // Serial.println("");
 // Serial.println("---------------------------------------");
 // Serial.println("Votage Reading Below 8V - Discard Data");
//  Serial.println("---------------------------------------");
//  Serial.println("");
  
  Serial.end(); 
  delay(1000);
  
}
  }
    }
}

    
       
  void save_value(String value)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
      Serial.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
      Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
      Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
      Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
      Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

    if (!client.connected())
     {
        Serial.println();
        Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
        Serial.print(c);
     }
     client.flush();
     client.stop();

   }  

 
 void save_value_current(String value_current)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_current) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_current+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_current+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }  
   
   
   
   void save_value_power(String value_power)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_power) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_power+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_power+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }  
   
 
 
 void save_value_soc(String value_soc)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_soc) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_soc+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_soc+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
    void save_value_ce(String value_ce)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_ce) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_ce+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_ce+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
    void save_value_ttg(String value_ttg)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_ttg) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_ttg+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_ttg+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
    void save_value_h2(String value_h2)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h2) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h2+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h2+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
   
   
    void save_value_h4(String value_h4)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h4) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h4+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h4+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
   
   
   
   
    void save_value_h6(String value_h6)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h6) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h6+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h6+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
   
      void save_value_h9(String value_h9)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h9) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h9+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h9+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   } 

So I just want to add a simple GET request in the main loop to check the state of a Ubidots variable using the code below:

float value11 = client.getValue(ID);
Serial.println(value);

Any help is Greatly Appericated! :smiley:

Hey @SolarDude! first of all let’s check the memory being used by your code, it seems a bit long for an Arduino and this may cause trouble parsing a GET request. When you upload your code, there should be a window in the lower part of the IDE, what does it say?

@aguspg The code you see is very stable.

Here is the memory level.

The problem with adding the get request to this code is that I can’t get it to compile due to issues between Ethernet Client & Ubidots Client.

I tried your latest library you just posted to Github 3 days ago but it keeps giving me the error that I’m trying to send 5 consecutive variables and then does not sent anything to Ubidots. So I’m just sticking with this code for now. I can delete some of the text that is there now to make more room for the program storage.

@aguspg

Also I could not get the Ubidots GET example code by its self to work properly.

The JSON return had the correct state returned but the value would not update correctly.

Here is the return from the GET example:

And here is what would serial print:

Hello solar dude, how many variables you need to send? I can try to fix the library for you and giving more atettion for your request.
I need some things of you:

  1. Quantity of variables
  2. Your code
    In addition with this I will update the library and i need that you try with my example and give me the arduino response please.

Hey @metavix I’m happy that you are here to help :smiley:

Here are some answers to your questions.

  1. I need 11 Variables.

  2. I posted my working code in the first post. But here I will post the code I created using your latest Ethernet library that was just updated 4 days ago via your Github.

I could not get the code below to post any data to my Ubidots account. At first it would just give me this message:

You are sending 5 consecutive Variables, the rest will be deleted error message.

I found the code in the .cpp file where it has the max variable data which was set to 4 so I changed it to 11 which got rid of the error but then it never pushed any data over to Ubidots and I saw nothing on the Serial Monitor as output from the program.

Here is the code I created using your latest github Ethernet code:

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


#define ID  "56dbd26276254207a77f17dc"  // Voltage  
#define ID2 "56dbd265762542088bd9353e"  // Current
#define ID3 "56dbd23776254207d8704fcd"  // Power
#define ID4 "56dbd22476254206ffac0bbc"  // Soc
#define ID5  "56dbd25f762542088bd93536" // Consumed Energy 
#define ID6 "56dbd26976254208af6ba4b3"  // Time To Go
#define ID7 "56dbd26a7625420869504855"  // History 2
#define ID8 "56dbd26776254207a77f17e5"  // History 4
#define ID9  "56dbd27576254208441ef594" // History 6 
#define ID10 "56dbd9207625422dff9d9600" // History 9

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

int Relay = 2;

// 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, 0x01 };


Ubidots client(TOKEN);

void setup(){
  
  pinMode(Relay, OUTPUT);      //Set's Digital Pin 2 to a Output Pin
  digitalWrite(Relay, LOW);    // Turns off relay.
  
  // disable SD SPI
   pinMode(4,OUTPUT);
   digitalWrite(4,HIGH);  
  
  Serial.begin(19200);
   
    // start the Ethernet connection:
        if (Ethernet.begin(mac) == 0) {
       Serial.println("Failed to configure Ethernet using DHCP");
       // no point in carrying on, so do nothing forevermore:
       for(;;);
     
       // give the Ethernet shield a second to initialize:
       delay(1000);
       Serial.println("connecting...");
     }
  
  delay(3000);
}


void loop(){
    
   Serial.flush();
   Serial.begin(19200); 
   
     while (Serial.available() == 0);
      {
        char ch = Serial.read();
        if(ch == 'V') // Wait for the capital V and ignore any detritus before it. The capital V (Voltage) marks the beginning of the data thats what we actually want.
        {
   
   int V = Serial.parseInt(); //Battery Voltage
   
   int I = Serial.parseInt(); //Current in or out of the battery
   
   int P = Serial.parseInt(); //W Instantaneous power
   
   long CE = Serial.parseInt(); //Consumed Energy
   
   unsigned int SOC = Serial.parseInt(); //State of charge
   
   long TTG = Serial.parseInt(); //Time to Go
   
   //long AR = Serial.parseInt(); //Alarm relay state
   
   //long BMV = Serial.parseInt(); //The 600 part of 600S gets parsed as it is an integer
   
  // long FW = Serial.parseInt(); //Firmware version gets parsed as it is an integer
  
   long Ha = Serial.parseInt(); // This parses the "1" integer from "H1" The next line will parse actual the value of H1
   long H1 = Serial.parseInt(); //Depth of Deepest Discharge mAh
   
   long Hb = Serial.parseInt(); // This parses the "2" integer from "H2" The next line will parse the actual value of H2 etc.
   long H2 = Serial.parseInt(); //Depth of Last Discharge (mAh)
   
   //long Hc = Serial.parseInt();
   //long H3 = Serial.parseInt(); //Depth of Average Discharge (mAh)
   
   long Hd = Serial.parseInt();
   unsigned long H4 = Serial.parseInt(); //Number of Charge cycles
   
   long He = Serial.parseInt();
   unsigned long H5 = Serial.parseInt(); //Number of full discharges
   
   long Hf = Serial.parseInt();
   long H6 = Serial.parseInt(); //Cumulative Ah from battery (mAh)
   
   long Hg = Serial.parseInt();
   unsigned int H7 = Serial.parseInt(); //Minimum battery voltage (mV)
   
   long Hh = Serial.parseInt();
   unsigned int H8 = Serial.parseInt(); //Maximum battery voltage (mV)
   
   long Hi = Serial.parseInt();
   unsigned long H9 = Serial.parseInt(); //Hours since last full charge.
   
  // long Hj = Serial.parseInt();
   // unsigned long H10 = Serial.parseInt(); //Number of times BMV automatically synchronised
   
   //long Hk = Serial.parseInt();
   //unsigned long H11 = Serial.parseInt(); //Number of Low voltage alarms
   
   //long Hl = Serial.parseInt();
   //unsigned long H12 = Serial.parseInt(); //Number of High voltage alarms
   
  // long Hm = Serial.parseInt();
   //unsigned long H17 = Serial.parseInt(); //Amount of discharged energy
   
   //long Hn = Serial.parseInt();
   //unsigned long H18 = Serial.parseInt(); //Amount of charged energy
  
   //long BMV = Serial.parseInt(); //The 600 part of 600S gets parsed as it is an integer
   
   //long FW = Serial.parseInt(); //Firmware version gets parsed as it is an integer
   
   //long PID = Serial.parseInt(); //Product ID
   

  
  if ((V /1000.00) > 8)
{
 // Serial.println("");
 // Serial.println("---------------------------------------"); 
 // Serial.println ("Voltage Above 8V - Send Data");
 // Serial.println("---------------------------------------"); 
 // Serial.println("");
 
   //Code to send variable to Ubidots 
   
   float value = (V /1000.00);  //voltage
   float value2 = (I /1000.00);  //current
   int  value3 = P;                //power
   int value4 = (SOC / 10);          //soc
   float value5 = (CE /1000.000);     //ce
   float value6 = (TTG /60.00);      //ttg
   float value7 = (H2 /1000.00);      //h2
   float value8 = H4;                 //h4
   float value9 = (H6 /1000.00);      //h6
   float value10 = (H9 /86400.00);     //h9
   
    client.add(ID, value);
    client.add(ID2, value2);
    client.add(ID3, value3);
    client.add(ID4, value4);
    client.add(ID5, value5);
    client.add(ID6, value6);
    client.add(ID7, value7);
    client.add(ID8, value8);
    client.add(ID9, value9);
    client.add(ID10, value10);
    client.sendAll();
    
   

 // Serial.println("");
 // Serial.println("---------------------------------------");
 // Serial.println("All Send Functions Complete");
 // Serial.println("---------------------------------------");
 // Serial.println("");
  
  Serial.end(); 
  delay(1000 * 30);
  
}
else
{
  
 
 // Do Nothing. Wait till next reading. 
  
 //  Serial.println("");
 //  Serial.println("---------------------------------------");
 //  Serial.println("Votage Reading Below 8V - Discard Data");
 //  Serial.println("---------------------------------------");
 //  Serial.println("");
  
  Serial.end(); 
  delay(1000);
  
}
  }
    }
}

This is being ran on a Arduino Uno R3 with Wiz Ethernet shield.

Thank you very much for helping out with this, I really appreciate it.

@SolarDude @Metavix let’s try modifying the library and test it then. However, keep in mind that the max variable limit is intentional because sending more variables would make the http request too long for the average Arduino shields, causing problems.

The easiest way around this would be to call the function 3 times, smt like this:

client.add(ID1, value);
client.add(ID2, value2);
client.add(ID3, value3);
client.add(ID4, value4);
client.sendAll();
client.add(ID5, value5);
client.add(ID6, value6);
client.add(ID7, value7);
client.add(ID8, value8);
client.sendAll();
client.add(ID9, value9);
client.add(ID10, value10);
client.add(ID11, value11);
client.sendAll();

@aguspg Yep I tried doing that also but it still did not send. I tried only sending 2 variables and still the data did not transfer to Ubidots when using your latest Ethernet code I posted above.

hey @SolarDude I change some things in the library I think that you code will work fine now, by the way i need you change these lines:

for this:

    client.add(ID, value);
    client.add(ID2, value2);
    client.add(ID3, value3);
    client.add(ID4, value4);
    client.add(ID5, value5);
    client.sendAll();
    client.add(ID6, value6);
    client.add(ID7, value7);
    client.add(ID8, value8);
    client.add(ID9, value9);
    client.sendAll();
    client.add(ID10, value10);
    client.sendAll();

Don’t forget download the library one more time here GitHub - ubidots/ubidots-arduino-ethernet: Ubidots-Ethernet is an Arduino library for interacting with Ubidots through its API with the Arduino ethernet shield.
cya :smiley:

@metavix @aguspg

OK I updated the .cpp file and added the client.add code change and it compiles just fine.

But its looking like all 3 attempts to send the variable data fail due to a connection failure. The connection is fine and runs just fine.

Here is the first serial print I get from the new code:

Here is the code I created using your latest library that is returning the connection failed.

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


#define ID  "56dbd26276254207a77f17dc"  // Voltage  
#define ID2 "56dbd265762542088bd9353e"  // Current
#define ID3 "56dbd23776254207d8704fcd"  // Power
#define ID4 "56dbd22476254206ffac0bbc"  // Soc
#define ID5  "56dbd25f762542088bd93536" // Consumed Energy 
#define ID6 "56dbd26976254208af6ba4b3"  // Time To Go
#define ID7 "56dbd26a7625420869504855"  // History 2
#define ID8 "56dbd26776254207a77f17e5"  // History 4
#define ID9  "56dbd27576254208441ef594" // History 6 
#define ID10 "56dbd9207625422dff9d9600" // History 9

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

int Relay = 2;

// 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, 0x01 };


Ubidots client(TOKEN);

void setup(){
  
  pinMode(Relay, OUTPUT);      //Set's Digital Pin 2 to a Output Pin
  digitalWrite(Relay, LOW);    // Turns off relay.
  
  // disable SD SPI
   pinMode(4,OUTPUT);
   digitalWrite(4,HIGH);  
  
  Serial.begin(19200);
   
    // start the Ethernet connection:
        if (Ethernet.begin(mac) == 0) {
       Serial.println("Failed to configure Ethernet using DHCP");
       // no point in carrying on, so do nothing forevermore:
       for(;;);
     
       // give the Ethernet shield a second to initialize:
       delay(1000);
       Serial.println("connecting...");
     }
  
  delay(3000);
}


void loop(){
    
   Serial.flush();
   Serial.begin(19200); 
   
     while (Serial.available() == 0);
      {
        char ch = Serial.read();
        if(ch == 'V') // Wait for the capital V and ignore any detritus before it. The capital V (Voltage) marks the beginning of the data thats what we actually want.
        {
   
   int V = Serial.parseInt(); //Battery Voltage
   
   int I = Serial.parseInt(); //Current in or out of the battery
   
   int P = Serial.parseInt(); //W Instantaneous power
   
   long CE = Serial.parseInt(); //Consumed Energy
   
   unsigned int SOC = Serial.parseInt(); //State of charge
   
   long TTG = Serial.parseInt(); //Time to Go
   
   //long AR = Serial.parseInt(); //Alarm relay state
   
   //long BMV = Serial.parseInt(); //The 600 part of 600S gets parsed as it is an integer
   
  // long FW = Serial.parseInt(); //Firmware version gets parsed as it is an integer
  
   long Ha = Serial.parseInt(); // This parses the "1" integer from "H1" The next line will parse actual the value of H1
   long H1 = Serial.parseInt(); //Depth of Deepest Discharge mAh
   
   long Hb = Serial.parseInt(); // This parses the "2" integer from "H2" The next line will parse the actual value of H2 etc.
   long H2 = Serial.parseInt(); //Depth of Last Discharge (mAh)
   
   //long Hc = Serial.parseInt();
   //long H3 = Serial.parseInt(); //Depth of Average Discharge (mAh)
   
   long Hd = Serial.parseInt();
   unsigned long H4 = Serial.parseInt(); //Number of Charge cycles
   
   long He = Serial.parseInt();
   unsigned long H5 = Serial.parseInt(); //Number of full discharges
   
   long Hf = Serial.parseInt();
   long H6 = Serial.parseInt(); //Cumulative Ah from battery (mAh)
   
   long Hg = Serial.parseInt();
   unsigned int H7 = Serial.parseInt(); //Minimum battery voltage (mV)
   
   long Hh = Serial.parseInt();
   unsigned int H8 = Serial.parseInt(); //Maximum battery voltage (mV)
   
   long Hi = Serial.parseInt();
   unsigned long H9 = Serial.parseInt(); //Hours since last full charge.
   
  // long Hj = Serial.parseInt();
   // unsigned long H10 = Serial.parseInt(); //Number of times BMV automatically synchronised
   
   //long Hk = Serial.parseInt();
   //unsigned long H11 = Serial.parseInt(); //Number of Low voltage alarms
   
   //long Hl = Serial.parseInt();
   //unsigned long H12 = Serial.parseInt(); //Number of High voltage alarms
   
  // long Hm = Serial.parseInt();
   //unsigned long H17 = Serial.parseInt(); //Amount of discharged energy
   
   //long Hn = Serial.parseInt();
   //unsigned long H18 = Serial.parseInt(); //Amount of charged energy
  
   //long BMV = Serial.parseInt(); //The 600 part of 600S gets parsed as it is an integer
   
   //long FW = Serial.parseInt(); //Firmware version gets parsed as it is an integer
   
   //long PID = Serial.parseInt(); //Product ID
   

  
  if ((V /1000.00) > 8)
{
    Serial.println("");
    Serial.println("---------------------------------------"); 
    Serial.println ("Voltage Above 8V - Send Data");
    Serial.println("---------------------------------------"); 
    Serial.println("");
 
   //Code to send variable to Ubidots 
   
   float value = (V /1000.00);  //voltage
   float value2 = (I /1000.00);  //current
   int  value3 = P;                //power
   int value4 = (SOC / 10);          //soc
   float value5 = (CE /1000.000);     //ce
   float value6 = (TTG /60.00);      //ttg
   float value7 = (H2 /1000.00);      //h2
   float value8 = H4;                 //h4
   float value9 = (H6 /1000.00);      //h6
   float value10 = (H9 /86400.00);     //h9
   
    client.add(ID, value);
    client.add(ID2, value2);
    client.add(ID3, value3);
    client.add(ID4, value4);
    client.add(ID5, value5);
    client.sendAll();
    client.add(ID6, value6);
    client.add(ID7, value7);
    client.add(ID8, value8);
    client.add(ID9, value9);
    client.sendAll();
    client.add(ID10, value10);
    client.sendAll();
    
   

  Serial.println("");
  Serial.println("---------------------------------------");
  Serial.println("All Send Functions Complete");
  Serial.println("---------------------------------------");
  Serial.println("");
  
  Serial.end(); 
  delay(1000 * 30);
  
}
else
{
  
 
 // Do Nothing. Wait till next reading. 
  
   Serial.println("");
   Serial.println("---------------------------------------");
   Serial.println("Votage Reading Below 8V - Discard Data");
   Serial.println("---------------------------------------");
   Serial.println("");
  
  Serial.end(); 
  delay(1000);
  
}
  }
    }
}

Here is the code that works perfectly.

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

#define ID  "56dc7b147625422fb6ec085d"  // Put here your Ubidots variable ID
#define TOKEN  "ZCZxcFGzfyB1mFTztUFnUaj8K0ZIt4"  // 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, 0x01 }; 

  

   EthernetClient client;

   String idvariable = "56dbd26276254207a77f17dc"; //
   String idvariable_current = "56dbd265762542088bd9353e"; //
   String idvariable_power = "56dbd23776254207d8704fcd"; //
   String idvariable_soc = "56dbd22476254206ffac0bbc"; //
   String idvariable_ce = "56dbd25f762542088bd93536"; //
   String idvariable_ttg = "56dbd26976254208af6ba4b3"; //
   String idvariable_h2 = "56dbd26a7625420869504855"; //
   String idvariable_h4 = "56dbd26776254207a77f17e5"; //
   String idvariable_h6 = "56dbd27576254208441ef594"; //
   String idvariable_h9 = "56dbd9207625422dff9d9600"; //
  
   String token = "ZCZxcFGzfyB1mFTztUFnUaj8K0ZIt4";  //O
  


int Relay = 2;



void setup() {
   
  pinMode(Relay, OUTPUT);      //Set's Digital Pin 2 to a Output Pin
  digitalWrite(Relay, LOW);    // Turns off relay.
  
  // disable SD SPI
   pinMode(4,OUTPUT);
   digitalWrite(4,HIGH);
  
  //Baud is set to 19200 because this is the baud that the BMV-600 transmits at.
   Serial.begin(19200);
  
  //Serial.println("BMV Battery Monitor");
  //Serial.println("==========================");
  
  delay(1000);
  
  
  // start the Ethernet connection:
     
     if (Ethernet.begin(mac) == 0) {
       Serial.println("Failed to configure Ethernet using DHCP");
       // no point in carrying on, so do nothing forevermore:
       for(;;);
     
       // give the Ethernet shield a second to initialize:
       delay(1000);
       Serial.println("connecting...");
     }
  
  delay(3000);
  
}





void loop() {
  
  // main program loop
  
  


 Serial.flush();
 Serial.begin(19200); 
 
 
    
     while (Serial.available() == 0);
      {
        char ch = Serial.read();
        if(ch == 'V') // Wait for the capital V and ignore any detritus before it. The capital V (Voltage) marks the beginning of the data thats what we actually want.
        {
   
   int V = Serial.parseInt(); //Battery Voltage
   
   int I = Serial.parseInt(); //Current in or out of the battery
   
   int P = Serial.parseInt(); //W Instantaneous power
   
   long CE = Serial.parseInt(); //Consumed Energy
   
   unsigned int SOC = Serial.parseInt(); //State of charge
   
   long TTG = Serial.parseInt(); //Time to Go
   
   long AR = Serial.parseInt(); //Alarm relay state
   
   long BMV = Serial.parseInt(); //The 600 part of 600S gets parsed as it is an integer
   
   long FW = Serial.parseInt(); //Firmware version gets parsed as it is an integer
  
   long Ha = Serial.parseInt(); // This parses the "1" integer from "H1" The next line will parse actual the value of H1
   long H1 = Serial.parseInt(); //Depth of Deepest Discharge mAh
   
   long Hb = Serial.parseInt(); // This parses the "2" integer from "H2" The next line will parse the actual value of H2 etc.
   long H2 = Serial.parseInt(); //Depth of Last Discharge (mAh)
   
   long Hc = Serial.parseInt();
   long H3 = Serial.parseInt(); //Depth of Average Discharge (mAh)
   
   long Hd = Serial.parseInt();
   unsigned long H4 = Serial.parseInt(); //Number of Charge cycles
   
   long He = Serial.parseInt();
   unsigned long H5 = Serial.parseInt(); //Number of full discharges
   
   long Hf = Serial.parseInt();
   long H6 = Serial.parseInt(); //Cumulative Ah from battery (mAh)
   
   long Hg = Serial.parseInt();
   unsigned int H7 = Serial.parseInt(); //Minimum battery voltage (mV)
   
   long Hh = Serial.parseInt();
   unsigned int H8 = Serial.parseInt(); //Maximum battery voltage (mV)
   
   long Hi = Serial.parseInt();
   unsigned long H9 = Serial.parseInt(); //Hours since last full charge.
   
  // long Hj = Serial.parseInt();
   // unsigned long H10 = Serial.parseInt(); //Number of times BMV automatically synchronised
   
   //long Hk = Serial.parseInt();
   //unsigned long H11 = Serial.parseInt(); //Number of Low voltage alarms
   
   //long Hl = Serial.parseInt();
   //unsigned long H12 = Serial.parseInt(); //Number of High voltage alarms
   
  // long Hm = Serial.parseInt();
   //unsigned long H17 = Serial.parseInt(); //Amount of discharged energy
   
   //long Hn = Serial.parseInt();
   //unsigned long H18 = Serial.parseInt(); //Amount of charged energy
  



  
  if ((V /1000.00) > 8)
{
 // Serial.println("");
 // Serial.println("---------------------------------------"); 
 // Serial.println ("Voltage Above 8V - Send Data");
 // Serial.println("---------------------------------------"); 
 // Serial.println("");
 
   //Code to send variable to Ubidots
  
   float value = (V /1000.00);
   float value_current = (I /1000.00);
   int  value_power = P;
   int value_soc = (SOC / 10);
   float value_ce = (CE /1000.000);
   float value_ttg = (TTG /60.00);
   float value_h2 = (H2 /1000.00);
   float value_h4 = H4;
   float value_h6 = (H6 /1000.00);
   float value_h9 = (H9 /86400.00);
   
   save_value(String(value)); 
   save_value_current(String(value_current)); 
   save_value_power(String(value_power)); 
   save_value_soc(String(value_soc)); 
   save_value_ce(String(value_ce));
   save_value_ttg(String(value_ttg));
   save_value_h2(String(value_h2));
   save_value_h4(String(value_h4));
   save_value_h6(String(value_h6));
   save_value_h9(String(value_h9));
  
 // Serial.println("");
 // Serial.println("---------------------------------------");
 // Serial.println("All Send Functions Complete");
 // Serial.println("---------------------------------------");
  //Serial.println("");
  
 
  
  Serial.end(); 
  delay(1000 * 30);
  
}
else
{
  
 
  // Do Nothing. Wait till next reading. 
  
 // Serial.println("");
 // Serial.println("---------------------------------------");
 // Serial.println("Votage Reading Below 8V - Discard Data");
//  Serial.println("---------------------------------------");
//  Serial.println("");
  
  Serial.end(); 
  delay(1000);
  
}
  }
    }
}

    
       
  void save_value(String value)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
      Serial.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
      Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
      Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
      Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
      Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

    if (!client.connected())
     {
        Serial.println();
        Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
        Serial.print(c);
     }
     client.flush();
     client.stop();

   }  

 
 void save_value_current(String value_current)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_current) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_current+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_current+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }  
   
   
   
   void save_value_power(String value_power)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_power) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_power+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_power+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }  
   
 
 
 void save_value_soc(String value_soc)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_soc) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_soc+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_soc+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
    void save_value_ce(String value_ce)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_ce) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_ce+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_ce+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
    void save_value_ttg(String value_ttg)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_ttg) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_ttg+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_ttg+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
    void save_value_h2(String value_h2)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h2) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h2+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h2+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
   
   
    void save_value_h4(String value_h4)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h4) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h4+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h4+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
   
   
   
   
    void save_value_h6(String value_h6)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h6) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h6+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h6+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   }    
   
   
   
   
      void save_value_h9(String value_h9)
   {
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value_h9) + "}";
     num = var.length();
     delay(300);
     if(client.connect("things.ubidots.com", 80))
     {
       Serial.println("connected");

       // New lines according to ubidots support:

       client.println("POST /api/v1.6/variables/"+idvariable_h9+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable_h9+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

     if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

     if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

   } 

I’m assuming there is something wrong with the send function you just updated but I’m not sure.

Would it be easier to try to just add in a Ubidots GET request to the code that is working fine? I just need to know when a switch widget in my dashboard changes so I can flip a relay ON or OFF based on the switch condition 1 or 0.

Let me know what you find out.

@SolarDude, it isn’t easier because the memory of Arduino addin another function maybe destroy garbage collector, the problem with the working code is that you are creating a lot of save_value function, and you only need one then the memory of arduino is very stressed out.
By the way i change the github code try please.

@metavix @aguspg

I updated to your latest .cpp code and it looks to be trying to post all 3 of the send all events but it still is not connecting for some reason.

Here is the serial output:

---------------------------------------
Voltage Above 8V - Send Data
---------------------------------------

Posting your variables
HTTP/1.1 404 NOT FOUND
Server: nginx
Date: Wed, 09 Mar 2016 23:36:54 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

17
{"detail": "Not found"}
0

Posting your variables
HTTP/1.1 404 NOT FOUND
Server: nginx
Date: Wed, 09 Mar 2016 23:36:55 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

17
{"detail": "Not found"}
0

Posting your variables
HTTP/1.1 404 NOT FOUND
Server: nginx
Date: Wed, 09 Mar 2016 23:36:56 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

17
{"detail": "Not found"}
0

What does the {“detail”: “Not found”} mean?

@SolarDude heyy we to close!!! I think thath I finish with our library problem, download it again now if it doesn’t work I will make you a personal code for you

@Metavix Yes its all good now :smiley:

I’m successfully sending data using the new library now which is great news :smiley:

Now how do I add a get request without screwing up the current SendAll code? Can you provide a example that works with the send all functions of the new library?

---------------------------------------
Voltage Above 8V - Send Data
---------------------------------------

Posting your variables
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Mar 2016 17:54:49 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

6e
[{"status_code": 201}, {"status_code": 201}, {"status_code": 201}, {"status_code": 201}, {"status_code": 201}]
0

Posting your variables
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Mar 2016 17:54:50 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

58
[{"status_code": 201}, {"status_code": 201}, {"status_code": 201}, {"status_code": 201}]
0

Posting your variables
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 10 Mar 2016 17:54:50 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

16
[{"status_code": 201}]
0


---------------------------------------
All Send Functions Complete
---------------------------------------

oh nice, now for the get code you only need to add:

float value = client.getValue(ID);
Serial.println(value);

Ok I added the following line of code to the sketch and it compiles just fine.

It seems to be working but it’s not fetching the correct value from the returned JSON string which does have the correct data in it.

Here is the code I’m using:

 float value11 = client.getValue(ID11);
   Serial.print("Switch State =  ");
   Serial.println(value11);
    if (value11 == 1.0) {     
    // turn LED on:    
    digitalWrite(Relay, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(Relay, LOW); 
  } 

The switch is in the 1 / ON state which is shown in the returned JSON string below:

148
{"count": 79, "next": "http://things.ubidots.com/api/v1.6/variables/56dc7b147625422fb6ec085d/values?page=2&page_size=1", "previous": null, "results": [{"url": "http://things.ubidots.com/api/v1.6/values/56df0b2552fdbb0447125063", "value": 1.0, "timestamp": 1457457957624, "context": {}, "created_at": "2016-03-08T17:25:57.624"}]}
0


Switch State =  0.00

Can you take a look at the GET code and see if anything needs to be changed. This has never worked for me.

Thanks for all your help with this.

I’m on it my friend! give me some minutes please

@SolarDude you can try now, dowload the lastest library! and tell me if it works!

@metavix @aguspg

All is working now :smile:

Thank you very much.

Looks like your new library is all good to go now :smiley:

:smiley: awesome, thank you for helping us turn a work-in-progress library into a stable one!

1 Like