0

mqtt.readSubscription(5000)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

mqtt.readSubscription(5000)

by erikdw on Wed Nov 07, 2018 9:28 am

I'm using "mqtt.readSubscription(5000)" in my script and work fine to receive onoff button information.
But the problem is that my main loop is waiting 5sec and do nothing.
So reading a local switch on a pin for example give problems. I must push more then 5 sec before he read the status.
Is there a solution ?

erikdw
 
Posts: 3
Joined: Tue Mar 08, 2016 5:22 am

Re: mqtt.readSubscription(5000)

by brubell on Thu Nov 08, 2018 10:46 am

Could you post the complete code or snippet that is giving you trouble?

What version of the MQTT Library are you using?

brubell
 
Posts: 189
Joined: Fri Jul 17, 2015 10:33 pm

Re: mqtt.readSubscription(5000)

by erikdw on Thu Nov 08, 2018 12:30 pm

this is the complete part to check the onoff switch :

// this is our 'wait for incoming subscription packets' busy subloop

Adafruit_MQTT_Subscribe *subscription;
while (subscription = mqtt.readSubscription(5000)) {

// we only care about the lamp events
if (subscription == &lamp) {

// convert mqtt ascii payload to int
char *value = (char *)lamp.lastread;
Serial.print(F("Received: "));
Serial.println(value);

// Apply message to lamp
String message = String(value);
message.trim();
if (message == "ON") {digitalWrite(lamp_pin, HIGH);}
if (message == "OFF") {digitalWrite(lamp_pin, LOW);}

}
}

I'm not at home, I can't see the lib version

erikdw
 
Posts: 3
Joined: Tue Mar 08, 2016 5:22 am

Re: mqtt.readSubscription(5000)

by erikdw on Mon Nov 12, 2018 5:20 am

the adafruit MQTT lib is version 0.20.3

erikdw
 
Posts: 3
Joined: Tue Mar 08, 2016 5:22 am

Please be positive and constructive with your questions and comments.