資源簡介
實現樂鑫esp8266的無線OTA升級,實現遠程在線升級固件。

代碼片段和文件信息
/******************************************************************************/
/*???????????????????????????????ESP8266?Family???????????????????????????????*/
/*???????????????????????????????????JiaXin???????????????????????????????????*/
/******************************************************************************/
#include?“osapi.h“
#include?“mem.h“
#include?“upgrade.h“
#include?“user_interface.h“
#include?“ota_update.h“
#include?“espconn.h“
struct?EspconnUpdateTransferData?{
////?請求參數?////
unsigned?short?remotePort;
char*?host;
char*?filename;
};
#define?INET_ADDRSTRLEN?18
////////////////////////////////////////////////////////////////////////////////
bool?ICACHE_FLASH_ATTR?getIpArray(char*?host?char?*server_ip)
{
if(NULL?==?server_ip)?{
return?false;
}
char?tmp[4];
char?*ptr?=?NULL;
char?*divStr?=?“.“;
int?i?=?0;
ptr?=?strtok(host?divStr);
while?(ptr?!=?NULL)?{
strncpy(tmp?ptr?strlen(ptr));
int?ip_int?=??atoi(tmp);
if?(ip_int?0?||?ip_int?>?255)?{
return?false;
}
server_ip[i]?=?ip_int;
ptr?=?strtok(NULL?divStr);
if(NULL?!=?ptr)?{
????++i;
}
}
if(i?!=?3)?{
return?false;
}
char?output[32];
os_sprintf(output?“getIpAddr():?“IPSTR“\r\n“?IP2STR(server_ip));
uart0_sendStr(output);
return?true;
}
void?ICACHE_FLASH_ATTR?getIpAddrString(ip_addr_t?*ipaddr?char?*ip)
{
memset(ip?0?INET_ADDRSTRLEN);
os_sprintf(ip?IPSTR?ip4_addr1(ipaddr)?ip4_addr2(ipaddr)?ip4_addr3(ipaddr)?ip4_addr4(ipaddr));
}
bool?ICACHE_FLASH_ATTR?http_parse_request_url(char?*URL?char?*host?int?hostSizechar?*filename?int?nameSize?unsigned?short?*port)?{
char?*PA;
char?*PB;
memset(host?0?hostSize);
memset(filename?0?nameSize);
*port?=?0;
if?(!(*URL)){
uart0_sendStr(“\r\n?-----?URL?return?-----??\r\n“);
return?false;
}
PA?=?URL;
if?(!strncmp(PA?“http://“?strlen(“http://“)))?{
PA?=?URL?+?strlen(“http://“);
}?else?if?(!strncmp(PA?“https://“?strlen(“https://“)))?{
PA?=?URL?+?strlen(“https://“);
}
PB?=?strchr(PA?‘/‘);
if?(PB)?{
uart0_sendStr(“\r\n?-----?PB=true?-----??\r\n“);
memcpy(host?PA?strlen(PA)?-?strlen(PB));
if?(PB?+?1)?{
memcpy(filename?PB?+?1?strlen(PB?-?1));
filename[strlen(PB)?-?1]?=?0;
}
host[strlen(PA)?-?strlen(PB)]?=?0;
//uart0_log(host);
}?else?{
uart0_sendStr(“\r\n?-----?PB=false?-----??\r\n“);
memcpy(host?PA?strlen(PA));
host[strlen(PA)]?=?0;
//uart0_log(host);
}
PA?=?strchr(host?‘:‘);
if?(PA){
*port?=?atoi(PA?+?1);
host[PA?-?host]?=?0;
}else{
*port?=?80;
}
char?buf[500];
os_sprintf(buf?“---PARSE?URL?host[%s]?filename[%s]?port[%u]\r\n“?host?filename?*port);
uart0_sendStr(buf);
return?true;
}
////////////////////////////////////////////////////////////////////////////////
void?ICACHE_FLASH_ATTR?freeTcpConn(struct?espconn?*pTcp_conn)
{
???if(NULL?!=?pTcp_conn)?{
???struct?EspconnUpdateTransferData?*?pData?=?pTcp_conn->reverse;
???if(NULL?!=?pData)?{
???????????if(NULL?!=?pData->filename)?{
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????8251??2018-10-10?11:25??ota_update.c
?????文件?????????663??2018-10-10?10:41??ota_update.h
?????目錄???????????0??2018-04-26?12:06??19_Esp8266_OTA_NONOS\
?????文件????????3719??2018-04-26?12:06??19_Esp8266_OTA_NONOS\.cproject
?????文件?????????798??2018-04-26?12:06??19_Esp8266_OTA_NONOS\.project
?????目錄???????????0??2018-04-26?12:06??19_Esp8266_OTA_NONOS\.settings\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\
?????目錄???????????0??2018-04-26?12:06??19_Esp8266_OTA_NONOS\app\.output\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\.output\eagle\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\.output\eagle\debug\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\.output\eagle\debug\bin\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\.output\eagle\debug\image\
?????文件??????337118??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\.output\eagle\debug\image\eagle.app.v6.out
?????文件????????3080??2018-02-06?04:45??19_Esp8266_OTA_NONOS\app\gen_misc.bat
?????文件????????3788??2018-02-06?04:45??19_Esp8266_OTA_NONOS\app\gen_misc.sh
?????目錄???????????0??2018-04-26?12:04??19_Esp8266_OTA_NONOS\app\include\
?????文件????????1296??2018-02-06?04:45??19_Esp8266_OTA_NONOS\app\include\user_config.h
?????文件????????2814??2018-02-06?04:45??19_Esp8266_OTA_NONOS\app\Makefile
?????目錄???????????0??2018-04-26?14:41??19_Esp8266_OTA_NONOS\app\user\
?????目錄???????????0??2018-04-26?12:06??19_Esp8266_OTA_NONOS\app\user\.output\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\debug\
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\debug\lib\
?????文件???????22956??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\debug\lib\libuser.a
?????目錄???????????0??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\debug\obj\
?????文件????????1317??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\debug\obj\user_main.d
?????文件???????22692??2018-04-27?11:38??19_Esp8266_OTA_NONOS\app\user\.output\eagle\debug\obj\user_main.o
?????文件????????1477??2018-02-06?04:45??19_Esp8266_OTA_NONOS\app\user\Makefile
?????文件????????7560??2018-04-27?11:37??19_Esp8266_OTA_NONOS\app\user\user_main.c
?????目錄???????????0??2018-04-26?14:49??19_Esp8266_OTA_NONOS\bin\
?????目錄???????????0??2018-02-06?04:45??19_Esp8266_OTA_NONOS\bin\at\
............此處省略114個文件信息
- 上一篇:PowerBI視覺對象75個
- 下一篇:佳藍客戶端在線生成平臺
評論
共有 條評論