philbowles / PangolinMQTT

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

Watchdog timeout with AsyncTCP #5

Closed clementnuss closed 4 years ago

clementnuss commented 4 years ago

When running the Quickstart_P.ino sketch, adapted to run on an ESP32, it successfully connects to the WiFi, from the console it appears that it correctly sends the MQTT test messages with QoS 0, 1, and 2.

PangolinMQTT v0.0.7
Connecting to Wi-Fi...
[WiFi-event] event: 0
[WiFi-event] event: 2
[WiFi-event] event: 4
[WiFi-event] event: 7
WiFi connected
IP address:
10.0.38.116
Connecting to MQTT...

SESSION IS CLEAN
Connected to MQTT session=0 max payload size=120914
Subscribing at QoS 2
T=432 Publishing at QoS 0
T=432 Publishing at QoS 1
T=433 Publishing at QoS 2
E (5592) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (5592) task_wdt:  - async_tcp (CPU 0/1)
E (5592) task_wdt: Tasks currently running:
E (5592) task_wdt: CPU 0: wifi
E (5592) task_wdt: CPU 1: async_tcp
E (5592) task_wdt: Aborting.
abort() was called at PC 0x400d7e1b on core 0

On the other side, reading with node-red, I only see the QoS 0 test payload on my (local) MQTT server.

obrain17 commented 4 years ago

You might try this flag in PlatformIO:

build_flags =
   ${env.build_flags}
   -DCONFIG_ASYNC_TCP_RUNNING_CORE=1

This will order AsycTCP to use core 1 (same as your sketch loop code) and modify watchdog handling

//If core is not defined, then we are running in Arduino or PIO
#ifndef CONFIG_ASYNC_TCP_RUNNING_CORE
#define CONFIG_ASYNC_TCP_RUNNING_CORE -1 //any available core
#define CONFIG_ASYNC_TCP_USE_WDT 1 //if enabled, adds between 33us and 200us per event
#endif

Probably you also can try to define CONFIG_ASYNC_TCP_USE_WD separately

BTW: There is currently something wrong with TCP handling with ESP32 (AsyncTCP) when several publishs are done one after another. (I already reported this to @philbowles and he is working on it)

obrain17 commented 4 years ago

This issue with TCP ACK handling in ESP32 is connected with way AsycTCP handles cansend() differently than ESPAsycTCP.

You might do a check: (only for a test of course !) Just change one line in asynctcp.cpp (1134)

bool AsyncClient::canSend(){
    return space() > 0;
}

to

bool AsyncClient::canSend(){
      return !_pcb_busy && (space() > 0);
}

Just report if it works then (?) Then it should be possible to modify PangolinMQTT to work with both.

clementnuss commented 4 years ago

I tried the DCONFIG_ASYNC_TCP_RUNNING_CORE=1 flag, which prevented the crash but the software still was not working correctly.

Finally, the solution to check !_pcb_busy does work ! (with and without the compile flag). Great if you can accomodate this in PangolinMQTT 👌

philbowles commented 4 years ago

I have just pushed a dev branch which I think fixes the ESP32 ack problem - grateful if you could try that and report back

obrain17 commented 4 years ago

I just downloaded the new code from dev branch and compiled it into my ESP32 sketch: Works pretty well now, no "_pcb_busy-workaround" needed anymore.

philbowles commented 4 years ago

Thanks, Rainer!