I need help with esp8266 wifiscan lazarus / 77-Embedded ---------------------------------------------------------------------- wennerer · 2025-08-19 19:35 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  Tsystem_event_cb = function(ctx: pointer; event: Psystem_event): Tesp_err;   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: QuoteEnter 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 · 2025-08-20 05:46 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 · 2025-08-20 15:49 Hello ccrause, I have opened an issue in your repository. Thank you for your work! Bernd ---------------------------------------------------------------------- ccrause · 2025-08-21 05:41 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 · 2025-08-21 18:27 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: Quotechksum 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!<0 x1b>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!$~<0 xa8>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 · 2025-08-22 05:07 Quote from: wennerer on August 21, 2025, 08:27:49 pmHello 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: Quotechksum 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!<0 x1b>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!$~<0 xa8>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. ---------------------------------------------------------------------- wennerer · 2025-08-22 16:54 Hello, You're the best! Now it works for me too. I would never have thought of swapping the libraries. QuoteThe 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 · 2025-08-23 05:29 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 ---------------------------------------------------------------------- ccrause · 2025-08-23 10:50 Quote from: dbannon on August 23, 2025, 07:29:22 amI 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 · 2025-08-24 06:17 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2025-08-24 10:08 Quote from: wennerer on August 24, 2025, 08:17:38 amHello, 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. QuoteFor simplicity's sake, I entered the SSID and password directly. This point in wificonnect2  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. QuoteIn any case, I can say that the programme is now running and I am connected to the WiFi. Awesome! Great, have fun! ---------------------------------------------------------------------- wennerer · 2025-08-24 11:23 Hello, this is the serial output when i use wificonnect: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i esp_event_loop_create_default␍␍␊esp_wifi_init␍␍␊<0x1b>[0;32mI (211) system_api: Base MAC address is not set, read default base MAC address from EFUSE<0x1b>[0m␍␊<0x1b>[0;32mI (251) 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 (531) phy_init: phy ver: 1163_0<0x1b>[0m␍␊esp_ event_loop_init␍␍␊esp_wifi_set_mode␍␍␊esp_wifi_set_config␍␍␊esp_wifi_s tart␍␍␊Event: SYSTEM_EVENT_STA_START␍␍␊Wifi started, now connecting...␍␍␊<0x1b>[0;32mI (789) wifi:state: 0 -> 2 (b0)␍␊<0x1b>[0m<0x1b>[0;32mI (812) wifi:state: 2 -> 3 (0)␍␊<0x1b>[0m<0x1b>[0;32mI (824) wifi:state: 3 -> 5 (10)␍␊<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␍␊<0x1b>[0mEvent: SYSTEM_EVENT_STA_CONNECTED␍␍␊Wifi event received: SYSTEM_EVENT_STA_CONNECTED␍␍␊<0x1b>[0;32mI (1702) tcpip_adapter: sta ip: 192.168.178.118, mask: 255.255.255.0, gw: 192.168.178.1<0x1b>[0m␍␊Event: SYSTEM_EVENT_STA_LOST_IP␍␍␊Lost IP␍␍␊## UNEXPECTED EVENT, bits = 0␍␍␊Starting web server...␍␍␊Starting server on port: 80␍␍␊Registering URI handler␍␍␊ 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊<0x1b>[0;32mI (464) phy_init: phy ver: 1163_0<0x1b>[0m␍␊␍␍␊Runtime error 203␍␍␊_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 ---------------------------------------------------------------------- ccrause · 2025-08-24 12:54 Quote from: wennerer on August 24, 2025, 01:23:05 pmHello, this is the serial output when i use wificonnect: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i <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␍␊<0x1b>[0mEvent: SYSTEM_EVENT_STA_CONNECTED␍␍␊Wifi event received: SYSTEM_EVENT_STA_CONNECTED␍␍␊<0x1b>[0;32mI (1702) tcpip_adapter: sta ip: 192.168.178.118, mask: 255.255.255.0, gw: 192.168.178.1<0x1b>[0m␍␊Event: SYSTEM_EVENT_STA_LOST_IP␍␍␊Lost IP␍␍␊## UNEXPECTED EVENT, bits = 0␍␍␊Starting web server...␍␍␊Starting server on port: 80␍␍␊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. QuoteAnd this is the error message when i compile with '', whether with wificonnect or wificonnect2: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i phy_version: 1163.0, 665d56c, Jun 24 2020, 10:00:08, RTOS new␍␊<0x1b>[0;32mI (464) phy_init: phy ver: 1163_0<0x1b>[0m␍␊␍␍␊Runtime error 203␍␍␊_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).