1. Users can establish their own cloud server, or use the cloud server provided by
Espressif.
2. Upload the new firmware to the cloud server.
3. Descriptions of the codes are listed below:
Connect the ESP8266 module to the AP (for details of this process users can refer to
previous examples). Then check if the ESP8266 Station can get the IP address through
function upgrade_task.
Wi-Fi_get_ip_info(STATION_IF,&ipconfig);
/*checktheIPaddressornetconnectionstate*/
while(ipconfig.ip.addr==0){
vTaskDelay(1000/portTICK_RATE_MS);
Wi-Fi_get_ip_info(STATION_IF,&ipconfig);
}
• When the IP address is obtained by ESP8266, the module will be connected to the
cloud server. (Users can refer to previous examples of socket programming).
• system_upgrade_flag_set: sets a flag to indicate the upgrade status.
- UPGRADE_FLAG_IDLE: idle.
- UPGRADE_FLAG_START: starts the upgrade.
- UPGRADE_FLAG_FINISH: finishes downloading new firmware from the cloud server.
• system_upgrade_userbin_check: checks the user binary file that the system is
running. If the system is running user1.bin, then user2.bin will be downloaded; if the
systems is running user2.bin, then user1.bin will be downloaded.
system_upgrade_init();
system_upgrade_flag_set(UPGRADE_FLAG_START);
• Send the downloading request to the server. After the upgraded firmware data is
received successfully, program it into the flash.
if(write(sta_socket,server->url,strlen(server->url)+1)<0){
……
}
while((recbytes=read(sta_socket,precv_buf,UPGRADE_DATA_SEG_LEN))>0){
⚠ Notice:
Erasing the flash memory is a slow process. Thus it may take longer time to erase a flash memory sector
while writing information into other sectors of the flash at the same time. Besides, the stability of the
network might also be affected. Consequently, it is suggested that users call function
spi_flash_erase_sector to erase sectors to be upgraded first; connect to the network, and download
the latest firmware from OTA server; then, call function spi_flash_write to write information into the
flash.