WiFi IoT Module - Arduino never execute callback function
Hello,
I'm using the WiFi IoT Module with an arduino board to send and receive commands using MQTT. The publishing works fine and the subscription correctly executed but when the server sends messages the callback function is never excecuted.
Here the code:
#include "DFRobot_WiFi_IoT_Module.h"
#define HWSERIAL Serial1
DFRobot_WiFi_IoT_Module_UART IoT(&HWSERIAL);
/* Thingsboard and wifi configuration params*/
const char *WIFI_SSID = "********;
const char *WIFI_PASSWORD = "*******";
//Easy IOT English configuration
const char *THINGSBOARD_SERVER = "*******";
const char *THINGSBOARD_PORT = "******";
const char *THINGSBOARD_ID = "********";
const char *THINGSBOARD_USRN = "******";
const char *THINGSBOARD_PWD = "*****";
const char *SUBSCRIBE_TOPIC = "*************";
const char *PUBLISH_TOPIC_TEMP = "*******";
const char *PUBLISH_TOPIC_PUMP = "**********";
void callback(const char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
}
void setup(void){
HWSERIAL.begin(9600);
while(IoT.begin() != 0){
Serial.println("init ERROR!!!!");
delay(100);
}
Serial.println("init Success");
//Connect to WiFi
while(IoT.connectWifi(WIFI_SSID, WIFI_PASSWORD) != 0){
Serial.print(".");
delay(100);
}
Serial.println("Wifi Connect Success");
//Init MQTT and connect to IoT platform
while(IoT.MQTTBegin(THINGSBOARD_SERVER, THINGSBOARD_PORT, THINGSBOARD_USRN, THINGSBOARD_PWD , THINGSBOARD_ID) != 0){
Serial.print(".");
delay(100);
Serial.println("MQTT Connect Success");
//call callback function
IoT.setCallBack(callback);
//subscribe device SUBSCRIBE_TOPIC
while(IoT.subscribe(SUBSCRIBE_TOPIC) != 0){
Serial.print(".");
delay(100);
}
Serial.println("Subscribe Topic Success");
}
void loop(){
IoT.loop();
}
Hi! Please refer to the sample code in the wiki: https://wiki.dfrobot.com/WiFi_IoT_Module_SKU_TEL0126
jenna