ESP8266 Developer Zone The Official ESP8266 Forum 2023-02-24T13:42:25+08:00 https://bbs.espressif.com:443/feed.php?f=7 2023-02-24T13:42:25+08:00 2023-02-24T13:42:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=39619&p=108553#p108553 <![CDATA[ESP8266 SDK • Re: 加入hilinksdk编译产生bss' is not within region `dram0_0_seg]]> Statistics: Posted by yuzhai — Fri Feb 24, 2023 1:42 pm


]]>
2023-02-22T18:39:54+08:00 2023-02-22T18:39:54+08:00 https://bbs.espressif.com:443/viewtopic.php?t=74970&p=108519#p108519 <![CDATA[ESP8266 SDK • Re: suppress boot msg on ESP8266]]> I used 1N5819 Schottky Barrier Plastic Rectifier.

To start transmission, set the GPIO polarity to OUTPUT and the level to LOW.
This method works pretty reliably.

Code:

void setup() {
   pinMode(GPIO, OUTPUT);
   digitalWrite(GPIO, LOW);
   Serial.begin(115200);
74654209-28084e80-51cd-11ea-8af5-d0c03551a484.jpg

Statistics: Posted by nopnop2002 — Wed Feb 22, 2023 6:39 pm


]]>
2023-01-13T01:13:20+08:00 2023-01-13T01:13:20+08:00 https://bbs.espressif.com:443/viewtopic.php?t=3140&p=106491#p106491 <![CDATA[ESP8266 SDK • Re: clarification on software]]> https://mongoose.ws/tutorials/esp8266/http-client-server/

Statistics: Posted by Tom83 — Fri Jan 13, 2023 1:13 am


]]>
2023-01-01T23:07:51+08:00 2023-01-01T23:07:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=77267&p=105613#p105613 <![CDATA[ESP8266 SDK • Linker error]]>
msys_msg.png

Statistics: Posted by s56ffb — Sun Jan 01, 2023 11:07 pm


]]>
2022-12-21T15:51:13+08:00 2022-12-21T15:51:13+08:00 https://bbs.espressif.com:443/viewtopic.php?t=77094&p=105165#p105165 <![CDATA[ESP8266 SDK • Q:How to set NONOS system on Windows (Msys)?]]>
I noticed an interesting project on the Github that uses ESP8266 and Non-os code.The project
documentation states:


qz]Install ESP8266 gcc. See
https://docs.espressif.com/projects/esp ... setup.html
Fetch ESP8266_NONOS_SDK from https://github.com/espressif/ESP8266_NONOS_SDK
Point environment variable ESP_SDK to the SDK directory.
Install esptool.


Since I already have a MSYS system that compile gcc code for AVR devices
(http://siz.hu/en/content/sd2iec-develop ... nt-windows), I tried to add support also
for xtensa-lx106-elf and ESP8266 NONOS SDK by next 7 steps:

1. Download the toolchain 8.4.0 from
https://docs.espressif.com/projects/esp ... setup.html

2. Extract zip on C: ,result is new folder C:\xtensa-lx106-elf

3. DoWnload zip from https://github.com/espressif/ESP8266_NONOS_SDK

4. Extract zip on C: ,result is new folder C:\ESP8266_NONOS_SDK

5. In the .bat file that start Msys, I add next 3 lines:
set Xtensa_PATH=%CD:~0,2%\xtensa-lx106-elf
set PATH=%PATH%;%Xtensa_PATH%\bin
set ESP_SDK=%CD:~0,2%\ESP8266_NONOS_SDK

6. Run the Msys and test:
xtensa-lx106-esp-gcc -- version -> print version 8.4.0 and other stuff
printenv ESP_SDK -> C:\ESP8266_NONOS_SDK

7, run sh script in /C/ESP8266_NONOS_SDK/driver_lib
./make_lib.sh driver
--------
But this not work...

When I start the make command in the project folder, compiler did not find ets_sys.h. I solved
this by simply add the missing .h files from SDK into the project folder.

Now compiling started successfully and produce object code (.o files), but then the linker
reported cannot find -lhal and few other missing parts.

It seems that the xtensa-lx106-elf does not know where the SDK is located. What did I do wrong?

Statistics: Posted by s56ffb — Wed Dec 21, 2022 3:51 pm


]]>
2022-12-18T19:10:02+08:00 2022-12-18T19:10:02+08:00 https://bbs.espressif.com:443/viewtopic.php?t=77046&p=104961#p104961 <![CDATA[ESP8266 SDK • Q:How to set NONOS system on Windows (Msys)?]]>
I noticed an interesting project on the Github that uses ESP8266 and Non-os code.The project documentation states:

Install ESP8266 gcc. See https://docs.espressif.com/projects/esp ... setup.html
Fetch ESP8266_NONOS_SDK from https://github.com/espressif/ESP8266_NONOS_SDK
Point environment variable ESP_SDK to the SDK directory.
Install esptool.


Since I already have a MSYS system that compile gcc code for AVR devices (http://siz.hu/en/content/sd2iec-develop ... nt-windows), I tried to add support also for xtensa-lx106-elf and ESP8266 NONOS SDK by next 7 steps:

1. Download the toolchain 8.4.0 from https://docs.espressif.com/projects/esp ... setup.html

2. Extract zip on C: ,result is new folder C:\xtensa-lx106-elf

3. DoWnload zip from https://github.com/espressif/ESP8266_NONOS_SDK

4. Extract zip on C: ,result is new folder C:\ESP8266_NONOS_SDK

5. In the .bat file that start Msys, I add next 3 lines:
set Xtensa_PATH=%CD:~0,2%\xtensa-lx106-elf
set PATH=%PATH%;%Xtensa_PATH%\bin
set ESP_SDK=%CD:~0,2%\ESP8266_NONOS_SDK

6. Run the Msys and test:
xtensa-lx106-esp-gcc -- version -> print version 8.4.0 and other stuff
printenv ESP_SDK -> C:\ESP8266_NONOS_SDK

7, run sh script in /C/ESP8266_NONOS_SDK/driver_lib
./make_lib.sh driver
--------

But this not work...

When I start the make command in the project folder, compiler did not find ets_sys.h. I solved this by simply add the missing .h files from SDK into the project folder.

Now compiling started successfully and produce object code (.o files), but then the linker reported cannot find -lhal and few other missing files or folders (picture below).

It seems that the xtensa-lx106-elf does not know where the SDK is located. What did I do wrong?
msys_msg.png

Statistics: Posted by s56ffb — Sun Dec 18, 2022 7:10 pm


]]>
2022-12-18T17:58:32+08:00 2022-12-18T17:58:32+08:00 https://bbs.espressif.com:443/viewtopic.php?t=77044&p=104959#p104959 <![CDATA[ESP8266 SDK • How to set NONOS system on Windows (Msys)?]]>
I noticed an interesting project on the Github that uses ESP8266 and Non-os code.The project documentation states:


qz]Install ESP8266 gcc. See https://docs.espressif.com/projects/esp ... setup.html
Fetch ESP8266_NONOS_SDK from https://github.com/espressif/ESP8266_NONOS_SDK
Point environment variable ESP_SDK to the SDK directory.
Install esptool.


Since I already have a MSYS system that compile gcc code for AVR devices (http://siz.hu/en/content/sd2iec-develop ... nt-windows), I tried to add support also for xtensa-lx106-elf and ESP8266 NONOS SDK by next 7 steps:

1. Download the toolchain 8.4.0 from https://docs.espressif.com/projects/esp ... setup.html

2. Extract zip on C: ,result is new folder C:\xtensa-lx106-elf

3. DoWnload zip from https://github.com/espressif/ESP8266_NONOS_SDK

4. Extract zip on C: ,result is new folder C:\ESP8266_NONOS_SDK

5. In the .bat file that start Msys, I add next 3 lines:
set Xtensa_PATH=%CD:~0,2%\xtensa-lx106-elf
set PATH=%PATH%;%Xtensa_PATH%\bin
set ESP_SDK=%CD:~0,2%\ESP8266_NONOS_SDK

6. Run the Msys and test:
xtensa-lx106-esp-gcc -- version -> print version 8.4.0 and other stuff
printenv ESP_SDK -> C:\ESP8266_NONOS_SDK

7, run sh script in /C/ESP8266_NONOS_SDK/driver_lib
./make_lib.sh driver
--------

But this not work...

When I start the make command in the project folder, compiler did not find ets_sys.h. I solved this by simply add the missing .h files from SDK into the project folder.

Now compiling started successfully and produce object code (.o files), but then the linker reported cannot find -lhal and few other missing files or folders (picture below).

It seems that the xtensa-lx106-elf does not know where the SDK is located. What did I do wrong?
msys_msg.png

Statistics: Posted by s56ffb — Sun Dec 18, 2022 5:58 pm


]]>
2022-12-02T15:06:55+08:00 2022-12-02T15:06:55+08:00 https://bbs.espressif.com:443/viewtopic.php?t=76556&p=103941#p103941 <![CDATA[ESP8266 SDK • ESP8266 : NonOS SDK API system_phy_set_tpw_via_vdd33]]> I need more description about this api. I tested tx power with this function param 1900 to 3300 and result make me surprised. Param 1900 make esp has more tx power in dbm than param 3300. Can anyone explain ? Thanks.

Statistics: Posted by DonP — Fri Dec 02, 2022 3:06 pm


]]>
2022-11-14T18:08:08+08:00 2022-11-14T18:08:08+08:00 https://bbs.espressif.com:443/viewtopic.php?t=76210&p=103240#p103240 <![CDATA[ESP8266 SDK • How to implement MQTT in PlatformIO IDE ESP8266 RTOS SDK 1.5]]>
Here Development board i am using is NodeMcu ESP8266 V3 Lua CH340 Wifi Dev. Board
Development Environment -> Platform IO IDE in Visual Studio Code.
Platform IO IDE SDK version support -> 1.5
Framework -> ESP8266 RTOS SDK
ESP8266 RTOS SDK download from expressif site -> Latest Version 3.4 (this version is not supported by PlatformIO IDE in Visual Studio Code)

