Hey guys!
Hello for all, i have good news for you, Ubidots create a new library for you, with this new library you will be able to connect to Ubidots with TCP method or if you prefer with UDP method. Here some basic examples:
// This #include statement was automatically added by the Particle IDE.
#include "Ubidots/Ubidots.h"
#define TOKEN "CCN8FrVulRYGulPTkbaiR9Myx8qN2o" // Put here your Ubidots TOKEN
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
}
void loop() {
float value = analogRead(A0);
ubidots.add("Variable_Name", value, "context1=value_context1$context2=value_context2"); // Change for your variable name
ubidots.sendAll();
delay(5000);
}
for UDP method use this:
// This #include statement was automatically added by the Particle IDE.
#include "Ubidots/Ubidots.h"
#define TOKEN "CCN8FrVulRYGulPTkbaiR9Myx8qN2o" // Put here your Ubidots TOKEN
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
ubidots.setMethod(TYPE_UDP);
}
void loop() {
float value = analogRead(A0);
ubidots.add("Variable_Name", value, "context1=value_context1$context2=value_context2"); // Change for your variable name
ubidots.sendAll();
delay(5000);
}
if you want to change the the data source name where the particle will save the variable use the next code:
// This #include statement was automatically added by the Particle IDE.
#include "Ubidots/Ubidots.h"
#define TOKEN "CCN8FrVulRYGulPTkbaiR9Myx8qN2o" // Put here your Ubidots TOKEN
#define DATA_SOURCE_NAME "Your_Data_Source_Name"
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
ubidots.setDatasourceName(DATA_SOURCE_NAME);
}
void loop() {
float value = analogRead(A0);
ubidots.add("Variable_Name", value, "context1=value_context1$context2=value_context2"); // Change for your variable name
ubidots.sendAll();
delay(5000);
}
by the way, we save the variables in a data source with a specific TAG, for default the data source TAG of the particle is the particle ID, but if you want to change it please use the next code:
// This #include statement was automatically added by the Particle IDE.
#include "Ubidots/Ubidots.h"
#define TOKEN "CCN8FrVulRYGulPTkbaiR9Myx8qN2o" // Put here your Ubidots TOKEN
#define DATA_SOURCE_TAG "Your_Data_Source_Tag"
Ubidots ubidots(TOKEN);
void setup() {
Serial.begin(115200);
ubidots.setDatasourceTag(DATA_SOURCE_TAG);
}
void loop() {
float value = analogRead(A0);
ubidots.add("Variable_Name", value, "context1=value_context1$context2=value_context2"); // Change for your variable name
ubidots.sendAll();
delay(5000);
}