I have an Arduino Sketch for an ESP32 board (ESPDUINO), configured to use my free MQTT Adafruit IO account services.
I am subscribed to two feeds linked to the dashboard (a slider and a button), and defined as follows:
Slider: Name: led-int Key: led-int
Button: Name: led-onoff Key: led-onoff
and I publish in two feeds without any problem with the same wificlientsecure instance (mqtt).
If I modified the value of the slider or the button state in the dashboard, no data arrived to the device.
I have tried several ways to setup the subs, etc...
any help please?
The code declarations for the subs are:
Code: Select all
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Setup feeds for subscribing
Adafruit_MQTT_Subscribe LED_int_feed = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/led-int", MQTT_QOS_1);
Adafruit_MQTT_Subscribe LED_onoff_feed = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/led-onoff", MQTT_QOS_1);
void LEDintcallback(double x) {
Serial.print("Hey we're in a slider callback, the slider value is: ");
Serial.println(x);
}
void LEDonoffcallback(char *data, uint16_t len) {
Serial.print("Hey we're in a onoff callback, the button value is: ");
Serial.println(data);
}
Code: Select all
// Set Adafruit IO's root CA
client.setCACert(adafruitio_root_ca);
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();
Serial.println("done");
Serial.print("Starting MQTT client... ");
/*
* Subscribing configuration
*/
LED_int_feed.setCallback(LEDintcallback);
LED_onoff_feed.setCallback(LEDonoffcallback);
// Setup MQTT subscription
mqtt.subscribe(&LED_int_feed);
mqtt.subscribe(&LED_onoff_feed);
Code: Select all
MQTT_connect();
// Now we can publish stuff!
if (! TD_feed.publish(tdsValue)) {
Serial.println(F("Failed TD feed"));
} else {
Serial.println(F("TD feed published"));
}
if (! Temp_feed.publish(tempavg)) {
Serial.println(F("Failed temperature feed"));
} else {
Serial.println(F("Temperature feed published"));
}
Serial.println();
// MQTT subcriptions
// this is our 'wait for incoming subscription packets and callback em' busy subloop
// try to spend your time here:
mqtt.processPackets(10000);