Now here my ESP8266 is connected to the mobile hotspot as a station mode successfully. But now i have to connect this ESP8266 device to mqtt broker. But PlatformIO IDE inbuilt RTOS SDK version 1.5 do not have support of mqtt. This SDK do not have mqtt examples. So can u please let me know how can i do mqtt implementation here.

Waiting for your reply as early as possible.

Regards,
RRJ

Statistics: Posted by Ronak Jain — Mon Nov 14, 2022 6:08 pm


]]>
2022-11-13T08:19:38+08:00 2022-11-13T08:19:38+08:00 https://bbs.espressif.com:443/viewtopic.php?t=76200&p=103222#p103222 <![CDATA[ESP8266 SDK • is possible Esp8266ex boot from HSPI ?]]> in my project i need sdio interface and i want to config esp8266 boot from HSPI connect flash.
i search alot but i don't find anythings about how do it,
is possible config esp8266ex to boot from HSPI interface?
thanks

Statistics: Posted by MehdiSoheili — Sun Nov 13, 2022 8:19 am


]]>
2022-11-03T03:47:28+08:00 2022-11-03T03:47:28+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9178&p=102751#p102751 <![CDATA[ESP8266 SDK • Re: ESP8266 2MB + OTA]]>

Statistics: Posted by AgentSmithers — Thu Nov 03, 2022 3:47 am


]]>
2022-10-26T13:59:26+08:00 2022-10-26T13:59:26+08:00 https://bbs.espressif.com:443/viewtopic.php?t=55&p=102610#p102610 <![CDATA[ESP8266 SDK • Re: SDK v0.9.3 Patch]]> Statistics: Posted by matton — Wed Oct 26, 2022 1:59 pm


]]>
2022-10-19T00:54:59+08:00 2022-10-19T00:54:59+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75770&p=102498#p102498 <![CDATA[ESP8266 SDK • ESP8266 cause reboot randomly - nonOS SDK - please help]]>
The following 2 line message are shown from serial port right before rebooting, then it will reboot immediately:
"tx rts error 0x16"
"mac 1370"

I am using arduino IDE with ESP8266 sdk v2.7.4, nonosdk, I have spent so much time to identify the issue, however I have no clue so far.

I suspect it has something to do with Nonos_sdk, and but there is no source code to let me tracking down where and how the issue occurs.

NOTES: I must use ESP8266 SDK v2.74 (or lower), but cannot use greater than v2.7.4, since I need to use lwip v1.4 compile from source option, and high version sdk doesn't have this option but only lwip v2.0, which is not suitable for our project.

Please help to resolve this issue.
Thanks in advance.

Statistics: Posted by johnxue — Wed Oct 19, 2022 12:54 am


]]>
2022-10-17T17:38:15+08:00 2022-10-17T17:38:15+08:00 https://bbs.espressif.com:443/viewtopic.php?t=50992&p=102486#p102486 <![CDATA[ESP8266 SDK • Re: How to achieve the "Shut down" / "power off" Power Mode]]> I try to set CHIP_EN pin to low but I got high current consumption.
The specification state that there is a power down mode for 0.5uA but no further description about this mode in the specification.

Statistics: Posted by rayleong — Mon Oct 17, 2022 5:38 pm


]]>
2022-10-08T19:10:44+08:00 2022-10-08T19:10:44+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9178&p=102325#p102325 <![CDATA[ESP8266 SDK • Re: ESP8266 2MB + OTA]]>
backupluis wrote:
FrenkR wrote:Issue resolved. If you have partition of size 1MB or 2MB, then "irom0_0_seg" address-es are the same for both partitions (looks like 0x1000 or 0x101000 are the same?). If you have 512KB partitions, then you must create LD script with different ROM addresses same way as is in LD files for 1024KB OTA partition segmentation(e.g.eagle.app.v6.new.1024.app1.ld, eagle.app.v6.new.1024.app2.ld).

If you don't do that, then uprading from app1 to app2 with the same bin will work, but if you will empty segment1, bin2 will stop working (which makes sense).

I hope that I saved 3 days of hard work "hunting" all those zillion of exceptions.
Rgds,
Frenk


I have a problem that looks like this one, first off all, Im using rtos sdk 1.4, yes, its very old and I want to move to 2 or even to 3 but I can't until I resolve some problems.
I been using this sdk version since 2017 in a wroom 2 board without any problems, even ota updates works well, but some days ago I found a ESP8266-1 8Mbits board in my lab and start to move the project to this board, just to have a starting source before try to migrate to sdk v2.

I can't do OTA update from user2 to user1 (Looks like the same problem noted in this thread). while OTA from user1 to user2 works well, from user2 to user1 hangs just after the flash erase then reboot by watchdog timer in the same user2 but it no longer boots, so, in my case, user2 seems to need something from user1,

I check my ld files and in my case irom0_0_seg are differents:
eagle.app.v6.new.1024.app1.ld irom0_0_seg : org = 0x40201010, len = 0x2B000
eagle.app.v6.new.1024.app2.ld irom0_0_seg : org = 0x40281010, len = 0x2B000

But I see something that looks weird, my two bin files are equals, user1.1024.new.bin and user2.1024.new.bin are binary equal.
I don't know too much about the internals of the compilers and the sdk, so, my question is:

is ok that both files have the same content?
If so, why we have to generate two files if the content its the same.
If not, why my setup generate both files with the same content and where I have to start digging to try to resolve it.

I really appreciate if you can explain or help me a little about my problem/confusion.

Thanks
Luis


I reply myself, just to leave record of the problem, I just read in some other post that user1 and user2 could NOT be equals, so, I start to check files I use to compile, this files was used for wroom 2 and I make new versions for esp-1, in some of the edits, I've removed the make clean between user1 and user2, thats why my bin files are equal, then, recompile and reflash, then test ota from user1 to user2 => OK, then from user2 to user1 => OK, so, my problem its solved.

Statistics: Posted by backupluis — Sat Oct 08, 2022 7:10 pm


]]>
2022-10-08T18:43:42+08:00 2022-10-08T18:43:42+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9178&p=102324#p102324 <![CDATA[ESP8266 SDK • Re: ESP8266 2MB + OTA]]>
FrenkR wrote:
Issue resolved. If you have partition of size 1MB or 2MB, then "irom0_0_seg" address-es are the same for both partitions (looks like 0x1000 or 0x101000 are the same?). If you have 512KB partitions, then you must create LD script with different ROM addresses same way as is in LD files for 1024KB OTA partition segmentation(e.g.eagle.app.v6.new.1024.app1.ld, eagle.app.v6.new.1024.app2.ld).

If you don't do that, then uprading from app1 to app2 with the same bin will work, but if you will empty segment1, bin2 will stop working (which makes sense).

I hope that I saved 3 days of hard work "hunting" all those zillion of exceptions.
Rgds,
Frenk


I have a problem that looks like this one, first off all, Im using rtos sdk 1.4, yes, its very old and I want to move to 2 or even to 3 but I can't until I resolve some problems.
I been using this sdk version since 2017 in a wroom 2 board without any problems, even ota updates works well, but some days ago I found a ESP8266-1 8Mbits board in my lab and start to move the project to this board, just to have a starting source before try to migrate to sdk v2.

I can't do OTA update from user2 to user1 (Looks like the same problem noted in this thread). while OTA from user1 to user2 works well, from user2 to user1 hangs just after the flash erase then reboot by watchdog timer in the same user2 but it no longer boots, so, in my case, user2 seems to need something from user1,

I check my ld files and in my case irom0_0_seg are differents:
eagle.app.v6.new.1024.app1.ld irom0_0_seg : org = 0x40201010, len = 0x2B000
eagle.app.v6.new.1024.app2.ld irom0_0_seg : org = 0x40281010, len = 0x2B000

But I see something that looks weird, my two bin files are equals, user1.1024.new.bin and user2.1024.new.bin are binary equal.
I don't know too much about the internals of the compilers and the sdk, so, my question is:

is ok that both files have the same content?
If so, why we have to generate two files if the content its the same.
If not, why my setup generate both files with the same content and where I have to start digging to try to resolve it.

I really appreciate if you can explain or help me a little about my problem/confusion.

Thanks
Luis

Statistics: Posted by backupluis — Sat Oct 08, 2022 6:43 pm


]]>
2022-10-07T02:06:12+08:00 2022-10-07T02:06:12+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9178&p=102307#p102307 <![CDATA[ESP8266 SDK • Re: ESP8266 2MB + OTA]]>
If you don't do that, then uprading from app1 to app2 with the same bin will work, but if you will empty segment1, bin2 will stop working (which makes sense).

I hope that I saved 3 days of hard work "hunting" all those zillion of exceptions.
Rgds,
Frenk

Statistics: Posted by FrenkR — Fri Oct 07, 2022 2:06 am


]]>
2022-10-05T09:30:49+08:00 2022-10-05T09:30:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9178&p=102290#p102290 <![CDATA[ESP8266 SDK • Re: ESP8266 2MB + OTA]]> I run into the same problem I believe. ESP-WROOM02 (16M, 512+512 OTA), bootloader 1.7, SDK 3.0.5, partition table:

Code:

   #define SYSTEM_PARTITION_OTA_SIZE                     0x6A000
   #define SYSTEM_PARTITION_OTA_2_ADDR                     0x81000
   #define SYSTEM_PARTITION_RF_CAL_ADDR                  0x1fb000
   #define SYSTEM_PARTITION_PHY_DATA_ADDR                  0x1fc000
   #define SYSTEM_PARTITION_SYSTEM_PARAMETER_ADDR            0x1fd000
   #define SYSTEM_PARTITION_CUSTOMER_PRIV_PARAM_ADDR           0x7c000

I found following. Upgrade from user1 -> user2 works. When chip is running user2 code and I remove code "user1.bin" (OTA partition 1), system stops working and following error is displayed:

Code:

Fatal exception (0):
epc1=0x40213e48, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Fatal exception (0):
epc1=0x40213e48, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
Fatal exception (0):
epc1=0x40213e48, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000


