How does ESPAsyncTCP handle Async without using Loop()?

I'm using an ESP8266 ESP-12E board to create an MQTT endpoint for my Home Assistant setup. I'm using the AsyncMqttClient library, which uses ESPAsyncTCP to send and receive MQTT messages over WiFi.

I've set this up using code from the examples that come with the libraries and it is working well.

My question is about how it is working.

The Wifi and MqttClient callbacks are set up in the Setup function of my sketch and Wifi connect is called. The Loop function is empty. I can add a delay(10000) to the loop function, and the MQTT message handler stays responsive.

It seems it must be using a software interrupt to service the TCP requests outside of Loop(), but I'm not good enough with C/C++ to figure out how it works from the source.

How is this kind of async programming usually done since it does not seem to use a hardware interrupt or rely on a function being called inside Loop() ?

Thanks for any insight.

the ESP8266 only has one core. The WiFi layer uses time, interrupts (and even the ADC peripheral) to provide its service. (On an ESP32 or Arduino Nano 33 IoT you have a separate core for handling WiFi that’s why you have two different libraries)

The ESP8266 Arduino Core’s is using lwip with the WiFi chip. See lwIP - ESP32 - — ESP-IDF Programming Guide latest documentation

I think that’s what provides the lower tcp level callback capabilities that the ESPAsyncTCP library is tapping into.

2 Likes

What makes you think that the WiFi hardware does not generate a hardware interrupt when a byte or packet arrives?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.