logo elektroda
logo elektroda
X
logo elektroda

ESP07 Slow WiFi Connection After forceSleepBegin Usage

Dawidixxx 1461 21
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18850432
    Dawidixxx
    Level 7  
    Hello

    After applying
    Code: C / C++
    Log in, to see the code
    .
    And
    Code: C / C++
    Log in, to see the code


    Esp 07 takes about 4 times as long to connect, after 3 seconds the printy slows down as if it is trying to connect and only then after 10-15 does the connection happen (or sometimes even longer). I did a delay(1000) after forceSleepWake to be sure, but it did nothing.
    Without using the function everything is ok, but I'd like to use this because the esp is battery powered and goes to sleep.
    Maybe I have forgotten something?
    Please help and best regards
  • ADVERTISEMENT
  • Helpful post
    #2 18850617
    khoam
    Level 42  
    Dawidixxx wrote:
    I did delay(1000) after forceSleepWake to be sure, but it didn't do anything.
    .
    Put delay(100) after WiFi.forceSleepBegin() and after WiFi.forceSleepWake() - then yield() will not be needed.

    Added after 8 [minutes]:

    Why did you comment WiFi.mode(WIFI_OFF)?
  • #3 18850689
    Dawidixxx
    Level 7  
    Thank you for your reply
    I did a quick check and am writing back because I have to go somewhere and yes there is an improvement :)
    I still wanted to check

    void preinit() {
    ESP8266WiFiClass::preinitWiFiOff();
    }

    But on esp version 2.4.2 it was not detecting the function
    So I upgraded to the latest version 2.7 and the web server stopped working for me without a compile error,
    so I quickly backtracked to 2.5 to check, I need to read why I had a problem during handleRoot

    As for WIFI_OFF
    I would have to verify but I think it executes as a parameter of WiFi.disconnect(true);

    Thanks again and regards :) .
  • Helpful post
    #4 18850839
    khoam
    Level 42  
    Dawidixxx wrote:
    But on esp version 2.4.2 it didn't detect the function.
    So I upgraded to the latest 2.7 and the web server stopped working for me without a compile error,
    so I quickly backtracked to 2.5 to check, I need to read why I had a problem during handleRoot
    .
    The current version is 2.7.3 You may have had compilation errors if the API to ESP8266WebServer has changed. If you showed these errors, it might be possible to help ;) .

    Dawidixxx wrote:
    What about WIFI_OFF
    I would have to verify but I think it executes as a WiFi.disconnect(true) parameter;
    .
    This is not the same. WiFi.mode(WIFI_OFF) is to disable WiFi in the ESP (you'll save a bit on battery life), WiFi.disconnect() only logs you off the WiFi network.
  • ADVERTISEMENT
  • #5 18851121
    Dawidixxx
    Level 7  
    Thank you for such commitment :) It would be nice to improve the code to a higher version
    After decoding on version 2.7.3 I got this information, just don't know where to start here

    
    Exception 3: LoadStoreError: Processor internal physical address or data error during load or store
    PC: 0x4000bf64
    EXCVADDR: 0x40245bd9
    
    Decoding stack results
    0x4020cbdb: _malloc_r(_reent*, size_t) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266\heap.cpp line 125
    0x4020247e: std::function ::function    (SmartRegister*)>, void>(std::_Bind   (SmartRegister*)>) at c:\users\dawid\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 1987
    0x40100c67: umm_free_heap_size_lw() at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266\umm_malloc/umm_local.c line 171
    0x40202038: SmartRegister::SmartRegister(int, String) at C:\Users\dawid\AppData\Local\Temp\arduino_build_753988\sketch\SmartRegister.cpp line 19
    0x4020c9fc: __pinMode(uint8_t, uint8_t) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266\core_esp8266_wiring_digital.cpp line 55
    0x40202a08: esp8266webserver::ESP8266WebServerTemplate ::responseCodeToString(int) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 717
    0x40204932: SmartRegister::ssidFromWeb() at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\libraries\ESP8266WebServer\src/ESP8266WebServer.h line 134
    0x40202a08: esp8266webserver::ESP8266WebServerTemplate ::responseCodeToString(int) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 717
    0x4020e9e4: Print::write(char) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266/Print.h line 75
    0x4020ea27: String::wbuffer() const at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266/WString.h line 309
    0x401000e1: std::function ::operator()() const at c:\users\dawid\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2/functional line 2465
    0x40202a40: esp8266webserver::ESP8266WebServerTemplate ::responseCodeToString(int) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 717
    0x40204526: SmartRegister::begin() at C:\Users\dawid\AppData\Local\Temp\arduino_build_753988\sketch\SmartRegister.cpp line 36
    0x40100400: Twi::onTwipEvent(unsigned char) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266\core_esp8266_si2c.cpp line 572
    0x4020463f: SmartRegister::begin() at C:\Users\dawid\AppData\Local\Temp\arduino_build_753988\sketch\SmartRegister.cpp line 54
    0x40209ef6: Print::print(String const&) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266/Print.h line 65
    0x4020490e: SmartRegister::ssidFromWeb() at C:\Users\dawid\AppData\Local\Temp\arduino_build_753988\sketch\SmartRegister.cpp line 140
    0x4020f278: read_encoded_value_with_base at /workdir/repo/gcc/libgcc/unwind-pe.h line 207
    0x40201fb4: SmartRegister::SmartRegister(int, String) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 85
    0x4020ea08: String::setLen(int) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266/WString.h line 304
    0x40204ee8: ESP8266WiFiAPClass::softAPConfig(IPAddress, IPAddress, IPAddress) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\libraries\ESP8266WiFi\src\ESP8266WiFiAP.cpp line 263
    0x4020f1a8: frame_heapsort at /workdir/repo/gcc/libgcc/unwind-dw2-fde.c line 546
    0x40209fd0: Print::printNumber(unsigned long, unsigned char) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266\Print.cpp line 250
    0x40100f21: calloc(size_t, size_t) at C:\Users\dawid\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.3\cores\esp8266\umm_malloc\umm_malloc.cpp line 908
    

    https://imgur.com/6dW1uJF
  • #6 18851154
    khoam
    Level 42  
    Without knowing the code of the SmartRegister.cpp file, this will be rather difficult. I think it's a file from your program?
  • ADVERTISEMENT
  • #7 18851174
    Dawidixxx
    Level 7  
    SmartRegister is a class responsible for starting a web server with a page that allows you to connect to your own WiFi network
    called when the device does not have a flag stored in EEPROM that it has been configured

    There must be something wrong here, because the /connect link and the method in which the server already provides the login and password is called
    while by default it should redirect to /, i.e. the home page
    I am adding images so that you can see the lines

    https://imgur.com/dvFycNg
    (host not in use, some leftover test code)

    the main handleRoot page calls this method

    https://imgur.com/eH5W97k

    The pages are saved in separate files as

    const char indexBegin[] PROGMEM = R"=====(
    <!DOCTYPE html>
    ...

    String s = constructHTMLpage();
    _server->send(200, "text/html", s);
    I read that there might be a problem here
    the error is triggered after connecting to the wifi of the device and typing/refreshing any page
  • Helpful post
    #8 18851541
    khoam
    Level 42  
    Yes, in the meantime: it looks like a heap overflow problem. Have you checked how much free heap space you have (ESP.getFreeHeap())?
    From the two code snippets you've provided, it looks like you're using the heap quite wastefully :) For an example, the following code should also work (for small data sizes):
    Code: C / C++
    Log in, to see the code
    .
    In version 2.5.x it is:
    Code: C / C++
    Log in, to see the code
    In version 2.7.x it is:
    Code: C / C++
    Log in, to see the code
    The difference is seemingly subtle, but IMHO it is better to create Uri class objects separately rather than "on the fly" by implicitly calling the constructor.

    P.S. There is already a 2.7.4 version of Arduino Core for the ESP8266.
  • #9 18852280
    Dawidixxx
    Level 7  
    I managed to improve the code, for future reference (in my case when moving from version 2.4.2 to 2.7.4) using
    Code: C / C++
    Log in, to see the code

    at
    Code: C / C++
    Log in, to see the code
    .
    conversion needed
    Code: C / C++
    Log in, to see the code

    than
    Code: VB.net
    Log in, to see the code
    .
    As for the code, I still need to optimise it as the constants need 36% of the memory, thank you for your advice :) .
  • #10 18852309
    khoam
    Level 42  
    Dawidixxx wrote:
    because constants need 36% of memory,
    .
    I notice that you don't use constexpr :) .
  • #11 18852341
    Dawidixxx
    Level 7  
    Hmm constexpr, heh until now I knew either #define or const, I need to read ;) .
    To be honest, I don't really know what could be eating up the memory here, the largest parts of the page are stored as PROGMEM
    It could be improved, for example, to send the page piece by piece rather than from one big String
  • #12 18852348
    khoam
    Level 42  
    I suggest instead of this type of code
    Code: C / C++
    Log in, to see the code
    using
    Code: C / C++
    Log in, to see the code
    You can read more about F() :) .
  • #14 18852461
    khoam
    Level 42  
    I also don't understand this use of new/delete . If you have limited RAM, I would rather avoid this.
  • ADVERTISEMENT
  • #15 18852549
    Dawidixxx
    Level 7  
    Dynamic array depending on the number of detected WiFi networks :) .
    But there is probably a more efficient way with little memory, vectors are rather out of the question
  • #16 18852589
    khoam
    Level 42  
    In post #8 I showed how to dynamically allocate such a small array without using the heap :) .

    The second thing is to use new in the SmartRegister constructor to create a _server object. It probably makes no sense to allocate such a large object on the heap since the destructor of the SmartRegister class will not be called in the program anyway. Isn't it better to create such an object simply as another variable in the SmartRegister class? It can then be initialised in the constructor:
    Code: C / C++
    Log in, to see the code
    .
  • #17 18852756
    Dawidixxx
    Level 7  
    A silly error of non-thought indeed.

    As for the example in post #8 I don't think I can do that, I need some fixed array size even if inflated to be given in that form.
    I still have a question for ESP.getFreeHeap() which I need to start using and get interested in memory. Does this function return the remaining available memory for the stack and heap?
    From what I have read it is common - static elements, and here we have FreeHeap
  • #18 18852812
    khoam
    Level 42  
    Dawidixxx wrote:
    Does this function return the remaining available memory for the stack and heap?
    .
    The remaining available memory for the heap. In contrast, ESP.getFreeContStack() returns the available memory for the stack (for Arduino Core calls only).

    Added after 53 [minutes]:

    Dawidixxx wrote:
    I need some sort of fixed board size even if inflated to give this form.
    .
    And what happens when WiFi.scanNetworks() returns a value of zero? :)
    I notice that you have implemented bubble sorting in the constructHTMLpage() function. You can simply use std::sort.
  • #19 18852986
    Dawidixxx
    Level 7  
    When returning 0 the loops do not execute but the page builds. Already on a static array.
    mate is impossible :D a veritable compiler

    I still have a question because I am now testing the connection on the AP from my laptop and the time is constant
    - with the WiFi module turned off at startup,
    - with on,
    - delay(100) and without,
    - Surprisingly forceSleepBegin without Wake

    with DHCP always comes out 6 seconds
    When I get a chance, I need to check the power consumption

    I am using an ESP07 module with a small antenna (on ali sometimes included) however I have not disconnected the ceramic antenna, can they interfere? (I also tested the connection on a clean project). The long wait time from the home AP was probably due to the router itself.
  • #20 18853246
    khoam
    Level 42  
    Dawidixxx wrote:
    I am using an ESP07 module with a small antenna (on ali sometimes included) however I have not disconnected the ceramic antenna, can they interfere?
    .
    The ceramic antenna should be disconnected - remove jumper (resistor 0 Ω) as shown below:

    ESP07 Slow WiFi Connection After forceSleepBegin Usage .

    Whether this will work better on an external antenna is a separate issue and largely depends on the quality of the external antenna. There has already been a thread on this topic on the forum:
    https://www.elektroda.pl/rtvforum/topic3117733.html

    Dawidixxx wrote:
    with DHCP it always comes out 6 seconds
    .
    Is there a "reserved" IP address for the ESP in the AP router?
  • #21 18854031
    Dawidixxx
    Level 7  
    I haven't yet tested the option with a fixed IP on both the AP and ESP side, I wanted to get a good feel for the dynamic connection :) first.
    I understand that I will get the best result by setting a fixed IP on both sides rather than just one?
  • #22 18854092
    khoam
    Level 42  
    I'm talking about reserving an IP address for the ESP in the DHCP server, in the router.

Topic summary

The discussion revolves around the slow WiFi connection issue experienced with the ESP07 module after using the `forceSleepBegin()` and `forceSleepWake()` functions. The user noted that the connection time increased significantly, taking up to 10-15 seconds to connect, compared to normal operation. Suggestions included adding delays after the sleep functions to improve connection times and clarifying the difference between `WiFi.mode(WIFI_OFF)` and `WiFi.disconnect()`. The user also encountered compilation issues when upgrading the ESP8266 library version, which were resolved by reverting to an earlier version. Further discussions included optimizing memory usage, handling heap overflow, and improving code efficiency. The importance of using fixed IP addresses and the potential interference from antennas were also mentioned.
Summary generated by the language model.
ADVERTISEMENT