Greetings from Colombia!
I have trying to send the data for the actual position of my esp32 device to the Ubidots platform, but I could not do it from the Arduino IDE. When the device is running, the platform doesn’t recognize the variable or the position.
PD: Sorry for my bad English.
This is the code that I have used:
#include "UbidotsEsp32Mqtt.h"
const char *UBIDOTS_TOKEN = "****************************";
const char *WIFI_SSID = "********";
const char *WIFI_PASS = "*******";
const char *DEVICE_LABEL = "MyEsp32";
const char *VARIABLE_LABEL = "gps";
const int PUBLISH_FREQUENCY = 5000;
unsigned long timer;
float latitud = 1.23164;
float longitud = -77.29426;
char context[25];
int gps = 1;
Ubidots ubidots(UBIDOTS_TOKEN);
/****************************************
* Auxiliar Functions
****************************************/
void callback(char *topic, byte *payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
/****************************************
* Main Functions
****************************************/
void setup()
{
Serial.begin(115200);
ubidots.setDebug(true);
ubidots.connectToWifi(WIFI_SSID, WIFI_PASS);
ubidots.setCallback(callback);
ubidots.setup();
ubidots.reconnect();
timer = millis();
}
void loop()
{
if (!ubidots.connected())
{
ubidots.reconnect();
}
if (abs(millis() - timer) > PUBLISH_FREQUENCY) // triggers the routine every 5 seconds
{
sprintf(context, "lat=%.2f$lng=%.2f", latitud, longitud);
ubidots.add(VARIABLE_LABEL, 1, context);
ubidots.publish(DEVICE_LABEL);
Serial.println(context);
timer = millis();
}
ubidots.loop();
}