0x40213e48 via disassembler points to following:

Code:

40213e48 <init_bss_data>:
40213e48:   fffe61           l32r   a6, 40213e40 <print_system_param_sectors+0x18>
40213e4b:   fffe41           l32r   a4, 40213e44 <print_system_param_sectors+0x1c>
40213e4e:   050c         movi.n   a5, 0
40213e50:   07b467           bgeu   a4, a6, 40213e5b <init_bss_data+0x13>
40213e53:   004452           s8i   a5, a4, 0
40213e56:   441b         addi.n   a4, a4, 1
40213e58:   f79467           bne   a4, a6, 40213e53 <init_bss_data+0xb>
40213e5b:   f00d         ret.n
40213e5d:   00             .byte 00
40213e5e:   00             .byte 00
40213e5f:   00             .byte 00
40213e60:   08 90 fe 3f    
40213e64:   10 90 fe 3f    
40213e68:   cc 24 00 40    


It looks that even if OTA2 (user2.bin) firmware is running, something points to section in OTA1 and if user1.bin is not there, firmware will not run. Any idea what to check to fix this issue?
Rgds,
Frenk

Statistics: Posted by FrenkR — Wed Oct 05, 2022 9:30 am


]]>
2022-09-16T09:20:44+08:00 2022-09-16T09:20:44+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75639&p=102150#p102150 <![CDATA[ESP8266 SDK • as station reconnect ap no ip]]>
when boot,the device connect the ap success,and dhcp client received the ip address.
then i close the ap,device report disconnected,then i reopen the ap,device show connected,but no ip get event trigged.
for this issue,i must reboot the device,does it has another method to resolve this issue

Statistics: Posted by Just — Fri Sep 16, 2022 9:20 am


]]>
2022-06-05T19:57:10+08:00 2022-06-05T19:57:10+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75388&p=101459#p101459 <![CDATA[ESP8266 SDK • Re: TCP client and Server at the same time ESP8266 Non OS SDK 2.2.1]]> Statistics: Posted by gailu — Sun Jun 05, 2022 7:57 pm


]]>
2022-05-27T12:13:30+08:00 2022-05-27T12:13:30+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75388&p=101300#p101300 <![CDATA[ESP8266 SDK • TCP client and Server at the same time ESP8266 Non OS SDK 2.2.1]]>
We are long time user of esp8266 and running thousands of live devices in home automation category on this chip. However a small limitation is holding us to develop some more interesting and innovative products.

Requirement: We have a requirement to run both TCP client (connected to our cloud server) and TCP server (on which some TCP clients can connect to ESP) at the same time.

Limitation: While we do not get any error when setting up TCP client and TCP Server at same time however we receive data only on connected client. Other TCP clients can not connect to TCP server. If do not connect TCP client from ESP to cloud server, TCP server on ESP very well accepts TCP client connections.

TCP client + UDP server also works perfectly.

Is there any work around to this limitation of TCP client and TCP server running on ESP8266 at the same time?

[Removing this limitation will certainly help to increase footprint of esp8266. With this limitation we are getting forced to look for alternatives]

Statistics: Posted by gailu — Fri May 27, 2022 12:13 pm


]]>
2022-05-18T16:47:12+08:00 2022-05-18T16:47:12+08:00 https://bbs.espressif.com:443/viewtopic.php?t=661&p=101246#p101246 <![CDATA[ESP8266 SDK • Re: SSL/TLS handshake issue]]>
Perhaps someone else already discovered the reason behind the ESP8266 SSL Handshake Failure, but I found out that ESP8266 sends an initial Random during Client Hello with UNIX Timestamp 00000000 (=Jan 1, 1970 01:00:00.000000000). This is outside the web server certificate's time frame and may be a reason for the web server to reject the connection.

I am using an ESP8266 containing:

AT version:1.7.5.0(Oct 9 2021 09:26:04)
SDK version:3.0.5(b29dcd3)
compile time:Oct 15 2021 18:05:38
Bin version(Wroom 02):1.7.5


Before sending AT+CIPSTART="SSL","servername",443 I did configure SNTP using AT+CIPSNTPCFG=1,1,"pool.ntp.org" and issued a successful SNTP request with AT+CIPSNTPTIME?. But still the time info in the Random remains 0. See wireshark extract below:

Handshake Protocol: Client Hello
Handshake Type: Client Hello (1)
Length: 47
Version: TLS 1.1 (0x0302)
Random: 000000006606ced024c458f0afad29b242403955b02a121fd48d0fc83c452f44
GMT Unix Time: (0)Jan 1, 1970 01:00:00.000000000
Random Bytes: 6606ced024c458f0afad29b242403955b02a121fd48d0fc83c452f44
Session ID Length: 0
Cipher Suites Length: 8
Cipher Suites (4 suites)
Cipher Suite: TLS_RSA_WITH_AES_128_CBC_SHA (0x002f)
Cipher Suite: TLS_RSA_WITH_AES_256_CBC_SHA (0x0035)
Cipher Suite: TLS_RSA_WITH_RC4_128_SHA (0x0005)
Cipher Suite: TLS_RSA_WITH_RC4_128_MD5 (0x0004)


The (Apache) webserver is allowing TLSv1.1, but responds with:

Transport Layer Security
TLSv1.1 Record Layer: Alert (Level: Fatal, Description: Handshake Failure)
Content Type: Alert (21)
Version: TLS 1.1 (0x0302)
Length: 2
Alert Message
Level: Fatal (2)
Description: Handshake Failure (40)


To test what happens if the Apache server does NOT accept TLSv1.1 I temporarily modified the server's SSL configuration. Then it responds as follows:

Transport Layer Security
TLSv1.1 Record Layer: Alert (Level: Fatal, Description: Protocol Version)
Content Type: Alert (21)
Version: TLS 1.1 (0x0302)
Length: 2
Alert Message
Level: Fatal (2)
Description: Protocol Version (70)


So it indicates reject because of the used TLS protocol version.

The server also accepts ciphers TLS_RSA_WITH_AES_128_CBC_SHA and TLS_RSA_WITH_AES_256_CBC_SHA, so this is probably not the reason for handshake failure.


So I have the strong impression that the wrong time stamp is the reason for the failed SSL connections. Any idea how this can be solved?
Thanks!

Statistics: Posted by ESP_Frank — Wed May 18, 2022 4:47 pm


]]>
2022-04-29T22:48:12+08:00 2022-04-29T22:48:12+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75335&p=101099#p101099 <![CDATA[ESP8266 SDK • Update firmware/SDK via flash tool 3.9.2]]> The Flash Tool SPIAUTOset and Flash size are not shown and there are only 2 tabs at the top. It is completely different to that shown in the Document. Have tried on different computer, using Windows 7.
Flash tool.png

Statistics: Posted by David-OLW — Fri Apr 29, 2022 10:48 pm


]]>
2022-04-15T11:23:01+08:00 2022-04-15T11:23:01+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75241&p=100903#p100903 <![CDATA[ESP8266 SDK • Re: ESP8266 cant join AP]]>
Perhaps related to this, other frameworks I have explored require a board definition (PlatformIO, Arduino) but I don't see that in the ESP8266-RTOS-SDK. Is that covered in `make menuconfig` or am I missing something here?

Thanks!

Statistics: Posted by HankB — Fri Apr 15, 2022 11:23 am


]]>
2022-03-21T01:42:56+08:00 2022-03-21T01:42:56+08:00 https://bbs.espressif.com:443/viewtopic.php?t=1240&p=100785#p100785 <![CDATA[ESP8266 SDK • Re: Cannot connect to ESP SoftAP after update SDK to 1.4.0 from Android devices]]>
ESP_Faye wrote:
Hi,

Here is a demo of ESP8266 softAP http://bbs.espressif.com/viewtopic.php?f=31&t=227.

Please try the test code to see if the problem is still unsolved ?

Notice that the "softap_config" has to be initialized, especially the softap_config.beacon_interval and softap_config.ssid_len, they has to be initialized, suggested to be 0.

Thanks for your interest in ESP8266 !


Also facing same issue.

Statistics: Posted by alexsadi — Mon Mar 21, 2022 1:42 am


]]>
2022-03-04T18:11:31+08:00 2022-03-04T18:11:31+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75303&p=100731#p100731 <![CDATA[ESP8266 SDK • Encrypted ESP01 ESP32]]> I have an installation working very good but now I would like "to play" with security.
I have multiple master sending information to one slave.
My masters are ESP01 and my slave is ESP32.
I am having problem when try to use key to encrypt the message.
The main part of the code:

Code:

esp_now_add_peer(mac,role,channel,key,size)
--> when KEY is NULL, everything is OK. when KEY has value, the receiver (esp32) doesn't receive anything.
is it possible? Does somebody proof this feature?
Thanks in advance.

Statistics: Posted by dvpe — Fri Mar 04, 2022 6:11 pm


]]>
2022-02-21T10:54:05+08:00 2022-02-21T10:54:05+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75299&p=100680#p100680 <![CDATA[ESP8266 SDK • smart config]]> Statistics: Posted by sxy369 — Mon Feb 21, 2022 10:54 am


]]>
2022-02-16T14:45:33+08:00 2022-02-16T14:45:33+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75295&p=100667#p100667 <![CDATA[ESP8266 SDK • Reset Cause 0 (unknown reset) after deep sleep]]> Environment
Development Kit: ESP12-F (ESP8266 Mod 4MB Flash)
IDF version: e9516e4 (release/v3.4)
Development Env: Make
Operating System: Ubuntu
Power Supply: Battery
Problem Description
can not boot
log-terminal shows: unknown reset

Expected Behavior
boot without any exception

Actual Behavior
CAN NOT boot, logs shows as below:

Code:

ets Jan  8 2013,rst cause:0, boot mode:(3,0)

unknown reset
ets_main.c


Steps to repropduce
    power on or wake up from deep sleep
    run code, connect wifi ... etc , about 5s
    run esp_deep_sleep(30000000) // 30s
    repeat step 1 - 3 about 2000-8000 cycle

Code to reproduce this issue
in function app_main()

Code:

vTaskDelay(5000 / portTICK_PERIOD_MS);
esp_deep_sleep(30000000);


Debug Logs

Code:

ets Jan  8 2013,rst cause:0, boot mode:(3,0)

unknown reset
ets_main.c

Statistics: Posted by cubic — Wed Feb 16, 2022 2:45 pm


]]>
2022-02-15T16:43:55+08:00 2022-02-15T16:43:55+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75294&p=100664#p100664 <![CDATA[ESP8266 SDK • Build Error with ESP8266_RTOS_SDK-v3.4]]> I tried to import SDK3.4 into Aithinker windows IDE program and then build it. Unfortunately i got the following error:

LD /d/8266/ESP8266_RTOS_SDK-v3.4/examples/get-started/hello_world/build/hello-world.elf
d:/program files (x86)/aithinkeride_v1.5.2/msys32/opt/esp8266/v5.2.0_for_3.0/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/bin/ld.exe: cannot find -lc_nano
collect2.exe: error: ld returned 1 exit status
make: *** [D:\8266\ESP8266_RTOS_SDK-v3.4/make/project.mk:510: /d/8266/ESP8266_RTOS_SDK-v3.4/examples/get-started/hello_world/build/hello-world.elf] Error 1

15:56:16 Build Finished (took 2m:36s.724ms)

can you help me with this error? how can i fix it?

Statistics: Posted by yingzezigai — Tue Feb 15, 2022 4:43 pm


]]>
2022-02-04T14:48:15+08:00 2022-02-04T14:48:15+08:00 https://bbs.espressif.com:443/viewtopic.php?t=640&p=100623#p100623 <![CDATA[ESP8266 SDK • Re: Connect with host name?]]> Statistics: Posted by marclesgomz — Fri Feb 04, 2022 2:48 pm


]]>
2022-01-18T23:12:58+08:00 2022-01-18T23:12:58+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75271&p=100570#p100570 <![CDATA[ESP8266 SDK • Re: Cjson print problem]]> Statistics: Posted by AgentSmithers — Tue Jan 18, 2022 11:12 pm


]]>
2022-01-16T01:18:22+08:00 2022-01-16T01:18:22+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75282&p=100559#p100559 <![CDATA[ESP8266 SDK • Add components to a component]]>
I am pretty new to the ESP8266 IDF and I have some questions.

I have created a project with different components, but for example I would like to import FreeRTOS in the #include section of my component source files.
I know I have to write it in the "component.mk", but I cannot make it work!
The make list-components shows everything correctly, but I cannot build correctly because the compiler cannot find the header files outside the "main" directory.

Please can you help me!

Thank you in advice.

Statistics: Posted by banach87 — Sun Jan 16, 2022 1:18 am


]]>
2022-01-11T07:45:01+08:00 2022-01-11T07:45:01+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75279&p=100545#p100545 <![CDATA[ESP8266 SDK • Failed to connect to Espressif device: Timed out waiting for packet header]]>
For whatever reason I can't flash anything to them neither using Arduino IDE nor using esptool.py. No matter what I do - I always receive "Failed to connect to Espressif device: Timed out waiting for packet header". For all 5 chips - same behavior.

I can connect to the device using minicom, and on "reset" it greets me with cryptic message

Code:

brlrl
ready

So at least the chips and the board itself are operable.

I tried to connect UART pins of the burner to CH340 adapter I have and then flash it - basically the same result.

I tried to press "flash + reset" and then release "flash" during that "Connecting..." prompt - no luck.

The same USB cable works just fine to flash NodeMCU boards, but I wonder if I am missing something with this one.

Statistics: Posted by stark2k — Tue Jan 11, 2022 7:45 am


]]>
2022-01-05T23:57:22+08:00 2022-01-05T23:57:22+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100528#p100528 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> Glad to know the OVA was of some assistance! =]

Statistics: Posted by AgentSmithers — Wed Jan 05, 2022 11:57 pm


]]>
2022-01-05T23:39:39+08:00 2022-01-05T23:39:39+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100527#p100527 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]>

I got it working... here are the results.
My program runs fine on your environment, as well as PlatformIO environments and on the Arduino environment versions too... IF... I include a call to espconn_init().

Some time ago, I read one post on another thread mentioning this method, but adding it to my projects gave compiler errors. So I discounted the post as being for an older version. The thing is... this call wasn't needed in SDK 2.2 and earlier.

Anyway, I was working backwards though the available Espressif codebase from the espconn_regist_disconcb() method and ran into... wait for it... espconn_init() in an Espressif C file. But it had no corresponding H file declaring it. I simply added my own declaration...

extern "C" void ICACHE_FLASH_ATTR espconn_init(void);

and added the call in my startup code... and Wham, bam, thank you mam! My disconnect callback started getting called and all was right with the world.

Thanks for your help!

Statistics: Posted by Inquisitor — Wed Jan 05, 2022 11:39 pm


]]>
2021-12-24T08:35:06+08:00 2021-12-24T08:35:06+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100485#p100485 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> *Edit* Yep, this is set to

osboxes.org <--- same as username. This is the default from osboxes.org (of course)

Statistics: Posted by AgentSmithers — Fri Dec 24, 2021 8:35 am


]]>
2021-12-24T05:50:08+08:00 2021-12-24T05:50:08+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100484#p100484 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]>
AgentSmithers wrote:
LMAO, no your fine.. I should of packed up a thumbdrive and sent over a carrier pigeon lol. I'll keep watch for your reply if you need anything else. I still use this OVA today for alot of my programming so should work like a charm.


For someone that spent the last twenty years of my career tied to fiber, this feels like using smoke-signals. For S&G, I started a download at home while all the tourist and locals are at home for the holidays... projected to be three+ days to download. Drove over to the library... and seven whole minutes to download. It's all GOOD! :D Next...

  1. Fortunately, I had VirtualBox loaded and a couple of Windows VM's that I know work.
  2. Imported just fine.
  3. Trying to boot up, it complained about the NIC card, but apparently that is a Virtual Box setting and it let me swap that over.
  4. Next it complained about my USB. It let me select the USB 1.1 and didn't complain (I have 2.0 and 3.0 ports on my desktop) Hoping if that is a problem, it'll let me upgrade them by detection and download over the Internet once I get in.
  5. It booted up and I'm now at the login... I tried all kinds of accounts/passwords... <blank>, sudo, su, password, passW0rd, pw, AgentSmithers, Inquisitor... and looked on the Internet for defaults for CentOS. Those didn't work either.

Seems like I'm close.

P.S. - I came from a Microsoft Windows development background and use the Arduino IDE for the MPU's... :? IOW... I barely know what a make file is... and have never knowingly opened one up. Even my baby step into PlatformIO have sheltered me from those evil files. :D If it's not too much trouble, a small project with make file would be great. Although, I probably could dig out the example projects from Espressif.

Oh... and no rush. Don't let this interfere with your holidays.

VBR

Statistics: Posted by Inquisitor — Fri Dec 24, 2021 5:50 am


]]>
2021-12-23T08:06:25+08:00 2021-12-23T08:06:25+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100478#p100478 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]>
Inquisitor wrote:
AgentSmithers wrote:Link as promised!
Download OracleBox and you can import the OVA.
https://drive.google.com/file/d/1JrA750 ... sp=sharing
Then import you project folder and compile and your good to go!
Let me know if you need help but that is a fully setup dev. If you need a test project if your having issues let me know and Ill zip one up with a makefile and send that over too.


Thank you for all your time. I hope I didn't take you away from festivities. :?
Later today, I'll go into town and download this at the library. If I remember correctly, these images are multi-gigabytes. I'm on a metered connection here at the house and with everyone home this time of year, my download is often below 1 Mbit and sometime it drops. :( I'll report back with progress.



LMAO, no your fine.. I should of packed up a thumbdrive and sent over a carrier pigeon lol. I'll keep watch for your reply if you need anything else. I still use this OVA today for alot of my programming so should work like a charm.

Statistics: Posted by AgentSmithers — Thu Dec 23, 2021 8:06 am


]]>
2021-12-22T18:41:55+08:00 2021-12-22T18:41:55+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100474#p100474 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]>
AgentSmithers wrote:
Link as promised!
Download OracleBox and you can import the OVA.
https://drive.google.com/file/d/1JrA750 ... sp=sharing
Then import you project folder and compile and your good to go!
Let me know if you need help but that is a fully setup dev. If you need a test project if your having issues let me know and Ill zip one up with a makefile and send that over too.


Thank you for all your time. I hope I didn't take you away from festivities. :?
Later today, I'll go into town and download this at the library. If I remember correctly, these images are multi-gigabytes. I'm on a metered connection here at the house and with everyone home this time of year, my download is often below 1 Mbit and sometime it drops. :( I'll report back with progress.

Statistics: Posted by Inquisitor — Wed Dec 22, 2021 6:41 pm


]]>
2021-12-22T06:53:42+08:00 2021-12-22T06:53:42+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100473#p100473 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> Download OracleBox and you can import the OVA.
https://drive.google.com/file/d/1JrA750 ... sp=sharing
Then import you project folder and compile and your good to go!
Let me know if you need help but that is a fully setup dev. If you need a test project if your having issues let me know and Ill zip one up with a makefile and send that over too.

Statistics: Posted by AgentSmithers — Wed Dec 22, 2021 6:53 am


]]>
2021-12-16T06:03:23+08:00 2021-12-16T06:03:23+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100460#p100460 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> Statistics: Posted by AgentSmithers — Thu Dec 16, 2021 6:03 am


]]>
2021-12-16T06:02:57+08:00 2021-12-16T06:02:57+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100459#p100459 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> Statistics: Posted by AgentSmithers — Thu Dec 16, 2021 6:02 am


]]>
2021-12-15T23:28:00+08:00 2021-12-15T23:28:00+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100458#p100458 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]>
AgentSmithers wrote:
Ah! I feel your pain, I used Pfalcons tool chain and had a hell of a time getting to Version 3.0+.
I have a VM premade with the environment setup in cent os (for this exact problem), Ill get it uploaded to Googledrive and you can download it and give it a run in Oracle box and move your files to it or from a share on your host OS. Its a complete setup of the latest SDK for NON-OS. Would that give you a hand?


Sure! That would be very helpful. At the very least it would confirm whether my program above works on pure Espressif SDK > 2.1. It would also confirm my suspicions that it's the Arduino libraries riding on top of Espressif SDK > 2.1 causing the problem.

Thank you for your help.

Statistics: Posted by Inquisitor — Wed Dec 15, 2021 11:28 pm


]]>
2021-12-14T05:02:38+08:00 2021-12-14T05:02:38+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100448#p100448 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> I have a VM premade with the environment setup in cent os (for this exact problem), Ill get it uploaded to Googledrive and you can download it and give it a run in Oracle box and move your files to it or from a share on your host OS. Its a complete setup of the latest SDK for NON-OS. Would that give you a hand?

Statistics: Posted by AgentSmithers — Tue Dec 14, 2021 5:02 am


]]>
2021-12-13T19:59:07+08:00 2021-12-13T19:59:07+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75271&p=100446#p100446 <![CDATA[ESP8266 SDK • Cjson print problem]]> ISSUE : using cJSON_AddNumberToObject crashes the ESP8266 during cJSON_Print command. The same piece of code executed correctly on ESP32.

void json_task(void *para)
{
int stackmem = uxTaskGetStackHighWaterMark(NULL);
ESP_LOGI("TAG", "stack space = %d", stackmem);

cJSON *root = cJSON_CreateObject();
bool res=cJSON_AddNumberToObject(root,"meta",212);
//cJSON_AddStringToObject(root,"meta","stringval");
char *out=cJSON_Print(root);
//cJSON_PrintPreallocated(root,resp,1500,true);
ESP_LOGI("TAG","\n%s\n",out);
while(1){vTaskDelay(100);}
}


the issue seems to be only with AddNumeberToObject, cJSON_AddStringToObject works fine.

Please help me debug the issue.
thanks

Statistics: Posted by toxicjv — Mon Dec 13, 2021 7:59 pm


]]>
2021-12-11T05:00:51+08:00 2021-12-11T05:00:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100439#p100439 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]>

AgentSmithers wrote:
...
API Reference" for 2.2 and compared it to this below (version 2.0, look for 2.1 if you can, I couldn't find it online)
http://www.liot.io/media/liot_esp8266_e ... erence.pdf

In 2.2 I think if my memory serves me correctly they add a few new API commands for the 802.11 to adjust power savings to some extent. I would add those API's into your AP init code and toggle with those Params and see if it resolves your issue. If it does post back here so everyone else can see the result!


Last week in desperation, I did resort to looking for old documentation. I did not find any. Must have had the wrong search terms. So this document was a great find. Since your post, I have been scouring through the differences and trying various parameters. I would not have even tried things related to power settings. At this point, I'd try anything.

I think what bothers me the most is that no one else has this problem. I am beginning to think it has more to do with the Arduino implementation riding on top of the Espressif code base. I have tried...
  1. A totally NonOS version using VSCode/PlatformIO which is at 2.1.0. It works fine, showing the espconn_regist_disconcb() being called.
    good.png
  2. Unfortunately, I can't seem to find a way to make PlatformIO use a newer SDK. So, I have not found a way to test the above code with a true, unmodified SDK like 3.0+.
  3. I have tested it with the NonOS modified version in Arduino IDE that uses SDK 1.5 and again, it works fine the same as above.
  4. As soon as I move to the newer Arduino IDE versions that uses Espressif version 2.2 through 3.0 SDK, it serves up the web page five times and fails on the sixth request. The Browser shows a "This site can’t be reached The connection was reset."
    bad.png

Currently, I'm now focusing on what settings the Arduino version modifies that might cause this to fail. But again, I'm stuck with the lack of complaints on the Arduino forum. There differences seem to be that all their code is based on lwIP while the above code avoids even using that 3rd party library.

Thanks again!
VBR

Statistics: Posted by Inquisitor — Sat Dec 11, 2021 5:00 am


]]>
2021-12-09T17:14:21+08:00 2021-12-09T17:14:21+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75239&p=100434#p100434 <![CDATA[ESP8266 SDK • Re: How to configure SoftAP with WPA2-PSK(AES) in non os sdk]]>
maverickchongo wrote:
Hi,

Apple iOS is complaining about low security for my SoftAP which is using WPA2-PSK (TKIP), I believe it is because it is still using TKIP and I am trying to configure it with AES, the non-os-sdk documentation says that for the SoftAP AES is supported as well but I can't find any API to set it:

"ESP8266 softAP supports OPEN, WPAPSK, WPA2PSK; and encryption AUTO, TKIP, AES
are supported. But for the group key, only TKIP is supported."
Source:
https://www.espressif.com/sites/default ... nce_en.pdf

How can I configure it?

Ps. Migrating SDK is not an option for us right now.


This is what I use for my AccessPoint. I hope this points you in the correct direction

Code:

#ifndef __accesspoint__
#define __accesspoint__
//#define WifiMemorySpaceSector 0x51
#define WifiMemorySpace 0x63000//0x51000 //Also defined in station.h, make sure they match!

struct Customflashconfig APFlashStationConf;

bool ICACHE_FLASH_ATTR reset_accessPoint()
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   struct Customflashconfig Tempconfig;
   Tempconfig.programmed=0;
   SpiFlashOpResult SpiReturn = spi_flash_write(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&Tempconfig,sizeof(Tempconfig));
   if (SpiReturn == SPI_FLASH_RESULT_OK)
   {
      os_printf("Accesspoint programmed=0\r\n");
   }
   else
   {
      os_printf("Failed to reset Accesspoint\r\n");
   }
}

bool ICACHE_FLASH_ATTR isset_accessPoint()
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   struct softap_config softapConfig;
   spi_flash_read(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&APFlashStationConf,sizeof(APFlashStationConf));
   if(APFlashStationConf.programmed==1)
   {
      return true;
   }
   else
   {
      return false;
   }
}
/*
typedef enum _auth_mode {
 AUTH_OPEN = 0,
 AUTH_WEP,
 AUTH_WPA_PSK,
 AUTH_WPA2_PSK,
 AUTH_WPA_WPA2_PSK
} AUTH_MODE;
*/

void ICACHE_FLASH_ATTR set_accessPoint(char * LSSID, char * LPassword, uint8 Lssid_len, AUTH_MODE Lauthmode, uint8 Lchannel, uint8 Lssid_hidden, uint8 Lmax_connection, uint16 Lbeacon_interval, char * LReserved)
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   struct Customflashconfig Tempconfig;
   os_memcpy(&Tempconfig.ssid, LSSID, 32);
     os_memcpy(&Tempconfig.password, LPassword, 64);
   Tempconfig.ssid_len=os_strlen(LSSID);
   Tempconfig.authmode=Lauthmode;
   Tempconfig.ssid_hidden=Lchannel;
   Tempconfig.max_connection=Lmax_connection;
   Tempconfig.beacon_interval=Lbeacon_interval;
   wifi_softap_set_config(&Tempconfig);
   
   Tempconfig.programmed=1;
   //SpiFlashOpResult SpiReturn = spi_flash_erase_sector(WifiMemorySpaceSector);
   SpiFlashOpResult SpiReturn = spi_flash_erase_sector(WifiMemorySpace/SPI_FLASH_SEC_SIZE);
   if (SpiReturn == SPI_FLASH_RESULT_OK)
   {
      os_printf("SPI Flash Erase OK\r\n");
   }
   SpiReturn = spi_flash_write(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&Tempconfig,sizeof(Tempconfig));
   if (SpiReturn == SPI_FLASH_RESULT_OK)
   {
      os_printf("SPI Flash Write OK\r\n");
   }
   os_printf("ssid: \"%s\"\npw: \"%s\"\nProgrammed: %d\r\n",Tempconfig.ssid,Tempconfig.password,Tempconfig.programmed);
}

void ICACHE_FLASH_ATTR reload_accesspoint()
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   unload_accesspoint();
   init_accesspoint();
}

void ICACHE_FLASH_ATTR unload_accesspoint()
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   os_printf("[%s] wifi_get_opmode() = %d\r\n", __func__, wifi_get_opmode());
   if ((wifi_get_opmode() & 2) == 2)
   {
      wifi_set_opmode_current(wifi_get_opmode() & ~2);
      os_printf("AccessPoint Disabled wifi_get_opmode() = %d\r\n", wifi_get_opmode());
   }
}

void dhcps_lease_test(void)
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   struct   ip_info   info;
   wifi_softap_dhcps_stop();
   IP4_ADDR(&info.ip, 192, 168, 1, 1);
   IP4_ADDR(&info.gw, 192, 168, 1, 1);
   IP4_ADDR(&info.netmask, 255, 255, 255, 0);
   wifi_set_ip_info(SOFTAP_IF, &info);
   wifi_softap_dhcps_start();
   struct dhcps_lease dhcp_lease;
   IP4_ADDR(&dhcp_lease.start_ip, 192, 168, 1, 100);
   IP4_ADDR(&dhcp_lease.end_ip, 192, 168, 1, 105);
   wifi_softap_set_dhcps_lease(&dhcp_lease);
}


void ICACHE_FLASH_ATTR init_accesspoint(char * password, uint8 maxconnections)
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);
   //Need to implement APSSID And Password
   if ((wifi_get_opmode() & 2) != 2)
   {
      os_printf("Loading AccessPoint %d -> %d\r\n", wifi_get_opmode(), (wifi_get_opmode() | 2));
      
      wifi_set_opmode_current(wifi_get_opmode() | 2);

      dhcps_lease_test();

      os_printf("AccessPoint Loaded %d\r\n", wifi_get_opmode());

      struct softap_config softapConfig;
      spi_flash_read(WifiMemorySpace+sizeof(APFlashStationConf),(uint32 *)&APFlashStationConf,sizeof(APFlashStationConf));   
      APFlashStationConf.ssid[31]=0;
      APFlashStationConf.password[63]=0;
      //wifi_set_opmode_current(WifiOpMode); //Need to add this to turn on AP
      if(APFlashStationConf.programmed==1)
      {
         os_printf("Saved Information Found for AP!!\r\nssid: \"%s\"\npw: \"%s\"\n SizeOf(APFlashStationConf) = %d\r\n", APFlashStationConf.ssid, APFlashStationConf.password, sizeof(APFlashStationConf));
         os_memcpy(&softapConfig.ssid, APFlashStationConf.ssid, 32);
           os_memcpy(&softapConfig.password, APFlashStationConf.password, 64);
         softapConfig.ssid_len=APFlashStationConf.ssid_len;
         softapConfig.authmode=APFlashStationConf.authmode;
         softapConfig.ssid_hidden=APFlashStationConf.ssid_hidden;
         softapConfig.max_connection=APFlashStationConf.max_connection;
         softapConfig.beacon_interval=APFlashStationConf.beacon_interval;
         wifi_softap_set_config(&softapConfig);
      }
      else
      {
         os_printf("Saved Information Not Found for AP, Using Defaults!!\r\n");
         //Set AP Settings
         char APssid[32] = "ESP ";
         char MACADDR[6];
         wifi_get_macaddr(SOFTAP_IF, MACADDR);
         char MACADDRFormatted[12];
         os_sprintf(MACADDRFormatted,"%02x%02x%02x%02x%02x%02x", MACADDR[0], MACADDR[1], MACADDR[2], MACADDR[3], MACADDR[4], MACADDR[5]);
         strcat(APssid, MACADDRFormatted);
         //strcat(APssid, MAC2STR(bss_link->bssid))
         //char APpassword[64] = "01234567"; //This should be defined by a function argument!!
         char APpassword[64] = {0};
         
         if (password != NULL)
         {
            softapConfig.authmode=AUTH_WPA_WPA2_PSK;
            os_printf("Copying AP Password: %s\r\n", password);
            os_strcpy(APpassword, password);
         }
         else
         {
            softapConfig.authmode=AUTH_OPEN;
            os_printf("No AP Password specificied, Leaving AP Open\r\n");
         }
         
         os_memcpy(&softapConfig.ssid, APssid, 32);
         //os_memcpy(&softapConfig.ssid, "bibo", 32);
           os_memcpy(&softapConfig.password, APpassword, 64);
         softapConfig.ssid_len=0;
         
         softapConfig.ssid_hidden=0;
         softapConfig.max_connection=maxconnections;
         softapConfig.beacon_interval=100;
         wifi_softap_set_config(&softapConfig);
         os_printf("Access Point Up - %s!!\r\n", &softapConfig.ssid); //APssid
      }
   }
   else
   {
      os_printf("AP Already Loaded");
   }
}
#endif

Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 5:14 pm


]]>
2021-12-09T17:09:49+08:00 2021-12-09T17:09:49+08:00 https://bbs.espressif.com:443/viewtopic.php?t=9178&p=100433#p100433 <![CDATA[ESP8266 SDK • Re: ESP8266 2MB + OTA]]>

Code:

#ifndef __httpPostFota__
#define __httpPostFota__

#include <upgrade.h>

//#define UPGRADE_DEBUG

#ifdef UPGRADE_DEBUG
#define UPGRADE_DBG os_printf
#else
#define UPGRADE_DBG
#endif

#define FOTAHTMLSIZE 8192

typedef void (*FOTAWebRecvFunctionCallback)(void *arg, char *pusrdata, unsigned short length);
FOTAWebRecvFunctionCallback FOTAWebRecvCallBack;
unsigned char * FOTAFormatedHTMLPageWithHttpHeader;
LOCAL struct espconn FOTAWebServerSocket;

static char *FOTAmsg_espconn_state[] =
{
      "NONE",
      "WAIT",
      "LISTEN",
      "CONNECT",
      "WRITE",
      "READ",
      "CLOSE"
};

char * FOTAHttpHeader = "HTTP/1.1 200 OK\r\nContent-Length: %d\r\nConnection: close\r\n\r\n";
LOCAL void ICACHE_FLASH_ATTR FOTAHttpSendWithHeader(struct espconn * WifiScanConfigConnection, unsigned char * LFormatedHTMLPage) //This may be able to be merged
{
   FOTAFormatedHTMLPageWithHttpHeader = (unsigned char*)os_zalloc(FOTAHTMLSIZE);
   if (FOTAFormatedHTMLPageWithHttpHeader == 0x0)
   {
      os_printf("[%s][%s][%d] - Unable to Alloc memory, exiting\r\n", __FILE__ ,__func__, __LINE__);
      return;
   }
   os_printf("Attaching header and sending\r\n");
   os_memset(FOTAFormatedHTMLPageWithHttpHeader, 0, FOTAHTMLSIZE);
   os_printf("Attaching header and sending\r\n");
   os_sprintf(FOTAFormatedHTMLPageWithHttpHeader, FOTAHttpHeader, os_strlen(LFormatedHTMLPage));
   os_printf("Attaching header and sending\r\n");
   os_strcat(FOTAFormatedHTMLPageWithHttpHeader, LFormatedHTMLPage);
   os_printf("Attaching header and sending\r\n");
   espconn_send(WifiScanConfigConnection, (uint8*)FOTAFormatedHTMLPageWithHttpHeader, os_strlen(FOTAFormatedHTMLPageWithHttpHeader));
   os_printf("HTTP Response sent bytes: %d\r\n", os_strlen(LFormatedHTMLPage));
   os_free(FOTAFormatedHTMLPageWithHttpHeader);
}

LOCAL os_timer_t Firmware_Timer;

static ETSTimer http2spi_flash_reboot_timer;

LOCAL char* ICACHE_FLASH_ATTR http2spi_checkheader(void *buf, int which)
{
   os_printf("[%s]\r\n", __func__);
   uint8_t *cd = (uint8_t *)buf;
   uint32_t *buf32 = buf;
   os_printf("OTA hdr %p: %08lX %08lX %08lX %08lX\n", buf,
   (long unsigned int)buf32[0],
   (long unsigned int)buf32[1],
   (long unsigned int)buf32[2],
   (long unsigned int)buf32[3]);
   if (cd[0] != 0xEA) return "IROM magic missing";
   if (cd[1] != 4 || cd[2] > 3 || (cd[3]>>4) > 6) return "bad flash header";
   //if (cd[3] < 3 && cd[3] != which) return "Wrong partition binary";
   if (((uint16_t *)buf)[3] != 0x4010) return "Invalid entry addr";
   if (((uint32_t *)buf)[2] != 0) return "Invalid start offset";
   return NULL;
}

long gstaticContentLength = 0; //This keeps the Content length in mem for the life of the transactions
long gContentLength = 0; //This is a countdown of Binary Data left to transmit to the client, this includes the Mime header data! Anything after first CRLFCRLF basiclly
uint16 RemotePortsOpenedInDownload = 0; //Only One port at a time can upload a firmware
bool HeaderRead = false;
int dataparts = 0; //This track the file transfer progress in packets

char FOTAdatabuffer[4] = {0}; //Rolling Ring Buffer
uint32 FOTAdatabufferindex = 0;

uint32_t FOTAburnto = 0x0;
uint32_t gOffset = 0x0;

LOCAL void ICACHE_FLASH_ATTR FOTAWebServerConn_recv_callback(void *arg, char *pusrdata, unsigned short length)
{
   bool unloadafter = false;
   struct espconn * FOTApespconn = (struct espconn *) arg;
   //os_printf("[%s] Client recv'ed from port: ", __func__);
   /*
   uint16_printf(FOTApespconn->proto.tcp->remote_port);   
   os_printf(" - ");
   uint16_printf(FOTApespconn->proto.tcp->local_port);   
   /*
   //os_printf(FOTApespconn->proto.tcp->client_port);
   //os_printf(FOTApespconn->tcp.client_port); //How to identify which socket is triggering this WebServerCallback. What if multiple clients are connected?
   os_printf("\r\n");

   /*
   char* getpost = strstr(pusrdata, "POST /upload");
   if (getpost != NULL)
   {
      
   }
   */

   if (RemotePortsOpenedInDownload == FOTApespconn->proto.tcp->remote_port)
   {
      //os_printf("Incoming file data gcontentlength = %u lCurrentIncomming: %u\r\n", gContentLength, length);
      
      if (dataparts <= 6)
      {
         dataparts++;
         //os_printf(pusrdata);
         //hex_printf(pusrdata, length);
         //os_printf("\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r\n");
      }
      char * Ptr = pusrdata;
      if (HeaderRead == false) //Move past the header
      {
         os_printf("Header removed\r\n");
         while (!strstarts(Ptr, "\r\n\r\n"))
         {
            Ptr++; //Increment Ptr
            //lengthleft--;
         }
         while (*Ptr == '\n' || *Ptr == '\r')
         {
            Ptr++; //Increment Ptr
            //lengthleft--;
         }

         os_printf("%u - %u!\r\n", Ptr, pusrdata);
         os_printf("Before %u!\r\n", length);
         length -= Ptr-pusrdata;
         gContentLength -= length;
         os_printf("After removing headers %u! Updating gContentLength(%u)\r\n", length, gContentLength);
         HeaderRead = true;
      }
      //os_printf("---");
      //os_printf(Ptr);
      //os_printf("gcontentlength(%d) - thispacketLength(%d) = %d remainding, DbufferIndex(%u)\r\n", gContentLength, length, (gContentLength - length), FOTAdatabufferindex);      

      unsigned short i,ii = 0;
      for (i=0; i<length; i++)
      {
         /*
         if (i == 0)
         {
            for (ii=0; ii<10; ii++)
            {
               os_printf("%x ", *(Ptr + ii));
            }
            os_printf("\r\n");
         }
         */

         if (gContentLength < 3000)
         {
            if (*(Ptr + i) == '-' && *(Ptr + i + 1) == '-' && *(Ptr + i + 2) == '-' && *(Ptr + i + 3) == '-' && *(Ptr + i + 4) == '-' && *(Ptr + i + 5) == '-')
            {
               //os_printf("Found Hyphens EOF -\r\n");
               char * ResponseToSend = "<!DOCTYPE html><html><head><meta http-equiv=\"refresh\" content=\"3;URL='/'\"></head><body>File Uploaded</body></html>";
               FOTAHttpSendWithHeader(FOTApespconn, ResponseToSend);   
               system_update_cpu_freq(80);
               return;
            }
         }

         //os_printf("i=%d", i);
         system_soft_wdt_feed();
         FOTAdatabuffer[FOTAdatabufferindex%4] = *(Ptr + i);
         FOTAdatabufferindex++;

         if (FOTAdatabufferindex%4 == 0)
         {
            system_soft_wdt_feed();
            if (spi_flash_write(gOffset, (uint32 *)&FOTAdatabuffer, 4) == SPI_FLASH_RESULT_OK)
            {
               if (gOffset % 0x10000 == 0)
               {
                  os_printf("%u of packet %u - %x %x %x %x Writen to offset 0x%x bin=0x%x bytesleft=%u!\r\n", i, length, FOTAdatabuffer[0], FOTAdatabuffer[1], FOTAdatabuffer[2], FOTAdatabuffer[3], gOffset, gOffset-FOTAburnto, gContentLength-FOTAdatabufferindex);
               }

               if (gstaticContentLength - FOTAdatabufferindex < 0x30)
               {
                  //os_printf("%u of packet %u - %x %x %x %x Writen to offset 0x%x bin=0x%x bytesleft=%u!\r\n", i, length, databuffer[0], databuffer[1], databuffer[2], databuffer[3], gOffset, gOffset-FOTAburnto, gContentLength-FOTAdatabufferindex);
               }
               
               if (FOTAdatabufferindex > gContentLength - 0x10 || FOTAdatabufferindex < 0x10 )// || i < 0x100 //This does for every packet
               {
                  //os_printf("%u of packet %u - %x %x %x %x Writen to offset 0x%x bin=0x%x bytesleft=%u\r\n", i, length, databuffer[0], databuffer[1], databuffer[2], databuffer[3], gOffset, gOffset-FOTAburnto, gContentLength-FOTAdatabufferindex);
               }
               
               gOffset += 4;
            }
            else
            {
               os_printf("failed writing length:%d\r\n", length);
            }
         }

         if (FOTAdatabufferindex > 60)
         {
            //return;
         }
      }

      gContentLength -= length;

      //os_printf("Packet Processed ContentLength(%u) of packet FOTAdatabufferindex(%u) Difference(%u)\r\n", gstaticContentLength, FOTAdatabufferindex, (gstaticContentLength - FOTAdatabufferindex));

      if (gContentLength == 0)
      {
         //espconn_disconnect(&FOTAWebServerSocket); //Webservers don't close sockets, clients do
         char * ResponseToSend = "<!DOCTYPE html><html><body>File Uploaded</body></html>";
         FOTAHttpSendWithHeader(FOTApespconn, ResponseToSend);   
      }
   }

   if (strstr(pusrdata, "POST /upload") != NULL)
   {
      system_update_cpu_freq(160);
      dataparts = 1;
      RemotePortsOpenedInDownload = FOTApespconn->proto.tcp->remote_port;
      os_printf(pusrdata);
      int index = 0;
      char * Ptr = pusrdata;
      
      while (!strstarts(Ptr, "Content-Length: "))
      {
         Ptr++; //Increment Potr
      }
      while (*Ptr != ' ')
      {
         Ptr++; //Increment Potr
      }
      Ptr++; //Increment to Content String

      char ContentLength[8] = {0};
      index = 0;
      while (*Ptr != '\r' && *Ptr != '\n')
      {
         ContentLength[index] = *Ptr;
         index++;
         Ptr++; //Increment Potr
      }
      os_printf(ContentLength);

      gContentLength = atoi(ContentLength);
      
      gstaticContentLength = gContentLength;
      
      Ptr = pusrdata; //Reset PTR
      while (!strstarts(Ptr, "Content-Type: multipart/form-data; boundary="))
      {
         Ptr++; //Increment Potr
      }
            
      while (*Ptr != '=')
      {
         Ptr++; //Increment Potr
      }
            
      Ptr++; //Increment to Content String
            
      char Boundary[64] = {0};      
            
      index = 0;
      
      while (*Ptr != '\r' && *Ptr != '\n')
      {
         Boundary[index] = *Ptr;
         index++;
         Ptr++; //Increment Ptr
         //os_printf("%u\r\n", Ptr);
      }
      Boundary[index] = 0; //This may not be needed by the way I declared boundary with = {0}
      os_printf(Boundary);
      os_printf("\r\n");

      
      while (!strstarts(Ptr, "\r\n\r\n"))
      {
         Ptr++; //Increment Ptr
         //os_printf("%u\r\n", Ptr);
      }
      Ptr += 4;
      
      os_printf("HEAD Content Length of file: %d\r\n", gContentLength); //Start erasing the flash at a given address

      if(system_upgrade_userbin_check() == 0)
      {
         FOTAburnto = 0x101000;
      }
      else
      {
         FOTAburnto = 0x1000;
      }
      gOffset = FOTAburnto;

      uint32_t poffset = 0x0;

      
      for (poffset=0x0; gContentLength-poffset>0; poffset++)
      {
         if ((FOTAburnto+poffset) % SPI_FLASH_SEC_SIZE == 0)
         {
            //os_printf("Erasing 0x%x\r\n", FOTAburnto+poffset);
            spi_flash_erase_sector((FOTAburnto+poffset)/SPI_FLASH_SEC_SIZE); //Doing it here may not be fast enough.
         }
      }
      
   
      HeaderRead = false; //SetHeader back to false to prep for incoming header to skip
      /*      
      os_printf("%u\r\n", Ptr);
      os_printf("%u\r\n", pusrdata);
      os_printf("%u\r\n", (Ptr-pusrdata));
      //os_printf("%u\r\n", (pusrdata-Ptr)); //This loops around the interger value giving a result back in the 4millons
      os_printf("Length: %u\r\n", length);
      os_printf("Logic:%u\r\n", length-(Ptr-pusrdata));
      //os_printf("%u\r\n", (&Ptr-&pusrdata)); //We don't really care about the addresses
      //os_printf("%u\r\n", (&pusrdata-&Ptr));
      */
      if(length-(Ptr-pusrdata) > 0) //It's possible data can be fragmented from the first packet
      {
         unsigned short packetlen = length-(Ptr-pusrdata);
         os_printf("Calling first packet remainding len:%u of %u\r\n", packetlen, length);
         FOTAWebServerConn_recv_callback(arg, Ptr, packetlen);//This function normally dosn't get called by chrome being predictable during development, This may change later sadly if IE frags the packets differently
      }
      else
      {
         //This is not normally called.
      }

   }

   if (strstr(pusrdata, "GET /favicon.ico HTTP/1.1") != NULL) //Skip FavIcon request
   {
      espconn_disconnect(&FOTAWebServerSocket);
      return;
   }

   if (strstr(pusrdata, "GET / HTTP/1.1") != NULL) //Display Config request
   {
      os_printf("[%s]\r\n", __func__);
      char * ResponseToSend = NULL;
      os_printf("[%s]s\r\n", __func__);
      if (system_get_userbin_addr() == 0x0)
      {
         os_printf("OTA Firmware is not detected, please load the OTA firmware\r\n");
         ResponseToSend = "<!DOCTYPE html><html><body>OTA Firmware is not detected, please load the OTA firmware</body></html>";
      }
      else
      {
         if(system_upgrade_userbin_check() == 0)
         {
            ResponseToSend = "<!DOCTYPE html><html><body><form action=\"upload\" method=\"post\" enctype=\"multipart/form-data\">Select image to upload to address 0x101000:<input type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\"><input type=\"submit\" value=\"Upload Image\" name=\"submit\"></form></body></html>";
         }
         else
         {
            ResponseToSend = "<!DOCTYPE html><html><body><form action=\"upload\" method=\"post\" enctype=\"multipart/form-data\">Select image to upload to address 0x1000:<input type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\"><input type=\"submit\" value=\"Upload Image\" name=\"submit\"></form></body></html>";
         }
      }
      os_printf("[%s]s1\r\n", __func__);
      //espconn_send(FOTApespconn, ResponseToSend, os_strlen(ResponseToSend));
      FOTAHttpSendWithHeader(FOTApespconn, ResponseToSend);
      os_printf("[%s]s2\r\n", __func__);
   }
}

LOCAL void ICACHE_FLASH_ATTR FOTAWebServerConn_connect_callback(void *arg)
{
   os_printf("[%s] Client Connected from port: ", __func__);
   struct espconn * FOTApespconn = (struct espconn *) arg;
   uint16_printf(FOTApespconn->proto.tcp->remote_port);   
   os_printf(" - ");
   uint16_printf(FOTApespconn->proto.tcp->local_port);   
   os_printf("\r\n");
   return;
   remot_info *premot = NULL;
   uint8 reter = espconn_get_connection_info(FOTApespconn,&premot,0);
   if (reter == ESPCONN_OK)
   {
      if(FOTApespconn->link_cnt)
      {
         os_printf("EspConn %u TCP connections:\r\n", FOTApespconn->link_cnt);
         int i = 0;
         while(i < FOTApespconn->link_cnt)
         {
            os_printf("%d) " IPSTR ":%u %s\r\n", i,  IP2STR(premot[i].remote_ip), premot[i].remote_port, FOTAmsg_espconn_state[premot[i].state] );
            i++;
         };
      }
   }
   else
   {
      os_printf("EspConn getting TCP connections failed: %d\r\n", reter);
   }
}

static ETSTimer http2spi_flash_reboot_timer;
void ICACHE_FLASH_ATTR FOTAWebServerConn_disconnect_callback(void *arg)
{
   os_printf("[%s] Client Disconnected from port: ", __func__);
   struct espconn * FOTApespconn = (struct espconn *) arg;
   uint16_printf(FOTApespconn->proto.tcp->remote_port);   
   os_printf(" - ");
   uint16_printf(FOTApespconn->proto.tcp->local_port);   
   os_printf("\r\n");

   if (RemotePortsOpenedInDownload == FOTApespconn->proto.tcp->remote_port)
   {
      os_printf("Last Status: gcontentlength(%d), DbufferIndex(%u)\r\n", gContentLength, FOTAdatabufferindex);

      uint32 Http2SPI_buf[8];
      spi_flash_read(FOTAburnto, Http2SPI_buf, sizeof(Http2SPI_buf));
      uint8 id = system_upgrade_userbin_check();
      char *err = http2spi_checkheader(Http2SPI_buf, 1-id);
      if (err != NULL) {
         os_printf("OTA Not a bootable bin, %s\n HTTP to SPI completed.\r\n", err);
         return -1;
      }

      os_printf("Reboot needed, rebooting...");
      // Schedule a reboot
      system_upgrade_flag_set(UPGRADE_FLAG_FINISH);
      os_timer_disarm(&http2spi_flash_reboot_timer);
      os_timer_setfn(&http2spi_flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL);
      os_timer_arm(&http2spi_flash_reboot_timer, 2000, 1);
   }
}

void ICACHE_FLASH_ATTR FOTAWebServerConn_sent_callback(void *arg)
{
   os_printf("[%s] Data Sent\r\n", __func__);
   espconn_disconnect(&FOTAWebServerSocket);
}

void ICACHE_FLASH_ATTR init_FOTAwebserver(uint16 port, void * LFOTAWebRecvCallBack(void *arg, char *pusrdata, unsigned short length)) //LFOTAWebRecvCallBack may need to point to the next pointer of the function and not the parent recv function
{
   os_printf("[%s]\r\n", __func__);
   //FOTAFormatedHTMLPageWithHttpHeader = (unsigned char*)os_zalloc(FOTAHTMLSIZE); //Never alloc on init. only when the far is used then free it asap!

   if (LFOTAWebRecvCallBack != NULL)
   {
      os_printf("Setting Callback for WebServer\r\n");
      FOTAWebRecvCallBack = LFOTAWebRecvCallBack;
   }
       FOTAWebServerSocket.type = ESPCONN_TCP;
       FOTAWebServerSocket.state = ESPCONN_NONE;
       FOTAWebServerSocket.proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
      if (FOTAWebServerSocket.proto.tcp == 0x0)
      {
         os_printf("[%s][%s][%d] - Unable to Alloc memory, exiting\r\n", __FILE__ ,__func__, __LINE__);
         return;
      }
       FOTAWebServerSocket.proto.tcp->local_port = port;  // ESP8266 tcp port
       espconn_accept(&FOTAWebServerSocket);   // create tcp
   espconn_regist_connectcb(&FOTAWebServerSocket, FOTAWebServerConn_connect_callback);
       espconn_regist_recvcb(&FOTAWebServerSocket, FOTAWebServerConn_recv_callback); // register a tcp packet receiving callback
   espconn_regist_sentcb(&FOTAWebServerSocket, FOTAWebServerConn_sent_callback);
   espconn_regist_disconcb(&FOTAWebServerSocket, FOTAWebServerConn_disconnect_callback);
}

#endif



You can run the server with something like this
init_FOTAwebserver(9999, NULL);

Once ran, browse to the ESP's ip on that port and you should get prompted with a button to upload your OTA file. From what I recall I tested and valided this code a few years back.

Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 5:09 pm


]]>
2021-12-09T16:59:51+08:00 2021-12-09T16:59:51+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75264&p=100432#p100432 <![CDATA[ESP8266 SDK • Re: Broken Code with SDK 2.2 and newer]]> API Reference" for 2.2 and compared it to this below (version 2.0, look for 2.1 if you can, I couldn't find it online)
http://www.liot.io/media/liot_esp8266_e ... erence.pdf

In 2.2 I think if my memory serves me correctly they add a few new API commands for the 802.11 to adjust power savings to some extent. I would add those API's into your AP init code and toggle with those Params and see if it resolves your issue. If it does post back here so everyone else can see the result!

Also, do a full memory purge with esp_tool erase and reflash your 'esp_init_data_default' files to make sure everything is clean.

That should get you back and running.

Good Luck!

Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 4:59 pm


]]>
2021-12-09T16:42:09+08:00 2021-12-09T16:42:09+08:00 https://bbs.espressif.com:443/viewtopic.php?t=75263&p=100431#p100431 <![CDATA[ESP8266 SDK • Re: ESP8266_NONOS_SDK-2.2.0,How to achieve sleep and button wake up]]> I am unsure if I understand your questions correctly but I'll give this one a go.

If I understand your questions correctly you want to act on a button press (or multiple on waking).
If you can provide a step by step example of what you are looking for I can indeed help :)

Here are some pieces anyways.

The first Snippet is how to read and write a counter to your SPI memory, this will survive any powerloss/reboot you have.
The second goes in your startup / main code that detects the reason for booting, Upon botting read the SPI, then sleep for about a second or so, As your pressing the button you can inc the SPI index value to +1 then after your sleep cycle on boot act on it or another method.

I personally use the following method below to have the chip detect that its in a crashing loop then to kick off a debug safe mode to report in if that were to ever happen so I have a chance for recover with FOTA.

I hope this points you in the correct direction, if not Ill be back this week and will watch for your reply.

Code:

typedef   struct   {
   uint32   magic   ;
   uint32   rst_count;
   uint64  Reserved;
}RTC_RST_STRUCT;

bool ICACHE_FLASH_ATTR StoreRSTCount(uint32 Count)
{
   os_printf("[%s][%s][%d] - creating with: %u\r\n", __FILE__ ,__func__, __LINE__, Count);   
   //system_rtc_mem_write(68, &Count, sizeof(Count));      
   RTC_RST_STRUCT rtc_rst;
   rtc_rst.magic   = 0xDEADBEEF;
   rtc_rst.rst_count = Count;
   system_rtc_mem_write(72, &rtc_rst, sizeof(rtc_rst));      
}

uint32_t ICACHE_FLASH_ATTR GetRSTCount(void)
{
   os_printf("[%s][%s][%d]\r\n", __FILE__ ,__func__, __LINE__);   
   uint32 count;
   //system_rtc_mem_read(68,   &count, sizeof(count));
   RTC_RST_STRUCT rtc_rst;
   system_rtc_mem_read(72,   &rtc_rst, sizeof(rtc_rst));
   if(rtc_rst.magic==0xDEADBEEF)
   {
      os_printf("[%s][%s][%d] - GET GetRSTCount %u\r\n", __FILE__ ,__func__, __LINE__, rtc_rst.rst_count);
      return rtc_rst.rst_count;
   }
   else
   {
      return NULL;
   }
}


Code:

struct rst_info *rtc_info = system_get_rst_info();
   os_printf("reset reason: %x\n",   rtc_info->reason);

   switch (rtc_info->reason)
   {
      case REASON_DEFAULT_RST:
         os_printf("REASON_DEFAULT_RST\r\n");
      break;
      case REASON_WDT_RST:
         os_printf("REASON_WDT_RST\r\n");
      break;
      case REASON_SOFT_WDT_RST:
         os_printf("REASON_SOFT_WDT_RST\r\n");
      break;
      case REASON_SOFT_RESTART:
         os_printf("REASON_SOFT_RESTART\r\n");
      break;
      case REASON_EXCEPTION_RST:
         os_printf("REASON_EXCEPTION_RST (%d)\r\n", rtc_info->exccause); //Add recovery code logic here
         uint32_t EXC = GetEXCCount();
         if (EXC == NULL)
         {
            StoreEXCCount(1);
         }
         else
         {
            EXC++;
            StoreEXCCount(EXC);
         }
         //Add some Call back register here! =)
      break;
      case REASON_DEEP_SLEEP_AWAKE:
         os_printf("REASON_DEEP_SLEEP_AWAKE\r\n");
      break;
      case REASON_EXT_SYS_RST:
         os_printf("REASON_EXT_SYS_RST - Button Press\r\n"); //When freshly Flashed we get this or a Hard button Reset
         common_RSTCount = GetRSTCount();
         if (common_RSTCount == NULL)
         {
            os_printf("common_RSTCount == NULL / ZERO\r\n");
            StoreRSTCount(1);
         }
         else if(common_RSTCount == 9)
         {
            os_printf("common_RSTCount == %u, setting up WiFi\r\n", common_RSTCount);
         }
         else
         {
            os_printf("common_RSTCount == %u\r\n", common_RSTCount);
            common_RSTCount++;
            StoreRSTCount(common_RSTCount);
         }
         delay_5seconds(); //Give the user five seconds to reset once more to higher the count!
         //Add some Call back register here! =)
         if(common_RSTCount >= 3 || false) //true for debugging code
         {
            os_printf("Entering Debug Mode");
            FlickerLED(2, 30);
            FlickerLED(2, 60);
            FlickerLED(2, 30);
            FlickerLED(2, 60);
            //Add some debug code here
            spi_flash_read(WifiMemorySpace,(uint32 *)&GlobalFlashConfig,sizeof(GlobalFlashConfig));
            uart_init(BIT_RATE_115200, BIT_RATE_115200, &UartReceive); //This only seems to be kicked off via the COM-USB onboard, Not the TX/RX port
            InDebugMode = true;
         }
         StoreRSTCount(0); //Reset value to zero
      break;
      default:
         os_printf("Some other REASON?!\r\n");
      break;
   }

   if (rtc_info->reason == REASON_WDT_RST || rtc_info->reason == REASON_EXCEPTION_RST || rtc_info->reason == REASON_SOFT_WDT_RST)
   {
      os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n", rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);//debug   garbled   output.
      halt();
   }   

Statistics: Posted by AgentSmithers — Thu Dec 09, 2021 4:42 pm


]]>