[SOLVED] Subscribed but cant get data

hello everyone, i am having this issue trying to use ubidots to trigger 3 switches in a ESP 8266.
i run my code, esp connects in the network, connects to ubidots MQTT, subscribe to the topics, but, when i change values with the dashboard the callback function is never called.

this is the code running in the ESP 8266

#include "UbidotsESPMQTT.h"

/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "XXXXXXXXXXXXXXXXXXXX" // Your Ubidots TOKEN
#define WIFINAME "XXXXX" //Your SSID
#define WIFIPASS "XXXXXXXX" // Your Wifi Pass

int sensorPin = A0;
int ledPin = D5;
int relayPin = D3;

int state;
int lightState;

Ubidots client(TOKEN);


/****************************************
 * Main Functions
 ****************************************/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  client.setDebug(true);
  client.wifiConnection(WIFINAME, WIFIPASS);
  client.begin(callback);
  client.ubidotsSubscribe("stuffboxrele", "relayone"); //Insert the dataSource and Variable's Labels
  client.ubidotsSubscribe("stuffboxrele", "relaytwo"); //Insert the dataSource and Variable's Labels
  client.ubidotsSubscribe("stuffboxrele", "relaytree"); //Insert the dataSource and Variable's Labels
  
  }


void loop() {
  // put your main code here, to run repeatedly:
  if(!client.connected()){
      client.reconnect();
      client.ubidotsSubscribe("stuffboxrele", "relayone"); //Insert the dataSource and Variable's Labels
      client.ubidotsSubscribe("stuffboxrele", "relaytwo"); //Insert the dataSource and Variable's Labels
      client.ubidotsSubscribe("stuffboxrele", "relaytree"); //Insert the dataSource and Variable's Labels

      }
      

  client.loop();
  }


/****************************************
 * 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 ((char)payload[0]=='1'){
    digitalWrite(relayPin, HIGH);
  }
   else if ((char)payload[0]=='0'){
    digitalWrite(relayPin, LOW);
  } 
}

it is the example code for subscribing ubidots mqtt with my data, this should work as the variables seems to be working in the dashboard.

after running this code i get the following data from the serial.(DEBUG)

`⸮⸮n⸮...........WiFi connected
IP address: 
192.168.100.177
entra
Attempting MQTT connection...connected
Subscribed to: 
/v1.6/devices/stuffboxrele/relayone/lv
Subscribed to: 
/v1.6/devices/stuffboxrele/relaytwo/lv
Subscribed to: 
/v1.6/devices/stuffboxrele/relaytree/lv

^^^just that and nothing more, even when i change variables value trhough the dashboard, i dont receive any data.

am I doing anything wrong?

Hi there, if you own an industrial account, please follow this example.

Let me know if it works.

this is the exemple i used, I own a trial account for instance

Hi there, not, in your first post you are not using the example that I provided you. You need to set the broker to business.api.ubidots.com or industrial.api.ubidots.com:

client.ubidotsSetBroker("business.api.ubidots.com");

Please refer to the line 35 of the example that I previously shared with you.

All the best

1 Like