ESP8266如何使用自己的云服务器进行云端升级 (OTA教程)


本人测试分别使用远程服务器和本地服务器都可以实现OTA无线升级,升级后的程序稳定运行
资源截图
代码片段和文件信息

/******************************************************************************
 * Copyright 2015-2018 Espressif Systems (Wuxi)
 *
 * Description: entry file of user application
 *
 * Modification history:
 *     2015/3/06 v1.0 create this file.
*******************************************************************************/
#include “c_types.h“
#include “user_interface.h“
#include “espconn.h“
#include “mem.h“
#include “osapi.h“
#include “upgrade.h“
#include “hsuser.h“

#ifdef OTA_UPGRADE_SUPPORT 

void ICACHE_FLASH_ATTR ota_finished_callback(void *arg)
{
struct upgrade_server_info *update = arg;
if (update->upgrade_flag == true)
{
os_printf(“[OTA]success; rebooting!
“);
system_upgrade_reboot();
}
else
{
os_printf(“[OTA]failed!
“);
}

os_free(update->pespconn);
os_free(update->url);
os_free(update);
}


void ICACHE_FLASH_ATTR ota_start_Upgrade(uint8_t serverVersion const char *server_ip uint16_t port const char *path)
{
const char* file;
uint8_t userBin = system_upgrade_userbin_check();
switch (userBin)
{
case UPGRADE_FW_BIN1: file = “user2.4096.new.4.bin“; break; //  user2.bin
case UPGRADE_FW_BIN2: file = “user1.4096.new.4.bin“; break; // user1.bin
default:
os_printf(“[OTA]Invalid userbin number!
“);
return;
}

uint16_t version=1;
if (serverVersion <= version)
{
os_printf(“[OTA]No update. Server version:%d local version %d
“ serverVersion version);
return;
}
os_printf(“[OTA]Upgrade available version: %d
“ serverVersion);

struct upgrade_server_info* update = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info));
update->pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));

os_memcpy(update->ip server_ip 4);
update->port = port;
os_printf(“[OTA]Server “IPSTR“:%d. Path: [%s]file: [%s]
“ IP2STR(update->ip) update->port path file);
update->check_cb = ota_finished_callback;
update->check_times = 10000;
update->url = (uint8 *)os_zalloc(512);

os_sprintf((char*)update->url
“GET /%s%s HTTP/1.1

“Host: “IPSTR“:%d

“Connection: keep-alive



path file IP2STR(update->ip) update->port);

if (system_upgrade_start(update) == false)
{
os_printf(“[OTA]Could not start upgrade
“);
os_free(update->pespconn);
os_free(update->url);
os_free(update);
}
else
{
os_printf(“[OTA]Upgrading...
“);
}
}

#endif


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件    4374970  2017-10-12 14:36  wifi空中升级2a-esp8266-sdk_getting_started_guide_cn.pdf

     文件    1586971  2017-10-12 14:36  wifi空中升级99c-esp8266_fota_upgrade_cn.pdf

     文件      86171  2017-10-11 15:14  wifi空中升级EasyWebSvr1.9.zip

     文件       2444  2017-10-12 13:58  wifi空中升级ota_upgrade.c

     文件       1218  2017-10-12 15:34  wifi空中升级wifi无线升级说明.txt

     文件     143464  2017-10-12 15:12  wifi空中升级服务器使用教程.docx

     目录          0  2017-10-12 15:12  wifi空中升级

----------- ---------  ---------- -----  ----

              6195238                    7


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)