先放上我的源码。
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2016 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "ets_sys.h"
#include "osapi.h"
#include "ip_addr.h"
#include "mem.h"
#include "client.h"
#include "uart.h"
#include "os_type.h"
#include "upgrade.h"
#include "espconn.h"
#include "user_interface.h"
#include "smartconfig.h"
#include "airkiss.h"
uint8 UserBinStr[10];
LOCAL os_timer_t user_runtimer;
#define DEVICE_TYPE "gh_9e2cff3dfa51" //wechat public number
#define DEVICE_ID "122475" //model ID
#define DEFAULT_LAN_PORT 12476
LOCAL esp_udp ssdp_udp;
LOCAL struct espconn pssdpudpconn;
LOCAL os_timer_t ssdp_time_serv;
LOCAL struct station_config s_staconf;
uint8_t lan_buf[200];
uint16_t lan_buf_len;
uint8 udp_sent_cnt = 0;
const airkiss_config_t akconf =
{
(airkiss_memset_fn)&memset,
(airkiss_memcpy_fn)&memcpy,
(airkiss_memcmp_fn)&memcmp,
0,
};
uint32 ICACHE_FLASH_ATTR
user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;
case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;
case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
break;
default:
rf_cal_sec = 0;
break;
}
return rf_cal_sec;
}
void ICACHE_FLASH_ATTR
user_rf_pre_init(void)
{
}
void ICACHE_FLASH_ATTR
user_running(void)
{
os_timer_disarm (&user_runtimer);
os_printf("%s is running!\r\n" , UserBinStr );
os_timer_setfn(&user_runtimer,(os_timer_func_t *)user_running,NULL);
os_timer_arm(&user_runtimer,2000,0);
}
static 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!\n");
system_upgrade_reboot();
}
else
{
os_printf("[OTA]failed!\n");
}
os_free(update->pespconn);
os_free(update->url);
os_free(update);
os_timer_setfn(&user_runtimer,(os_timer_func_t *)user_running,NULL);
os_timer_arm(&user_runtimer,2000,0);
}
#define pheadbuffer "Connection: keep-alive\r\n\
Cache-Control: no-cache\r\n\
\r\n"
static void ICACHE_FLASH_ATTR handleUpgrade(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.1024.new.2.bin"; break;
case UPGRADE_FW_BIN2: file = "user1.1024.new.2.bin"; break;
default:
os_printf("[OTA]Invalid userbin number!\n");
return;
}
uint16_t version=1;
if (serverVersion <= version)
{
os_printf("[OTA]No update. Server version:%d, local version %d\n", serverVersion, version);
return;
}
os_printf("[OTA]Upgrade available version: %d\n", 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%s\n", IP2STR(update->ip), update->port, path, file);
update->check_cb = ota_finished_callback;
update->check_times = 20000;
update->url = (uint8 *)os_zalloc(512);
os_sprintf((char*)update->url,
"GET %s%s HTTP/1.1\r\n"
"Host: "IPSTR":%d\r\n"
pheadbuffer,
path, file, IP2STR(update->ip), update->port);
if (system_upgrade_start(update) == false) {
os_printf("[OTA]Could not start upgrade\n");
os_free(update->pespconn);
os_free(update->url);
os_free(update);
}
else
{
os_printf("[OTA]Upgrading...\n");
}
}
/******* WIFI事件回调函数 ******/
void ICACHE_FLASH_ATTR wifi_event_handler_cb_cb(System_Event_t *event){
struct ip_info info;
switch(event->event)
{
case EVENT_STAMODE_CONNECTED:
os_printf("et connect to ssid %s, channel %d\n",
event->event_info.connected.ssid,
event->event_info.connected.channel);
break;
case EVENT_STAMODE_GOT_IP:
os_printf("ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR,
IP2STR(&event->event_info.got_ip.ip),
IP2STR(&event->event_info.got_ip.mask),
IP2STR(&event->event_info.got_ip.gw));
os_printf("\n");
char ip[4] = {119,23,42,111}; //ww.linzoe.cn的IP地址
os_printf("LLAMANDO!!\n");
os_timer_disarm (&user_runtimer);
handleUpgrade(2,ip,1122,"/");
/* const char remote_ip[4]={192,168,10,107}; //存放外部的IP地址
wifi_get_ip_info(STATION_IF,&info);
tcp_server_init((struct ip_addr *)remote_ip,&info.ip,8080);
*/
// HttpReadFile("http://ww.linzoe.cn:1122/");
break;
default:
break;
}
}
/******* WIFI Station参数配置与连接AP(路由) ******/
void ICACHE_FLASH_ATTR
user_set_station_config(void)
{
uint8 ssid[32] = "LinZeJS";
uint8 password[64] = "linze2016";
struct station_config stationConf;
stationConf.bssid_set = 0; //need not check MAC address of AP
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 64);
wifi_station_set_config(&stationConf);
wifi_station_connect();
}
void ICACHE_FLASH_ATTR
user_init(void)
{
os_printf("SDK version版本:%s\n", system_get_sdk_version());
// uart_init(74880,74880);
if ( system_upgrade_userbin_check( ) == UPGRADE_FW_BIN1 )
{
strncpy(UserBinStr , "user1.bin" , 9 );
}
else
{
strncpy(UserBinStr , "user2.bin" , 9 );
}
UserBinStr[9] = '\0';
os_printf( "%s is running!\r\n" , UserBinStr );
os_timer_disarm (&user_runtimer);
os_timer_setfn(&user_runtimer,(os_timer_func_t *)user_running,NULL);
os_timer_arm(&user_runtimer,2000,0);
smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS
wifi_set_opmode(STATION_MODE);
os_printf("mode:%d\n", wifi_get_opmode());
wifi_set_event_handler_cb(wifi_event_handler_cb_cb); //event处理回调函数,出现相应event事件回调用该函数
user_set_station_config();
}
其中在user_init主函数里,只要我将
smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS
设置快连接模式加上,远程升级就会失败,注释掉这条函数后,远程升级就会成功,请问下是什么原因造成这种现象的?
打印Log如下:
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 816, room 16
tail 0
chksum 0x8d
load 0x3ffe8000, len 788, room 8
tail 12
chksum 0xcf
ho 0 tail 12 room 4
load 0x3ffe8314, len 288, room 12
tail 4
chksum 0xcf
csum 0xcf
2nd boot version : 1.2
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size : 4Mbit
jump to run user1
rf cal sector: 123
freq trace enable 0
rf[112] : 00
rf[113] : 00
rf[114] : 01
SDK ver: 2.1.0(116b762) compiled @ May 5 2017 16:08:55
phy ver: 1134_0, pp ver: 10.2
SDK version版本:2.1.0(116b762)
user1.bin is running!
mode:1
mode : sta(18:fe:34:d3:f7:74)
add if0
user1.bin is running!
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 15
cnt
connected with LinZeJS, channel 11
dhcp client start...
et connect to ssid LinZeJS, channel 11
ip:192.168.10.114,mask:255.255.255.0,gw:192.168.10.1
ip:192.168.10.114,mask:255.255.255.0,gw:192.168.10.1
LLAMANDO!!
[OTA]Upgrade available version: 2
[OTA]Server 119.23.42.111:1122. Path: /user2.1024.new.2.bin
system_upgrade_start
upgrade_connect 50160
[OTA]Upgrading...
upgrade_connect_cb
pusrdata = HTTP/1.1 200 OK
Content-Length: 256100
Content-Type: application/octet-stream
Last-Modified: Tue, 06 Jun 2017 02:11:52 GMT
Accept-Ranges: bytes
ETag: "2d503e436aded21:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Tue, 06 Jun 2017 02:14:38 GMT
Connection: close
sumlength = 256100
sec_block 63
sec_block 63 exceed
upgrade_check
[OTA]failed!
upgrade_get_sum_disconcb 50480
为什么只加了一句函数,远程升级就会失败?
Re: 为什么只加了一句函数,远程升级就会失败?
Postby YONG_LI » Fri Jun 09, 2017 10:23 am
你讲的这个我了解,smartconfig和user_set_station_config只能任选其一,不过我的问题是,我暂时没有用smartconfig,而只是先设置了这个模式而已。
在没加这句设置函数前,远程升级是正常的,但加上这句函数后,远程升级就失败了,我对比了下打印的log,在没加smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS); 这句设置函数前,擦除的块是
sec_block 58
..........................................................erase sector=1 ok
upgrade_get_sum_disconcb 47512
erase sector=2 ok
erase sector=3 ok
erase sector=4 ok
.........
erase sector=57 ok
erase sector=58 ok
不过在加了smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS);这句函数后,擦除的块就变成了
sumlength = 256100
sec_block 63
sec_block 63 exceed
upgrade_check
[OTA]failed!
所以我不知道为什么我仅仅只是加了一句函数,它擦去的块的位置就变了?
在没加这句设置函数前,远程升级是正常的,但加上这句函数后,远程升级就失败了,我对比了下打印的log,在没加smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS); 这句设置函数前,擦除的块是
sec_block 58
..........................................................erase sector=1 ok
upgrade_get_sum_disconcb 47512
erase sector=2 ok
erase sector=3 ok
erase sector=4 ok
.........
erase sector=57 ok
erase sector=58 ok
不过在加了smartconfig_set_type(SC_TYPE_ESPTOUCH_AIRKISS);这句函数后,擦除的块就变成了
sumlength = 256100
sec_block 63
sec_block 63 exceed
upgrade_check
[OTA]failed!
所以我不知道为什么我仅仅只是加了一句函数,它擦去的块的位置就变了?
Who is online
Users browsing this forum: No registered users and 64 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.