Statistics: Posted by ESP_Faye — Mon Aug 24, 2015 5:08 pm
Code:
/******************************************************************************
* Copyright 2013-2014 Espressif Systems (Wuxi)
*
* FileName: user_main.c
*
* Description: entry file of user application
*
* Modification history:
* 2014/1/1, v1.0 create this file.
*******************************************************************************/
#include "ets_sys.h"
#include "osapi.h"
#include "user_interface.h"
#include "espconn.h"
#include "mem.h"
#include "osapi.h"
#include "upgrade.h"
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);
}
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 = 10000;
update->url = (uint8 *)os_zalloc(512);
os_sprintf((char*)update->url,
"GET %s%s HTTP/1.1\r\n"
"Host: "IPSTR":%d\r\n"
"Connection: close\r\n"
"\r\n",
path, file, IP2STR(update->ip), update->port);
os_printf("URL: %s.\r\n", (char*)update->url);
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");
}
}
void user_rf_pre_init(void)
{
}
char ipBuf[] = {192, 168, 1, 120};
void ICACHE_FLASH_ATTR wifiConnectCb(System_Event_t *evt)
{
uint8_t i;
bool res = false;
os_printf("Wifi event: %d\r\n", evt->event);
if(evt->event == EVENT_STAMODE_GOT_IP){
handleUpgrade(2, ipBuf, 80, "/upgrade/");
}
os_printf("Free heap: %d\r\n", system_get_free_heap_size());
}
void user_init(void)
{
os_printf("SDK version:%s rom %d\n", system_get_sdk_version(), system_upgrade_userbin_check());
gpio_init();
wifi_set_opmode(STATION_MODE);
wifi_set_event_handler_cb(wifiConnectCb);
// Config led to inidicate wifi status
wifi_status_led_install(4, PERIPHS_IO_MUX_GPIO4_U, FUNC_GPIO4);
wifi_station_set_auto_connect(TRUE);
wifi_station_set_reconnect_policy(1);
wifi_station_connect();
}
Code:
2nd boot version : 1.4(b1)
SPI Speed : 40MHz
SPI Mode : QIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000
d��+P�*��h�*�Dr
SDK ver: 1.3.0 compiled @ Aug 7 2015 19:17:30
phy ver: 41201, pp ver: 9.0
SDK version:1.3.0 rom 1
mode : sta(18:fe:34:99:31:77)
add if0
f 0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
connected with Vinh 1102, channel 7
Wifi event: 0
Free heap: 49976
dhcp client start...
Wifi event: 3
[OTA]Upgrade available version: 2
[OTA]Server 192.168.1.120:80. Path: /upgrade/user1.1024.new.2.bin
URL: GET /upgrade/user1.1024.new.2.bin HTTP/1.1
Host: 192.168.1.120:80
Connection: close
.
system_upgrade_start
upgrade_connect
[OTA]Upgrading...
Free heap: 48496
ip:192.168.1.58,mask:255.255.255.0,gw:192.168.1.1
upgrade_connect_cb
GET /upgrade/user1.1024.new.2.bin HTTP/1.1
Host: 192.168.1.120:80
Connection: close
sumlength = 304240
�@*r��P���K�t�dr�.@��.�Ѫ�
Code:
"GET /upgrade/user1.1024.new.2.bin HTTP/1.1" 200 304240 "-" "-"
Code:
python esptool.py --port /dev/ttyUSB0 write_flash -fs 8m 0x00000 ../bin/boot_v1.4(b1).bin 0x81000 ../bin/upgrade/user2.1024.new.2.bin 0xFE000 ../bin/blank.bin
Statistics: Posted by nvl1109 — Sat Aug 22, 2015 4:56 pm