philbowles / PangolinMQTT

PangolinMQTT - ArduinoIDE client library for ESP8266, ESP32 and STM32-NUCLEO
Other
71 stars 21 forks source link

how i can effectively block "publish" from sending messages or check state of connection in more speed manner? #29

Open poulch74 opened 3 years ago

poulch74 commented 3 years ago

The problem is - low heap. For example after onConnect I start publish messages each 1 sec to remoute mqtt server. All ok until WAN interface of my router goes down. if keepAlive is about 15 then "publish" eat all heap but I not receive any onError or onDisconnect and MCU fail and reboot. I can limit keepAlive to 3, so until heap goes low onDisconnect fired and i can recovery. but I think it not right way... (keepAlive can be under user control) I can check heap and block "publish"... but... so which right way?

philbowles commented 3 years ago

Can you send me some diagnostic output from the serial monitor and/or wireshark traces please? Its very difficult to try to understand this without seeing some data. Also seeing your own code and how you are using Pangolin might be helpful too

poulch74 commented 3 years ago

I use pangolin in simple manner like ` setup() { .... mqtt.connect(); }

onConnect() { mqtt.subscribe(); can_publish = 1; }

onDisconnect() { can_publish = 0;}

onError() {can_publish = 0;}

void loop() { if(can_publish) mqtt.publish(); delay(1000);} ` but if router WAN interface goes done no packets transmitted to remoute mqtt server, but heap eated by mqtt queue and tcp buffers -> low heap and reset before any callback (onDisconnect or onError) fired... maybe some timeout mangment for tcp ack must be added to api (asynctcp default about 5000ms?)?

philbowles commented 3 years ago

It looks like there may be an error in Pango's keepalive / server notification system. I will look into it using the very rough sketch you outlined.

On a separate note, is there a problem with you sending me the actual sketch? The more work you make me do to try to fix the problem, the less likely I am to get round to it - please show me the actual code you are running: a) there may be some other problem with it b) there is no point "debugging" NOT (the code you are running) to try to find a problem in the code you are running.

Also how do you detect / manage WAN reconnection? If the WAN goes down, then yes Pango should spot it and give you a timeout error. But even assuming it DID do that correctly. your example will just sit in the main loop forever , doing nothing until you reboot the MCU...anyway, post me the code and I will look into it.