My apologies - I mistakenly replied to a [Solved]previous thread - which was probably bad form.
I am having a similar problem to others using the Particle Ubidots library (v2.1.9)- values returned are always 0 regardless if using the .getValue() or getValueWithDatasource. I have no problem sending data. I was also concerned that I might be using the incorrect data source name - although I have tried both the name I provided in the Dashboard (say myAlarm) or the Particle Photon device ID. Which is correct?
thanks David
Yes, I was using the same tag as shows up in the API label (also the same as the device ID). Also the simple getValue (no tags) also returns 0
thanks
David
I’ve been tested the library with the particle electron and works fine for me. At the moment I don’t have a Particle Photon to reply the error, but the next week I could make a test!
If I get the same issue I’ll check the library for verify the problem, I’ll let you know any advance.
I have made a test with this script sucessfully, would you try it:
// This example is to get the last value of variable from the Ubidots API
#include "Ubidots.h"
#define TOKEN "....." // Put here your Ubidots TOKEN
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
}
void loop() {
float value;
value = ubidots.getValue("58dbc1a37625427df19449e3");
Serial.println(value);
delay(5000);
}
Please be sure that you are using the last version of our library (2.9) in the Particle’s IDE.
Yup I try this option and yup is working couple time and that is it.
I have exactly the same issue like agardd described on first post, on the top.
Thank you
Arek
Maria
While the simple code using getValue & the numerical id for the variable works (as opposed to the variable name such as “variable4” which doesn’t), if I try to use 2 getValue calls, the red SOS light starts flashing. Any suggestions?
thanks
Thanks - is the getValueWithDataSource routine any more usable?
Re using MQTT, I had actually started with that, but then switched upon advice from this forum when I started getting compiler errors in the 0.4.8 version (already discussed). As a new user of Particle/Ubidots, I am a bit frustrated with the instabilities, yet greatly appreciate the efforts to sort it all out.
Hello @agardd, Actually I’m updating the MQTT library because it was outdated, I hope to have it ready this week, meanwhile I attach you an example for using MQTT on your particle devices:
/****************************************
* Include Libraries
****************************************/
#include "MQTT/MQTT.h"
/****************************************
* Define Constants
****************************************/
#ifndef TOKEN
#define TOKEN "...." // Add here your Ubidots TOKEN
#endif
/****************************************
* Auxiliar Functions
****************************************/
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
Serial.println("payload obtained from server:");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]); // prints the answer of the broker for debug purpose
}
// Some stuff to make with the payload obtained
// ......
//
Serial.println();
}
/****************************************
* Instances
****************************************/
MQTT client = MQTT("things.ubidots.com", 1883, callback, 512);
String clientName = "";
/****************************************
* Main Functions
****************************************/
void setup() {
Serial.begin(115200);
clientName = System.deviceID();
client.connect(clientName, TOKEN, NULL);
if(client.isConnected()){
client.subscribe("/v1.6/devices/my-device/my-variable/lv");
}
}
void loop() {
if(!client.isConnected()){
Serial.println("attemping to connect");
}
while(!client.isConnected()){
client.connect(clientName, TOKEN, NULL);
Serial.print(".");
delay(5000);
}
Serial.println("connected");
client.publish("/v1.6/devices/test-m", "{\"test-var\":1}"); // Publish to device 'test-m' and variable 'test-var'
client.subscribe("/v1.6/devices/my-device/my-variable/lv"); // Subscribe to 'my-variable' at 'my-device' device
client.loop();
delay(1000);
}
@dreamER I recently made an update for the getting value function, I tested it for somedays but if it still has issues I’d like to know more about them, would you please use the setDebug() function and post the message?
I’ve released a new version for the Ubidots HTTP and MQTT libraries, I’ve tested them and it seems to work properly, I’ll thankful a lot you if you can test them and to let me know any issues.
I using Serial1 for debug with raspberry pi which is monitoring serial data all day long and this errors are happen very rarely and without any rules.
Regarding to new MQTT library which I start testing yesterday.
UbidotsMQTT.h line 34 #define MAX_VALUES 5 that’s is not enough for me, so I attach library manually to be able to handle more.
Every things works fine without memory crash. Public() works perfect ! (since from yesterday)
Subscribe() works weird I mean , I can play for even 30min. (I didn’t try for more) to turn on/off LED or some other stuff and works like charm! but when I stop for lets see 5min. (close web browser ) then I try again and is not working. Then I got client.reconnect (debug message) which was confirmed successful but after still not work.
So I use particle.function() with System.reset(); and this help I mean is starting and working again
I’m kind off busy right now but when I found some free time I will post Debug messages.
Hello Gentlemen’s and Ladies i’m blind or even worse!
I forgot to add
client.ubidotsSubscribe(“My_Dev_API_Label”, “My_var_API_Label”); in to the Main Loop();
upssss…
So far everythings works awesome !!!
Sorry jotathebest for bothering
and Thank You very much !!!
Hello @dreamER I’m glad to listen that the library works for you, about the ‘OK|Ok|Ok’ answer when using our other library this happens because by default the protocol to send data is UDP, as UDP doesn’t maintain connection or waits for answer from the server sometimes the data is sent too fast that the connection gets closed before getting any answer on the device side so answers are queued (this happens sometimes and depends of different things like internet speed at moment, routine process or server charge), once you send again a message via UDP you will get all the queued which is the ‘OK|Ok|Ok’. As UDP uses a translate service in our side and not our API I made some guards and that is why the get value functions returns a NULL in case of wrong answers and that is what I check in the loop() routine of the examples. Btw, if you use TCP you won’t get multiple answers because TCP maintains connections but have a greater data cost (in kB) than UDP.
Hello @jotathebest
From my limited testing so far with the Ubidots library, the getValue and getValueWithDataSource sometimes work fine and others return Null. While I am happy to test for Null and only then use the value - this only works with getting data from a slider in the Ubidots dashboard. When I try to get data from an on-off switch, I get a 1 for false but a Null for true.
Any suggestions?
thanks
Hello @agardd, it shouldn’t make any difference if you use a button or a slider because both of them has as unique function to set a value, can you set the setDebug() method to true and print what you get on your serial console?
Hello @jotathebest
I have tried it and using a call to getValue() if the variable is attached to an on/of, it returns Null for true even though the debug says OK|0
when set to false it returns fine
I get a similar behavior if I use getValueWithDataSourceLabel
Data on a slider returns fine
here is the code fragment
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
ubidots.setDebug(true); //Uncomment this line for printing debug messages
}
void loop() {
float value1;
value1 = ubidots.getValue(VAR_ID);
if(value1!=NULL){
Serial.println(value1);
} else Serial.println("error on value1”);
Getting your variable with request:
Particle/2.1.10|GET|B7epEiEdBNs6swBJzs4AYedzeQTa9W|58fcba417625420d823155f9|end
response:
OK|0
Value obtained:
0
error on value1
Getting your variable with request:
Particle/2.1.10|GET|B7epEiEdBNs6swBJzs4AYedzeQTa9W|58fcba417625420d823155f9|end
response:
OK|1
Value obtained:
1
1.00