Recent

Author Topic: I need help with esp8266 wifiscan  (Read 7716 times)

wennerer

  • New member
  • *
  • Posts: 9
I need help with esp8266 wifiscan
« on: August 19, 2025, 09:35:56 pm »
Hello,
I have created a trunk (with fpcupdeluxe) that can be used to program an nodemcu ESP8266. I have successfully tested several examples from the ccrause GitHub page. Unfortunately, I have been trying to get the WifiScan example to work for quite some time now. When compiling, I initially received an error message stating that the procedure esp_event_loop_init is unknown. I then found it commented out in the unit esp_event_legacy. I then entered the following there:
Code: Pascal  [Select][+][-]
  1. type
  2.   Tsystem_event_cb = function(ctx: pointer; event: Psystem_event): Tesp_err;
  3.  
  4.   function esp_event_loop_init(system_event_cb: Tsystem_event_cb;ctx :Pointer):Tesp_err;external;  

Now the programme can be compiled and linked without errors. Unfortunately, however, no APs are found.

This is the output in a serial monitor:
Quote
Enter scan␍␍␊
<0x1b>[0;32mI (124) system_api: Base MAC address is not set, read default base MAC address from EFUSE<0x1b>[0m␍␊
<0x1b>[0;32mI (128) system_api: Base MAC address is not set, read default base MAC address from EFUSE<0x1b>[0m␍␊
phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊
<0x1b>[0;32mI (185) phy_init: phy ver: 1163_0<0x1b>[0m␍␊
Event -  SYSTEM_EVENT_STA_START␍␍␊
Event -  SYSTEM_EVENT_SCAN_DONE␍␍␊
No AP records returned.␍␍␊
␍␍␊
_haltproc called, exit code: 0␍␍␊

Can anyone tell me what I'm doing wrong?

Best regards,
Bernd





ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: I need help with esp8266 wifiscan
« Reply #1 on: August 20, 2025, 07:46:09 am »
Please file an issue for the missing esp_event_loop_init, I forgot to add the exp_event_legacy unit to the repository.

Will test the wifiscan example against the fpcupdeluxe install later this week.

wennerer

  • New member
  • *
  • Posts: 9
Re: I need help with esp8266 wifiscan
« Reply #2 on: August 20, 2025, 05:49:18 pm »
Hello ccrause,
I have opened an issue in your repository.

Thank you for your work!

Bernd

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: I need help with esp8266 wifiscan
« Reply #3 on: August 21, 2025, 07:41:30 am »
The missing units have been added to repository and compilation of wifiscan example is fixed.

The fpcupdeluxe installed esp8266-rtos-sdk libraries do not appear to support the wifiscan functionality. To update the esp8266 libraries, extract the libs folder from the esp8266 snaptshot and copy the libraries (libxxx.a) into the fpcupdeluxe libraries folder (fpcupdeluxefolder/cross/lib/xtensa-freertos/lx106/), overwriting the old libraries.

wennerer

  • New member
  • *
  • Posts: 9
Re: I need help with esp8266 wifiscan
« Reply #4 on: August 21, 2025, 08:27:49 pm »
Hello ccrause,
First of all, thank you for adapting your repository.

I tested your suggestion and replaced the libraries. Unfortunately, it doesn't seem to work. My output in CuteCom looks like this:

Quote
chksum 0x8e␍␊
load 0x3ffe8420, len 2548, room 8 ␍␊
tail 12␍␊
chksum 0xec␍␊
csum 0xec␍␊
<0xa2>5;r94P<0x17>[jh<0x01>mrjCz<0x01><0x18>Nbb!<0x1b>r<0x01>r<0xeb>t<0x1b>t@<0x1b>r!<0x08>3tiNbb!<0x1b>r<0x01><0xed>~2LJ<0xc4>9<0x8d><0x17>[jh,(mrjla%$vbb!<0x1b>r<0x01>%P~7<0x10>*<0x1b>r!<0xba>W<0x15>vtiNbb!<0x1b>r<0x01><0xed>~LJ9<0xe1>,z<0xb3>p[~ah<0xbd>␍*<0x15>BV)@<0x98>|<0xb9>--*,-<0x1d>,@<0xcc>b#'<0x8d>T<0x15>j<0x15>"(,z1<0x01>,#<0x1d>l<0x17>D<0xa9> |h@bb<0x13>8db8<0xe1><0xb3>|h@7bb<0x13><0xa2>dbn<0xa3>&4 @<0x1d>M<0x93>O<0xe1>x<0x13><0x03>hL4(<0xba><0x0e>t<0x01>.#!!\!h8!(hr<0xdb>Xo8!$~<0xa8>z<0x01>n<0x19>blBlnn&4(<0xbb><0x0e>XEl8!hvh~uEjf<0xe0><0x03><0xac><0xd5>L94(dz<0xbb>z<0x1b>PZpv<0x1d>g<0xe0>R`f$n8n8!'{vPZpv<0x1d>g<0xe0>R␊

I'll try rebuilding Lazarus with your libraries over the weekend. Let's see what happens.

Best regards,
Bernd

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: I need help with esp8266 wifiscan
« Reply #5 on: August 22, 2025, 07:07:11 am »
Hello ccrause,
First of all, thank you for adapting your repository.

I tested your suggestion and replaced the libraries. Unfortunately, it doesn't seem to work. My output in CuteCom looks like this:

Quote
chksum 0x8e␍␊
load 0x3ffe8420, len 2548, room 8 ␍␊
tail 12␍␊
chksum 0xec␍␊
csum 0xec␍␊
<0xa2>5;r94P<0x17>[jh<0x01>mrjCz<0x01><0x18>Nbb!<0x1b>r<0x01>r<0xeb>t<0x1b>t@<0x1b>r!<0x08>3tiNbb!<0x1b>r<0x01><0xed>~2LJ<0xc4>9<0x8d><0x17>[jh,(mrjla%$vbb!<0x1b>r<0x01>%P~7<0x10>*<0x1b>r!<0xba>W<0x15>vtiNbb!<0x1b>r<0x01><0xed>~LJ9<0xe1>,z<0xb3>p[~ah<0xbd>␍*<0x15>BV)@<0x98>|<0xb9>--*,-<0x1d>,@<0xcc>b#'<0x8d>T<0x15>j<0x15>"(,z1<0x01>,#<0x1d>l<0x17>D<0xa9> |h@bb<0x13>8db8<0xe1><0xb3>|h@7bb<0x13><0xa2>dbn<0xa3>&4 @<0x1d>M<0x93>O<0xe1>x<0x13><0x03>hL4(<0xba><0x0e>t<0x01>.#!!\!h8!(hr<0xdb>Xo8!$~<0xa8>z<0x01>n<0x19>blBlnn&4(<0xbb><0x0e>XEl8!hvh~uEjf<0xe0><0x03><0xac><0xd5>L94(dz<0xbb>z<0x1b>PZpv<0x1d>g<0xe0>R`f$n8n8!'{vPZpv<0x1d>g<0xe0>R␊

I'll try rebuilding Lazarus with your libraries over the weekend. Let's see what happens.

Best regards,
Bernd

The garbled serial output is due to a change in default baud rate for the application in the configuration of the SDK (so that the default baud rate for both esp32 and esp8266 is the same).  Change your serial monitor's baud to 115200, that should show proper text.  The bootloader baud rate is still 74880, so the boot messages will now be garbled.

There should be no need to recompile Lazarus, the esp8266 libraries are only used by the cross compiler.
« Last Edit: August 22, 2025, 07:13:06 am by ccrause »

wennerer

  • New member
  • *
  • Posts: 9
Re: I need help with esp8266 wifiscan
« Reply #6 on: August 22, 2025, 06:54:09 pm »
Hello,
You're the best! Now it works for me too. I would never have thought of swapping the libraries.

Quote
The garbled serial output is due to a change in default baud rate for the application in the configuration of the SDK

Yes, now suddenly some things make sense.

Thank you very much for your help!
Bernd

dbannon

  • Hero Member
  • *****
  • Posts: 3616
    • tomboy-ng, a rewrite of the classic Tomboy
Re: I need help with esp8266 wifiscan
« Reply #7 on: August 23, 2025, 07:29:22 am »
I have been watching this thread, interesting !

Some time ago, I used ccrause great work but ran into problems because, my fault, I purchased ESP-c3 (RISC-V) devices. The wireless was a particular problem. Under some time pressure, I wrote some C++ code, it works but leaves be worried.

So, if I get another chance I'd like to try the FPC approach again. I can, now, get both ESP8266 and ESP-S3 (LX7) boards, would that make better use of FPC and ccrause's libraries ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: I need help with esp8266 wifiscan
« Reply #8 on: August 23, 2025, 12:50:45 pm »
I have been watching this thread, interesting !

Some time ago, I used ccrause great work but ran into problems because, my fault, I purchased ESP-c3 (RISC-V) devices. The wireless was a particular problem. Under some time pressure, I wrote some C++ code, it works but leaves be worried.

So, if I get another chance I'd like to try the FPC approach again. I can, now, get both ESP8266 and ESP-S3 (LX7) boards, would that make better use of FPC and ccrause's libraries ?

The development branch of FPC does support the newer xtensa S2 & S3 modules and the RISC-V based C2, C3 & C6 modules. However, fpc-esp-freertos is still stuck at esp-idf v4.3 and only caters for esp32 (and esp8266 via ESP8266_RTOS_SDK). The fpc-esp-freertos bindings should be updated to at least esp-idf v5.1 (currently SDK is at v5.5).  There was substantial refactoring of the SDK from v4.3 to v5+ and will require a substantial chunk of time to update the Pascal bindings.  I have done some preliminary checks with S3 and C3 boards and that works with FPC.

wennerer

  • New member
  • *
  • Posts: 9
Re: I need help with esp8266 wifiscan
« Reply #9 on: August 24, 2025, 08:17:38 am »
Hello,
I would like to add that I have now also tested the simplehttpserver example.
For my ESP8266, I had to use the wificonnect2 unit instead of the wificonnect unit. For simplicity's sake, I entered the SSID and password directly.
This point in wificonnect2 
Code: Pascal  [Select][+][-]
  1. if APName <> '' then
received an error message. I simply inserted a space between the '' and now everything could be compiled and linked.
I don't know if this is a bug or if I did something wrong.

In any case, I can say that the programme is now running and I am connected to the WiFi.
Awesome!

Bernd




ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: I need help with esp8266 wifiscan
« Reply #10 on: August 24, 2025, 12:08:34 pm »
Hello,
I would like to add that I have now also tested the simplehttpserver example.
For my ESP8266, I had to use the wificonnect2 unit instead of the wificonnect unit.
Did you get a runtime error 203 when using wificonnect?  There are two possible fixes, either add the fmem unit as first unit in the program (perhaps better option), or tell the compiler to allocate some memory for the heap via -Ch (or in Lazarus Project Options: Compiler Options -> Compilation and Linking > Heap size).  1024 bytes should be enough.  I think I will add the fmem unit to all the projects that needs dynamic memory.

Quote
For simplicity's sake, I entered the SSID and password directly.
This point in wificonnect2 
Code: Pascal  [Select][+][-]
  1. if APName <> '' then
received an error message. I simply inserted a space between the '' and now everything could be compiled and linked.
I don't know if this is a bug or if I did something wrong.

What error message?  When I test the simplehttpserver example with the wificonnect2 unit I don't get any compile time errors.

Quote
In any case, I can say that the programme is now running and I am connected to the WiFi.
Awesome!
Great, have fun!

wennerer

  • New member
  • *
  • Posts: 9
Re: I need help with esp8266 wifiscan
« Reply #11 on: August 24, 2025, 01:23:05 pm »
Hello,
this is the serial output when i use wificonnect:

Code: Pascal  [Select][+][-]
  1. esp_event_loop_create_default␍␍␊
  2. esp_wifi_init␍␍␊
  3. <0x1b>[0;32mI (211) system_api: Base MAC address is not set, read default base MAC address from EFUSE<0x1b>[0m␍␊
  4. <0x1b>[0;32mI (251) system_api: Base MAC address is not set, read default base MAC address from EFUSE<0x1b>[0m␍␊
  5. phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊
  6. <0x1b>[0;32mI (531) phy_init: phy ver: 1163_0<0x1b>[0m␍␊
  7. esp_event_loop_init␍␍␊
  8. esp_wifi_set_mode␍␍␊
  9. esp_wifi_set_config␍␍␊
  10. esp_wifi_start␍␍␊
  11. Event: SYSTEM_EVENT_STA_START␍␍␊
  12. Wifi started, now connecting...␍␍␊
  13. <0x1b>[0;32mI (789) wifi:state: 0 -> 2 (b0)␍␊
  14. <0x1b>[0m<0x1b>[0;32mI (812) wifi:state: 2 -> 3 (0)␍␊
  15. <0x1b>[0m<0x1b>[0;32mI (824) wifi:state: 3 -> 5 (10)␍␊
  16. <0x1b>[0m<0x1b>[0;32mI (866) wifi:connected with FRITZ!Box 7590 MA, aid = 9, channel 6, HT20, bssid = 44:4f:6d:1d:f4:d8␍␊
  17. <0x1b>[0mEvent: SYSTEM_EVENT_STA_CONNECTED␍␍␊
  18. Wifi event received: SYSTEM_EVENT_STA_CONNECTED␍␍␊
  19. <0x1b>[0;32mI (1702) tcpip_adapter: sta ip: 192.168.178.118, mask: 255.255.255.0, gw: 192.168.178.1<0x1b>[0m␍␊
  20. Event: SYSTEM_EVENT_STA_LOST_IP␍␍␊
  21. Lost IP␍␍␊
  22. ## UNEXPECTED EVENT, bits = 0␍␍␊
  23. Starting web server...␍␍␊
  24. Starting server on port: 80␍␍␊
  25. Registering URI handler␍␍␊
  26.  
Adding fmem or compiling with ch 1024 does not change the output.

And this is the error message when i compile with '', whether with wificonnect or wificonnect2:
Code: Pascal  [Select][+][-]
  1. phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊
  2. <0x1b>[0;32mI (464) phy_init: phy ver: 1163_0<0x1b>[0m␍␊
  3. ␍␍␊
  4. Runtime error 203␍␍␊
  5. _haltproc called, exit code: 203␍␍␊

Now comes the surprise: if I compile wificonnect2 with '' and with fmem or ch1024, the error message disappears and it works.

Bernd
« Last Edit: August 24, 2025, 05:43:26 pm by wennerer »

ccrause

  • Hero Member
  • *****
  • Posts: 1083
Re: I need help with esp8266 wifiscan
« Reply #12 on: August 24, 2025, 02:54:02 pm »
Hello,
this is the serial output when i use wificonnect:

Code: Pascal  [Select][+][-]
  1. <0x1b>[0m<0x1b>[0;32mI (866) wifi:connected with FRITZ!Box 7590 MA, aid = 9, channel 6, HT20, bssid = 44:4e:6d:1d:f3:d8␍␊
  2. <0x1b>[0mEvent: SYSTEM_EVENT_STA_CONNECTED␍␍␊
  3. Wifi event received: SYSTEM_EVENT_STA_CONNECTED␍␍␊
  4. <0x1b>[0;32mI (1702) tcpip_adapter: sta ip: 192.168.178.118, mask: 255.255.255.0, gw: 192.168.178.1<0x1b>[0m␍␊
  5. Event: SYSTEM_EVENT_STA_LOST_IP␍␍␊
  6. Lost IP␍␍␊
  7. ## UNEXPECTED EVENT, bits = 0␍␍␊
  8. Starting web server...␍␍␊
  9. Starting server on port: 80␍␍␊
  10. Registering URI handler␍␍␊
Adding fmem or compiling with ch 1024 does not change the output.
The way the event loop is initialized in wificonnect is not quite correct, however the web server should still be functional.  This was reworked in the wificonnect2 unit, my intention is to rename wificonnect2 to wificonnect when these problems are fully resolved.

There was no runtime error 203, so no need to change the heap settings or memory manager.

Quote
And this is the error message when i compile with '', whether with wificonnect or wificonnect2:
Code: Pascal  [Select][+][-]
  1. phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊
  2. <0x1b>[0;32mI (464) phy_init: phy ver: 1163_0<0x1b>[0m␍␊
  3. ␍␍␊
  4. Runtime error 203␍␍␊
  5. _haltproc called, exit code: 203␍␍␊

Now comes the surprise: if I compile wificonnect2 with '' and with fmem or ch1024, the error message disappears and it works.
Runtime error 203 is thown when the memory manager runs out of heap space (by default no memory is allocated to the heap of the default RTL memory manager). This can be fixed by either using fmem (which uses the freertos memory manager) or by the -Ch option (which allocates heap memory for the default RTL memory manager).

 

TinyPortal © 2005-2018