VasilisP asked:
Now I am trying to send more variables but the only way described in the tutorial is using curl…Is it possible to send a collection of variables to ubidots using the code provided by @chipmc ?
VasilisP asked:
Now I am trying to send more variables but the only way described in the tutorial is using curl…Is it possible to send a collection of variables to ubidots using the code provided by @chipmc ?
Following the API instructions on how to post multiple variables (http://ubidots.com/docs/api/v1_6/collections/post_values.html) you can easily modify the code to send multiple variables. We just need to change the URL and the BODY of your HTTP request. Here’s an example:
In the declaration of the program’s variables, specify the new URL:
char action[] = "POST "; // Edit to build your command - "GET ", "POST ", "HEAD ", "OPTIONS " - note trailing space
char server[] = "things.ubidots.com";
char path[] = "/api/v1.6/collections/values"; // Edit Path
char token[] = "xxxxxxxxxxxxxxxxxxxx"; // Edit to insert you API Token
int port = 80; // HTTP
// Also, remember to declare the variables to which you want to send data
Then, when building the payload (body) of the HTTP request, build the JSON accordingly (this is just for illustrative purposes; it has not been compiled or tested in the IDE):
var= "[{\"variable\":"+ var1 + ", \"value\": " + value1 + " }, { \"variable\":" + var2 + ", \"value\": " + value1 + " }]"
This example is for two variables, but you can send as many as you want; just append them in the JSON payload.
This works but, it would be cool if you could “back date” the data. For example, when your data logger is connected (WiFi, GPRS, Ethernet, etc) it collects data and reports it to Ubidots where it is date and time stamped.
Now, imagine a real-world problem. The data logger is collecting data but, temporarily looses connectivity. It could store the data locally (with its own date / time stamp) and perform a batch upload when connectivity is resumed. However, it would be difficult to do reporting on this data as the date / time stamp that Ubidots would assign would not reflect when they were collected. What would be cool would be a “Batch Upload API” where you could optionally assign the date / time stamp and that would determine the correct placement of those data points in the serial data stream.
Make sense?
Hello chipmc,
…still have problems with my LinkIt One.
Don’t know whats wrong but it tries to connect twice.(don’t know if this is related but if I send one SMS, I receive it twice)
I added a delay(50) to your code
void loop()
{
if (globalClient.available()) {// if there are incoming bytes available from the server
char c = globalClient.read(); // read them and print them:
Serial.print©;
}
if (millis() >= LastReport + ReportingInterval) { // Section to report - will convert to a function on next rev
SendToUbidots(BatteryPayload(), battkey); // Send it to Ubidots
SendToUbidots(TempPayload(), tempkey); // Send it to Ubidots
LastReport = millis();
}
delay(50);
}
If I omit the delay I get a bad request but data are uploading to ubidots anyway!?
Does anybody know why this is happening?
Regards,
VasilisP