Hi from Italy.
I use Ubidots library with my Arduino and I can send successfully float values to my dashboard.
But I have troubles with dynamic string variables (I receive a Json double quote(?) error).
For example:
char myGlobalArray[10];
ReadDeviceStatus(); // this function update a global char array
client.add(VARIABLE_LABEL_1, 2, myGlobalArray);
client.sendAll();
I had to format text in some way with sprintf?
Thanks.
Marco
As first, can you specify is which is the library used by you? Thanks!
Reviewing the portion of code provided, I note that you are trying to send a char array as context of a variable, right? For this you can reference to this sample code where show how to build the context using the sprintf method.
I use Ubidots-Arduino-Ethernet library (as suggested in your article “Connect the Arduino UNO with Ubidots using the Arduino Ethernet Shield”).
Now it seems that I have other problems with timers in my sketch…I’ll do other tests and I will update you as soon as possible (I’ll paste my real sketch).
Thank you so much.
Marco
You are trying to send mydataRec.program as context of a variable, when the real context should be the char built with the sprintf method which is contextProg. Also, I recommend you print the variable contextProg after built it in order to check if was built properly. You should have something like below:
Just to give you a better idea, take as reference the code below:
/* Sends latitude and longitude for watching position in a map */
char context[25];
sprintf(context, "\"lat\":1.2343, \"lng\":132.1233");
client.add(VARIABLE_LABEL, 1, context);
client.sendAll();
Hi Maria
Now seems to work!
I have issue with transmission of multiple context, but I think it’s due to a memory lack (I trust I can solve it).
Thank you very much.
I’ll keep you updated.
Marco
Hello Maria,
Since I could change this code with floating variables, I need my GPS module to obtain latitude and longitude and those coordinates are the ones that I assign to my conductivity variable.
Thanks in advance.
/* Sends latitude and longitude for watching position in a map */
char context[25];
sprintf(context, ““lat”:1.2343, “lng”:132.1233”);
client.add(VARIABLE_LABEL, 1, context);
client.sendAll();
I’m using the example “UbidotsSaveValuesWithContext from the library” UbidotsEthernet.h "
/********************************
* Libraries included
*******************************/
#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>
/********************************
* Constants and objects
*******************************/
/* Assigns the Ubidots parameters */
char const * TOKEN = "Assign_your_Ubidots_TOKEN_here"; // Assign your Ubidots TOKEN
char const * VARIABLE_LABEL = "position"; // Assign the unique variable label to send the data
/* 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();
/* Sends latitude and longitude for watching position in a map */
char context[25];
**_sprintf(context, "\"lat\":1.2343, \"lng\":132.1233");_**
client.add(VARIABLE_LABEL, 1, context);
client.sendAll();
delay(5000);
}
I need to be able to enter the latitude and longitude measured by the GPS.
Greetings, you need to read the coordinates from your module (usually float type variables) and cast them to char type to be added into the context. You can reference some examples in the link to our docs posted in my previous reply.