-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Sporadically slow MQTT reaction when using ESP32 (ESP8266 works OK) #7183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@guydvir2 - Could you please test your project with this WiFi setup code, and then let mw know the results: void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
// Serial.println(ssid);
WiFi.useStaticBuffers(true); // <<=== This line ay change the may how WiFi perfroms...
WiFi.mode(WIFI_STA);
WiFi.begin("iot", "GdS");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
} |
|
The drawback about using |
thank you. I'm going to add it to code. |
|
Please use Arduino Core 2.0.3+ in order to have access to this feature. |
@SuGlider |
Do you use Arduino IDE? For that, just go to Menu->tools->board manager |
@SuGlider In other tutorial, this path was to use https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json. This one has 2.0.4 Why is that ? Anyway - Now I'll check |
@SuGlider after few days of testing, adding Appreciate any further help, |
@guydvir2 I'd suggest to run the ESP32 in parallel with the ESP8266 to the same MQTT server and check if they behave the same. |
My MQTT server is a local RaspberryPi, connected using a LAN cable (reduce Wifi effects). To be on the safe side- I'm using now a designated MQTT server on a seperated network (same spec and connectivity), and my UUT is soley sending messages to that new MQTT server. I think this is the best I can do for now in that area. QoS is 0. Your idea is refreshing and very interesting, I'll add it to my test (ESP32 in parallel to ESP8266). BTW - In my trials, I used MQTT explorer (a 3rd party MQTT application), which shows that message is reached and recieved as expected ( without any significant latency ), but not received in ESP32 ( monitoring Serial terminal which prints when msg is received). I'll be happy to here some more ideas/ suggestions. Guy |
@SuGlider |
I was having a somewhat similar issue to this, and this was one of the top results when searching. I have a WebSocket server that is receiving commands and they would sometimes lag, slowdown, or stutter. It was really frustrating. This advice helped a little bit, but what really solved it for me was turning the sleep mode off. Here's the code I ended up with:
|
Please explain what behaviour did you encounter. |
I am making a board that controls some power mosfets and talks through a websocket server using the EspAsyncWebServer. When I was load testing it with lots of traffic it would bog down and die. I really don't know what the underlying issue is, but turning off the wifi sleep mode fixed it for me. |
Few days ago, I posted this question in Arduino stackExchange- but no one answered.
I'll be happy to help and get help
//////////////////////////////////////////////////////////////////////////////////////
Problem description: Every ~20+ published messages (using terminal), MCU receives that message in a very noticeable delay (mostly ~10 sec, few time it got up to 1 min). Upon receive (printed in Serial monitor), MCU is working as expected.
Hardware: ESP32 DEVKIT MCU,
PubSubClient.h
for MQTT andWiFi.h
for WiFi.Important remark: Code is same for ESP8266 and ESP32.This behavior happens only on ESP32.
Question: Does ESP32 has a know issue regarding receiving MQTT messages? is there a workaround? or perhaps- bug in code?
What did I do to try isolating the problem:
Tried on 3 different ESP32s (2 DEVkit MCU, and 1 with relays on board) - same behavior - it is not an specific MCU hardware problem.
Used another PC to publish MQTT messages (via terminal. MAC and Linux, and a 3rd party MQTT App)- no change. It has nothing to do with publishing platform.
To rule out it may be a MQTT broker's fault (Local RPI3 connected using LAN cable)- Subscribing to that topic in order to see if the delay repeats . MQTT server receive pubs on time. Broker responds on time (while waiting to see when publish is received in Serial monitor).
adding a flashing LED every 200ms in
loop()
, to verify that MCU is not get stuck in a process.loop()
is looping as expected (see in code below).Spitting heap free memory to Serial monitor, in order to see if there is some memory issue, degradation. Nothing suspicious.
Code simplification- used code segments from ESP32 wifi and MQTT pubsub's example, while disabling every functionality of original code(with and without). Delay still happens sporadically.
OUTPUT1- sending "0" and "1" almost simultaneously, almost 15 sec delay
OUTPUT-2: Code
Originally posted by @guydvir2 in #6543 (comment)
The text was updated successfully, but these errors were encountered: