[SOLVED] Arduino Uno Ethernet is not getting value from Ubidots (getValue)

Hi All, Thanks for helping me.

I am trying to add my device to get value from Ubidots.com so I can control a switch or a relay but I am not successful even when I am using the default example:-1:
My code is as below:-


#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>
char const ID = "5a2b91da180cae385e86afdd";
char const TOKEN = "xxxxxxxxxxxVcAjXgLIPAj3Gxxxxxx";
char const Label = "Switch8";


byte mac[] = { 0xDE, 0x00, 0x00, 0xEF, 0xFE, 0xED };

IPAddress ip(192, 168, 137, 150);

Ubidots client(TOKEN);
void setup() {
  Serial.begin(9600);
  //client.setDebug(true);// uncomment this line to visualize the debug message
  
   if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    Ethernet.begin(mac, ip);
  }
  delay(1000);
}

void loop() {
 
  float value = client.getValue(ID, Label);
   Serial.print("the value received is:  ");
  Serial.println(value);
  delay(5000);
}
    indent preformatted text by 4 spaces 

And the result of the serials is as below:-


HTTP/1.1 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

400 Bad request

Your browser sent an invalid request.

the value received is: 0.00


Thanks
Rassim

Hello @Rassim,

We’re going to try to reproduce your issue and will let you know. Btw, we have been working on a new version of the Arduino Ubidots Ethernet Library which will be available this week, into this version we fixed some memory issues, so I recommend you to use this one once is available :grinning:

All the best,
Maria C.

The Library is available at the Ubidots Repository, please go to the following link to download the new version. Everything is working properly, so you should not have any issue getting started with it.

All the best,
Maria C.

Thanks @mariahernandez, but not [solved] , as there is no update for the values recievied from the ubidots site

As you can see the below is the serial port display response:-

Starting ethernet...192.168.137.41

Ready
HTTP/1.1 404 Not Found
Server: nginx
Date: Wed, 13 Dec 2017 04:18:33 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Cookie
Allow: GET, HEAD, OPTIONS

18
{“detail”: “Not found.”}
0

the value received is: 0.00
HTTP/1.1 404 Not Found
Server: nginx
Date: Wed, 13 Dec 2017 04:18:39 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Cookie
Allow: GET, HEAD, OPTIONS

18
{“detail”: “Not found.”}
0

the value received is: 0.00
HTTP/1.1 404 Not Found
Server: nginx
Date: Wed, 13 Dec 2017 04:18:1234:
Preformatted text

and for long time there is no update and only connects for the first few second:-

Please help.

Dear user,

The reponse of the server obtained is 404, which means “Not Found – We couldn’t find the variable or Device you are trying to access. Verify your token and item’s ID”. To know the meaning of all the response, please reference to the following link. In order of this, please verify the credentials assigned.

As I can see in your code, you are following an old example using variables ID. Please, reference to the new get example here. It is important to mention that the device and variable label assigned in the code have to be created before upload the code into the board.

If you a not familiar using API labels, you can see the following article which will help you to understand the they works and where you can find them.

All the best,
Maria C.

Hi @mariahernandez, and thanks for your reply and follow up.

I tried these guides you already provided and I am sure that I am using the correct ones, but the same:-

I am using the default example provided by your updated library.

Let me explain something:-

1-When I try only get value, it is not connecting.
2-When I try only Sendvalue, it connects normally and easily and all values are updated normally to ubidots.
3-When I tried to mix get and send value using the example of send and mixing getvalue with it, it works for some time and disconnects sometime.

As I tried and got some indication that it is may be all related to the malloc that assigned in the getvalue function in the main UbidotsEthernet.cpp file, it makes the issue and need to be resolved.

Thanks to consider my point.

Please check and help.

Hello @Rassim,

I have been testing the library and regrettably I’m not able to reproduce your inconvenience. Are you sure that you are the last version updated? Arduino Ethernet Ubidots

  1. As you can see below using the UbidotsGetValue example, the device is connecting and receiving the value properly:

  1. All the POST examples are working properly:


  1. Mixing the POST and GET examples are working properly without any inconvenience with the connection. In this case, I recommend you verify your connection directly.

The Ubidots Libraries are built for the users as initials tools to start with their devices easily with the platform, then they can build their our example making the request to the platform directly following the Ubidots REST API Refence. Also, it is important highlight the License of the Library, so if you considere an issue in the library feel free to contribute to it and we will be happy to check the PR! :wink:

All the best,
Maria C.

Thanks @mariahernandez for the efforts, what I did today,
1- I downloaded the library you referred the link again and installed it.
2- I copied you code for get value and put my credentials, device and variable labels as you already used.

But the result is the same:- BTW I am using Arduino (UNO) with ethernet Shield, your trial is also with the same Uno type?

/********************************
 * Libraries included
 *******************************/
#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>

/********************************
 * Constants and objects
 *******************************/
/* Assigns the Ubidots parameters */
char const * TOKEN = "BBFF-2rsWTmelVcAjXgLIPAj3G9myUdYV9I"; // Assign your Ubidots TOKEN
char const * DEVICE_LABEL = "Ard121"; // Assign the unique device label
char const * VARIABLE_LABEL = "S11"; // Assign the unique variable label to get the last value

/* 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 };

/* initialize the instance */
Ubidots client(TOKEN);

/********************************
 * Main Functions
 *******************************/
void setup() {
  Serial.begin(9600);
  //client.setDebug(true);// uncomment this line to visualize the debug message
  /* start the Ethernet connection */
  Serial.print(F("Starting ethernet..."));
  if (!Ethernet.begin(mac)) {
    Serial.println(F("failed"));
  } else {
    Serial.println(Ethernet.localIP());
  }
  /* Give the Ethernet shield a second to initialize */
  delay(2000);
  Serial.println(F("Ready"));
}

void loop() {
  Ethernet.maintain();
  /* Getting the last value from a variable */
  float value = client.getValue(DEVICE_LABEL, VARIABLE_LABEL);
  /* Print the value obtained */
  Serial.print("the value received is:  ");
  Serial.println(value);
  delay(5000);
}```

Thanks for your time and efforts again.

At first, I recommend you try the example provided in the Arduino IDE - Examples > Ethernet > WebClient, in order to verify the right functionality of the device. If everything okay, you should not have any inconvenience with it, but if the inconvenience persist using the Ubidots library and not with the WebClient example I recommend you build your own script based on this example making the GET request to the Ubidots API.

I can see on the image above that the device called “Ard121” says No last activity that means the variable that you are trying to get do not have any value yet. Please, make the test with an variable which had data available to retreive.

I’m using the Arduino UNO too, probably the inconvenience is related with the shield, and regrettably that is out of our scope.

All the best,
Maria C.