-
Notifications
You must be signed in to change notification settings - Fork 240
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
Cant connect to broker when using esp8266 version 3.1.1 #292
Comments
I have the same issue when trying to upgrade to 3.1.1 [update] This sample code works on the previous version but return error -9 on the v3.1.1 version of the esp8266 arduino fwk. WiFiClient _wifi; mqtt.begin("myhost", 1883, _wifi); if (mqtt.publish("test/topic", "value")) { mqtt.disconnect(); |
Here are some dumps with debugging on for the two frameworks: It looks like it fails to get the ACK due to timeout when sending the initial data to the server (my first thoughts) These were the flags I added. Working one (older fwk).---- start testing for mqtt bug Failing (3.1.1).---- start testing for mqtt bug |
I had the same problem, just with esp8266 core 3.1.1 (and not with 3.1.0 or previous 3.0.x) The problem seems related to the change in delay() coming with ESP8266 core ver 3.1.1
I'm not 100% sure, but changing https://github.com/256dpi/arduino-mqtt/blob/master/src/MQTTClient.cpp#L72 from delay(0) to delay(1) can fix. No other occurrence of "delay" is present in the code... I hope this can help. |
You were spot on. Changing delay(0) to delay(1) fixes the problem with running under 3.1.1. I will do some more tests and issue a PR for this later on. |
I did some more testing. Trying to use delayMicroseconds instead of delay but that didnt work. I'm wondering if the issue is connected to timing and reading the result from the initial connection. Changing from delay(1) to yield() also works. I'm not sure which option is best in this case. Changing a behaviors' in the arduino core like this would probably break more libraries, so I'm curious if this was intentional or they introduced a new bug. |
If I have pieced together correctly, old version of delay(0) results in calling __esp_delay(0)
and eventually in esp_schedule() followed by esp_suspend(). On the contrary, new version of delay(0) requires more steps with overload versions of esp_delay and esp_try_delay.
This manipulation can lead to a final call of __esp_delay with a non-zero argument. The delayMicroseconds function does not yield to other tasks, so I assume it can't be a valid option. On the other hand, yield (alias __yield) seems very similar to former delay(0)
Sorry for the long post. |
Great investigation, you really traced the code. The question is if this change is a bug in the new arduino framework and it will be fixed in future versions or not. I would regard this as a bug in the arduino framework since it changes the behaviour and is not backwards compatible. |
Thank you all for the detailed investigation into this issue! I just released a new version (2.5.1) of the library that increases the delay to 1ms which hopefully results in a proper scheduler yield on all RTOS platforms. I refrained from adding compiler conditionals to check the existence of "yield()" to keep the code simple for the time being. But, if this does not fix the issue or causes others, we can look into adding those as necessary. |
I'm closing this. Please reopen if necessary. |
Using Arduino IDE, and install board version 3.1.1.
and call connect API, always return false.
it works when using version 3.0.x
The text was updated successfully, but these errors were encountered: