-
Notifications
You must be signed in to change notification settings - Fork 13.3k
800-900ms between loop() latency during wifi connection handling -3 #6136
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
Additional informations: As additive test I also checked the Timer 1 interrupt. That interrupt continue to work as expected without any latency (I used it as workaround for time critical functions). |
Much better, thank you. |
What happens if you:
Also, could you please modify the sketch to measure time, e. g. with millis(), instead of toggling pins? Not everyone has a logic analyzer to reproduce in that way. |
Hi @devyte regarding your questions:
Please, see the next post for the new sketch with trace and time measures. |
This is the requested sketch. The time produced in the logs is referred to the wifi initialization (t=0). I noticed now the latency always occur when the ssid is recognized, even in case of an uncorrect key. EDIT: the tests are performed at 160Mhz clock MCVE Sketch#include <Arduino.h>
#include "ESP8266WiFi.h"
//-- Pin definitions. Trace purpose only
#define tracePin0_loop 14
#define tracePin1_setup 12
#define tracePin2_event 13
char mySsid[]="xxx";
char myKey[]="yyy";
unsigned long start_ms,lastCheck_ms;
const unsigned long trigger_ms=10; //for latency detection
void recordEvent(WiFiEvent_t event){
//produce a burst of event+1 pulses on tracePin2_event pin
for (int i=0; i<=(int)event; i++){
digitalWrite(tracePin2_event, 1);
digitalWrite(tracePin2_event, 0);
}
Serial.println(String("******* Wifi Event ") + (int) event + " received. Time: " + (millis() - start_ms));
}
void setup() {
Serial.begin(115200);
//initialize trace -----------------------
pinMode(tracePin0_loop, OUTPUT);
pinMode(tracePin1_setup, OUTPUT);
pinMode(tracePin2_event, OUTPUT);
digitalWrite(tracePin0_loop, 0);
digitalWrite(tracePin1_setup, 0);
digitalWrite(tracePin2_event, 0);
delay (10000);
//end of trace initialization -------------
Serial.println("******* Set time reference to 0 (Wifi initialization)");
start_ms = millis();
digitalWrite(tracePin1_setup, 1);
WiFi.onEvent(recordEvent);
WiFi.persistent(false); //avoid delays by flash operations
WiFi.mode(WIFI_OFF);
WiFi.setAutoConnect(false);
WiFi.setAutoReconnect(false);
//WiFi.disconnect(true);
//WiFi.mode(WIFI_STA);
digitalWrite(tracePin1_setup, 0);
//wait exactly 1000ms from the time reference to facilitate the reading of the log
delay(1000 - (millis()-start_ms));
Serial.println(String("******* Wifi.begin call. Time:") + (millis()-start_ms));
lastCheck_ms = millis();
digitalWrite(tracePin1_setup, 1);
WiFi.begin(mySsid, myKey);
digitalWrite(tracePin1_setup, 0);
}
// The loop function is called in an endless loop
void loop() {
unsigned long now,timeFromCheck;
digitalWrite(tracePin0_loop, !digitalRead(tracePin0_loop));
now=millis();
timeFromCheck = now - lastCheck_ms;
if (timeFromCheck >= trigger_ms)
Serial.println(String("******* LATENCY ") + timeFromCheck + " ms detected. Time : " +(now - start_ms));
lastCheck_ms = now;
//do some stuff
delay(2); //cpu latency by WiFi (887ms) could occur here, or outside of this function
} --- Test condition: not existent ssid ---------------------------------- --- Test condition: correct SSID but wrong key. Latency occurred. ------ SDK:2.2.1(cfd48f3)/Core:unspecified=0/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020 --- Test condition: correct SSID and key. Latency occurred. ------ SDK:2.2.1(cfd48f3)/Core:unspecified=0/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020 connected with DAP, channel 6
|
Update: The latency always present with a constant duration (885 - 889 ms) in ALL cases. |
hi @devyte,
For a comparison test, I installed the 8266 RTOS environment and I performed a pair of tests using the simple_wifi example with the task priority lowered to "1". (0 = idle) . In a such case, for every connection I observed two minimal latencies of only 27ms and 50ms (scheduler freq= 100Hz), 32ms and 75ms (scheduler freq=1Khz). Regards. EDIT =05/Jun/19: The RTOS case is not correct. I discovered that the latency sometime occur also in this framework. I suppose a wifi driver issue. I'm still investigating about that. |
I am also observing this issue. Same 800-900 ms delay. |
This issue is present at least as far back as 2.4.1. I stopped testing beyond that. |
Also occurs if you specify channel and BSSID, so it isn't related to doing a scan. |
Also tried a test with a timer0 interrupt. It looks like that keeps running all the way through. If anyone needs to ensure real-time behavior during a wifi connect, that might be an option. Timer1 also works, and may be preferable since timer0 is ostensibly used by wifi already. |
espressif/ESP8266_RTOS_SDK#626 Hi @readmodifywrite |
@dsptech Awesome. I'm glad you found this issue, I would have been pretty lost in trying to find out what was going on without it. |
@dsptech a whole lot has changed since this was reported. Please retest with release 2.6.0. |
Hi @devyte, To confirm that, I already experienced an heavier wifi issue in the ESP8266 RTOS: |
Did you report in the NONOS SDK repo? I suggest doing that, and referencing work being done in the FreeRTOS repo. |
I've not reported the issue in NONOS SDK reported because many guys has already worked on: Anyway, I assumed that the report in NONOS SDK was already done by the arduino team. |
@devyte |
Basic Infos
Platform
Settings in IDE
Problem Description
Long latency of the loop function (887ms) due WiFi connection activity. There are no change of the issue changing the lock setting from 80Mhz to 160Mhz.
The issue occur after a while that WiFi.begin is called and just before the "WIFI_EVENT_STAMODE_CONNECTED" event.
Use the sketch below to recreate the issue. The sketch also use some pin to allow the tracing via an hardware logic analizer. The two attached pictures show the behavior with 80Mhz and 160Mhz clock settings.
In the two pictures, the 2nd pulse in the track "SETUP" is the WiFi.begin call.
The track "LOOP" is generated by loop function that toggle a pin every 2ms (see the sketch).
The issue is active in the commits: 968d6fc and the last b551992
Could be related to: #4891
MCVE Sketch
Debug Messages
Additional information in the next post
The text was updated successfully, but these errors were encountered: