Hello,
I’m just start with Ubidots and NodeMcu, to start, i’m doing the first test of turning on a led, i can connect but i can’t turn the led on or off, you know what it can be?
/****************************************
- Include Libraries
****************************************/
#include “UbidotsESPMQTT.h”
/****************************************
- Define Constants
****************************************/
#define TOKEN “xxxxxxxxxxx” // Your Ubidots TOKEN
#define WIFINAME “xxxxx” //Your SSID
#define WIFIPASS “xxxxxxx” // 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();
if( payload[0] == '0' ){
digitalWrite(D0,LOW);
}
else
{
digitalWrite(D0,HIGH);
}
}
/****************************************
- Main Functions
****************************************/
void setup() {
// Setup LED pin
pinMode(D0,OUTPUT);
Serial.begin(115200);
client.setDebug(true); // Pass a true or false bool value to activate debug messages
client.wifiConnection(WIFINAME, WIFIPASS);
//client.ubidotsSetBroker(“business.ubidots.com”);
client.ubidotsSetBroker(“things.ubidots.com”);
client.begin(callback);
client.ubidotsSubscribe(“esp8266”,“led”); //Insert the dataSource and Variable’s Labels
}
void loop() {
// put your main code here, to run repeatedly:
if(!client.connected()){
client.reconnect();
client.ubidotsSubscribe(“esp8266”,“led”); //Insert the dataSource and Variable’s Labels
}
client.loop();
}