Hello All,
I’m using the WeMos D1 for Arduino and able to successfully do POST Data by following the code in this link: (https://help.ubidots.com/connect-your-devices/connect-a-wemos-d1-to-ubidots-over-http)
So I would like to ask how to do a Get Data using WeMos D1? - as I’ve searched there’s no historical case I’ve found. What are the changes I need to do or add?
Please help. Thanks so much Everyone in Advance
Greetings, please refer to our docs, there you will find examples to get data using the ESP8266 which is the heart core of the Wemos.
All the best
Hello All,
I’ve run this code using WEMOS D1
/****************************************
* Include Libraries
****************************************/
#include "UbidotsESPMQTT.h"
/****************************************
* Define Constants
****************************************/
#define TOKEN "....." // Your Ubidots TOKEN
#define WIFINAME "...." //Your SSID
#define WIFIPASS "....." // Your Wifi Pass
Ubidots client(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() {
// put your setup code here, to run once:
//client.ubidotsSetBroker("business.api.ubidots.com"); // Sets the broker properly for the business account
client.setDebug(true); // Pass a true or false bool value to activate debug messages
Serial.begin(115200);
client.wifiConnection(WIFINAME, WIFIPASS);
client.begin(callback);
}
void loop() {
// put your main code here, to run repeatedly:
if(!client.connected()){
client.reconnect();
}
float value1 = analogRead(A0);
client.add("temperature", value1);
client.ubidotsPublish("my-new-device");
client.loop();
}
And to Get the Data for the “my-new-device”, temperature
I’ve run this code
/****************************************
* Include Libraries
****************************************/
#include "UbidotsESPMQTT.h"
/****************************************
* Define Constants
****************************************/
#define TOKEN "....." // Your Ubidots TOKEN
#define WIFINAME "....." //Your SSID
#define WIFIPASS "....." // Your Wifi Pass
#define DEVICE_LABEL "my-new-device" // Put here your Ubidots device label
#define VARIABLE_LABEL "temperature" // Put here your Ubidots variable label
Ubidots client(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() {
// put your setup code here, to run once:
client.ubidotsSetBroker("business.api.ubidots.com"); // Sets the broker properly for the business account
client.setDebug(false); // Pass a true or false bool value to activate debug messages
Serial.begin(115200);
client.wifiConnection(WIFINAME, WIFIPASS);
client.begin(callback);
client.ubidotsSubscribe(DEVICE_LABEL, VARIABLE_LABEL); //Insert the dataSource and Variable's Labels
}
void loop() {
// put your main code here, to run repeatedly:
if(!client.connected()){
client.reconnect();
client.ubidotsSubscribe(DEVICE_LABEL, VARIABLE_LABEL); //Insert the dataSource and Variable's Labels
}
client.ubidotsSubscribe(DEVICE_LABEL, VARIABLE_LABEL);
client.loop();
}
Both Code run successfully but I wasn’t able to get the value for the temperature. It prints but it has some characters together with it.
My goal is to use the value of temperature as a threshold for my actuators so I only need the numerical values. How can I do that?
Thanks
I would advice you to use a RAW example from our docs to discard any issue with your device. Also, set your serial port baud rate to the same value that you are setting in your setup() routine.
All the best