From 1534a44d4914f876ece1ff6f5b6e6d7a5f625b76 Mon Sep 17 00:00:00 2001 From: Chen Wu Date: Fri, 14 Jun 2024 19:48:57 +0800 Subject: [PATCH] feat(N8266-90): Re-added ota implement and generated AT firmwares on ci - Re-added OTA implement based on iot.espressif.cn - Generated AT firmwares on CI jobs - Closes N8266-90 - Closes N8266-91 --- .gitlab-ci.yml | 48 +++- examples/at/Makefile | 5 + examples/at/include/user_config.h | 10 +- examples/at/user/at_esp_upgrade.c | 327 +++++++++++++++++++++++++ examples/at_nano/Makefile | 5 + examples/at_nano/include/user_config.h | 10 +- examples/at_nano/user/at_esp_upgrade.c | 327 +++++++++++++++++++++++++ 7 files changed, 724 insertions(+), 8 deletions(-) create mode 100755 examples/at/user/at_esp_upgrade.c create mode 100755 examples/at_nano/user/at_esp_upgrade.c diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d25769eb..872ad253 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,7 +41,11 @@ stages: # - chmod +x gen_misc_non_os.sh # - ./gen_misc_non_os.sh -build_at: +.at_setup_tokens: &at_setup_tokens + - echo -e "#define CONFIG_AT_1024_1024_TOKEN \"$AT_1024_1024_TOKEN\"" >> include/user_config.h + - echo -e "#define CONFIG_AT_512_512_TOKEN \"$AT_512_512_TOKEN\"" >> include/user_config.h + +build_at_1024_1024_u1: <<: *build_template artifacts: paths: @@ -51,7 +55,47 @@ build_at: script: - cp -rf examples/at at - cd at - - make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=5 + - *at_setup_tokens + - make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=5 AT_ESP_UPGRADE=1 + +build_at_1024_1024_u2: + <<: *build_template + artifacts: + paths: + - ./bin/upgrade + - ./bin/*.bin + expire_in: 6 mos + script: + - cp -rf examples/at at + - cd at + - *at_setup_tokens + - make COMPILE=gcc BOOT=new APP=2 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=5 AT_ESP_UPGRADE=1 + +build_at_512_512_u1: + <<: *build_template + artifacts: + paths: + - ./bin/upgrade + - ./bin/*.bin + expire_in: 6 mos + script: + - cp -rf examples/at_nano at + - cd at + - *at_setup_tokens + - make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=2 AT_ESP_UPGRADE=1 + +build_at_512_512_u2: + <<: *build_template + artifacts: + paths: + - ./bin/upgrade + - ./bin/*.bin + expire_in: 6 mos + script: + - cp -rf examples/at_nano at + - cd at + - *at_setup_tokens + - make COMPILE=gcc BOOT=new APP=2 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=2 AT_ESP_UPGRADE=1 build_at_espconn: <<: *build_template diff --git a/examples/at/Makefile b/examples/at/Makefile index fcb5d40a..ed3efb12 100755 --- a/examples/at/Makefile +++ b/examples/at/Makefile @@ -127,6 +127,11 @@ CONFIGURATION_DEFINES += \ -DAT_UPGRADE_SUPPORT endif +ifeq ($(AT_ESP_UPGRADE),1) +CONFIGURATION_DEFINES += \ + -DAT_ESP_UPGRADE +endif + ifeq ($(SPI_SIZE_MAP),5) CONFIGURATION_DEFINES += -DFLASH_MAP=$(SPI_SIZE_MAP) endif diff --git a/examples/at/include/user_config.h b/examples/at/include/user_config.h index f254b1a7..680c0dc6 100755 --- a/examples/at/include/user_config.h +++ b/examples/at/include/user_config.h @@ -22,10 +22,13 @@ * */ -#ifndef __USER_CONFIG_H__ -#define __USER_CONFIG_H__ +#pragma once +// #define AT_ESP_UPGRADE + +#ifndef AT_ESP_UPGRADE #define AT_CUSTOM_UPGRADE +#endif #ifdef AT_CUSTOM_UPGRADE #ifndef AT_UPGRADE_SUPPORT @@ -37,4 +40,5 @@ // #define CONFIG_AT_WPA2_ENTERPRISE_COMMAND_ENABLE #define CONFIG_ENABLE_IRAM_MEMORY 1 -#endif + +#define ESP_AT_FW_VERSION "Bin version(Wroom 02):1.7.6" diff --git a/examples/at/user/at_esp_upgrade.c b/examples/at/user/at_esp_upgrade.c new file mode 100755 index 00000000..0615c87a --- /dev/null +++ b/examples/at/user/at_esp_upgrade.c @@ -0,0 +1,327 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2024 + * + * 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 "c_types.h" +#include "user_interface.h" +#include "espconn.h" +#include "mem.h" +#include "osapi.h" +#include "upgrade.h" + +#include "at_custom.h" + +#ifdef AT_UPGRADE_SUPPORT +#ifdef AT_ESP_UPGRADE + +#define AT_OTA_SERVER "iot.espressif.cn" + +#if (SPI_FLASH_SIZE_MAP == 2) +#define AT_OTA_TOKEN CONFIG_AT_512_512_TOKEN +#elif (SPI_FLASH_SIZE_MAP == 5) +#define AT_OTA_TOKEN CONFIG_AT_1024_1024_TOKEN +#else +#error "The flash map is not supported for OTA" +#endif + +#define pheadbuffer "Connection: keep-alive\r\n\ +Cache-Control: no-cache\r\n\ +User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\ +Accept: */*\r\n\ +Authorization: token %s\r\n\ +Accept-Encoding: gzip,deflate,sdch\r\n\ +Accept-Language: zh-CN,zh;q=0.8\r\n\r\n" + +/**/ + + +struct espconn *pespconn = NULL; +struct upgrade_server_info *upServer = NULL; + +static os_timer_t at_delay_check; +static struct espconn *pTcpServer = NULL; +static ip_addr_t host_ip; +static bool s_got_version = false; +static uint8_t s_rom_version[12] = {0}; + +/****************************************************************************** + * FunctionName : user_esp_platform_upgrade_cb + * Description : Processing the downloaded data from the server + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_rsp(void *arg) +{ + struct upgrade_server_info *server = arg; + + + if(server->upgrade_flag == true) + { + os_printf("device_upgrade_success\r\n"); + at_response_ok(); + system_upgrade_reboot(); + } + else + { + os_printf("device_upgrade_failed\r\n"); + at_response_error(); + } + + s_got_version = false; + os_memset(s_rom_version, 0, 12); + os_free(server->url); + server->url = NULL; + os_free(server); + server = NULL; +} +/** + * @brief Tcp client disconnect success callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_discon_cb(void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + uint8_t idTemp = 0; + + if(pespconn->proto.tcp != NULL) + { + os_free(pespconn->proto.tcp); + } + if(pespconn != NULL) + { + os_free(pespconn); + } + + os_printf("disconnect\r\n"); + + if(system_upgrade_start(upServer) == false) + { + at_response_error(); + } + else + { + at_port_print_irom_str("+CIPUPDATE:4\r\n"); + } +} + +/** + * @brief Udp server receive data callback function. + * @param arg: contain the ip link information + * @retval None + */ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_recv(void *arg, char *pusrdata, unsigned short len) +{ + if (!s_got_version) { + char *pstr = (char *)os_strstr(pusrdata, "recommended_rom_version\": \""); + if (pstr) { + pstr += 27; + char *pstr_end = (char *)os_strstr(pstr, "\""); + os_memcpy(s_rom_version, pstr, pstr_end - pstr); + os_printf("found version: %s\r\n", s_rom_version); + s_got_version = true; + } + } + if (s_got_version) { + struct espconn *pespconn = (struct espconn *)arg; + char temp[32] = {0}; + uint8_t user_bin[12] = {0}; + uint8_t i = 0; + + os_timer_disarm(&at_delay_check); + at_port_print_irom_str("+CIPUPDATE:3\r\n"); + + upServer = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info)); + + upServer->upgrade_version[5] = '\0'; + + upServer->pespconn = pespconn; + + os_memcpy(upServer->ip, pespconn->proto.tcp->remote_ip, 4); + + upServer->port = pespconn->proto.tcp->remote_port; + + upServer->check_cb = at_upDate_rsp; + upServer->check_times = 180000; + + if(upServer->url == NULL) + { + upServer->url = (uint8 *) os_zalloc(1024); + } + + if(system_upgrade_userbin_check() == UPGRADE_FW_BIN1) + { + os_memcpy(user_bin, "user2.bin", 10); + } + else if(system_upgrade_userbin_check() == UPGRADE_FW_BIN2) + { + os_memcpy(user_bin, "user1.bin", 10); + } + + os_sprintf(upServer->url, + "GET /v1/device/rom/?action=download_rom&version=%s&filename=%s HTTP/1.1\r\nHost: "IPSTR":80\r\n"pheadbuffer"", + s_rom_version, user_bin, IP2STR(upServer->ip), AT_OTA_TOKEN); + + espconn_disconnect(pespconn); + } +} + +LOCAL void ICACHE_FLASH_ATTR +at_upDate_wait(void *arg) +{ + struct espconn *pespconn = arg; + os_timer_disarm(&at_delay_check); + if(pespconn != NULL) + { + espconn_disconnect(pespconn); + } + else + { + at_response_error(); + } +} + +/****************************************************************************** + * FunctionName : user_esp_platform_sent_cb + * Description : Data has been sent successfully and acknowledged by the remote host. + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_sent_cb(void *arg) +{ + struct espconn *pespconn = arg; + os_timer_disarm(&at_delay_check); + os_timer_setfn(&at_delay_check, (os_timer_func_t *)at_upDate_wait, pespconn); + os_timer_arm(&at_delay_check, 5000, 0); + os_printf("at_upDate_sent_cb\r\n"); +} + +/** + * @brief Tcp client connect success callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_connect_cb(void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + uint8_t user_bin[9] = {0}; + char *temp = NULL; + + at_port_print_irom_str("+CIPUPDATE:2\r\n"); + + + espconn_regist_disconcb(pespconn, at_upDate_discon_cb); + espconn_regist_recvcb(pespconn, at_upDate_recv);//////// + espconn_regist_sentcb(pespconn, at_upDate_sent_cb); + + temp = (uint8 *) os_zalloc(512); + + os_sprintf(temp,"GET /v1/device/rom/?is_format_simple=true HTTP/1.0\r\nHost: "IPSTR":80\r\n"pheadbuffer"", + IP2STR(pespconn->proto.tcp->remote_ip), AT_OTA_TOKEN); + + espconn_sent(pespconn, temp, os_strlen(temp)); + os_free(temp); +} + +/** + * @brief Tcp client connect repeat callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_recon_cb(void *arg, sint8 errType) +{ + struct espconn *pespconn = (struct espconn *)arg; + + at_response_error(); + if(pespconn->proto.tcp != NULL) + { + os_free(pespconn->proto.tcp); + } + os_free(pespconn); + os_printf("disconnect\r\n"); + + if(upServer != NULL) + { + os_free(upServer); + upServer = NULL; + } + at_response_error(); + +} + +/****************************************************************************** + * FunctionName : upServer_dns_found + * Description : dns found callback + * Parameters : name -- pointer to the name that was looked up. + * ipaddr -- pointer to an ip_addr_t containing the IP address of + * the hostname, or NULL if the name could not be found (or on any + * other error). + * callback_arg -- a user-specified callback argument passed to + * dns_gethostbyname + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +upServer_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) +{ + struct espconn *pespconn = (struct espconn *) arg; +// char temp[32]; + if(ipaddr == NULL) + { + at_response_error(); + return; + } + at_port_print_irom_str("+CIPUPDATE:1\r\n"); + + + if(host_ip.addr == 0 && ipaddr->addr != 0) + { + if(pespconn->type == ESPCONN_TCP) + { + os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4); + espconn_regist_connectcb(pespconn, at_upDate_connect_cb); + espconn_regist_reconcb(pespconn, at_upDate_recon_cb); + espconn_connect(pespconn); + } + } +} + +void ICACHE_FLASH_ATTR +at_exeCmdCiupdate(uint8_t id) +{ + pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn)); + pespconn->type = ESPCONN_TCP; + pespconn->state = ESPCONN_NONE; + pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp)); + pespconn->proto.tcp->local_port = espconn_port(); + pespconn->proto.tcp->remote_port = 80; + + espconn_gethostbyname(pespconn, AT_OTA_SERVER, &host_ip, upServer_dns_found); +} +#endif +#endif diff --git a/examples/at_nano/Makefile b/examples/at_nano/Makefile index 5458685d..7113a934 100755 --- a/examples/at_nano/Makefile +++ b/examples/at_nano/Makefile @@ -127,6 +127,11 @@ CONFIGURATION_DEFINES += \ -DAT_UPGRADE_SUPPORT endif +ifeq ($(AT_ESP_UPGRADE),1) +CONFIGURATION_DEFINES += \ + -DAT_ESP_UPGRADE +endif + ifeq ($(SPI_SIZE_MAP),5) CONFIGURATION_DEFINES += -DFLASH_MAP=$(SPI_SIZE_MAP) endif diff --git a/examples/at_nano/include/user_config.h b/examples/at_nano/include/user_config.h index f254b1a7..680c0dc6 100755 --- a/examples/at_nano/include/user_config.h +++ b/examples/at_nano/include/user_config.h @@ -22,10 +22,13 @@ * */ -#ifndef __USER_CONFIG_H__ -#define __USER_CONFIG_H__ +#pragma once +// #define AT_ESP_UPGRADE + +#ifndef AT_ESP_UPGRADE #define AT_CUSTOM_UPGRADE +#endif #ifdef AT_CUSTOM_UPGRADE #ifndef AT_UPGRADE_SUPPORT @@ -37,4 +40,5 @@ // #define CONFIG_AT_WPA2_ENTERPRISE_COMMAND_ENABLE #define CONFIG_ENABLE_IRAM_MEMORY 1 -#endif + +#define ESP_AT_FW_VERSION "Bin version(Wroom 02):1.7.6" diff --git a/examples/at_nano/user/at_esp_upgrade.c b/examples/at_nano/user/at_esp_upgrade.c new file mode 100755 index 00000000..0615c87a --- /dev/null +++ b/examples/at_nano/user/at_esp_upgrade.c @@ -0,0 +1,327 @@ +/* + * ESPRESSIF MIT License + * + * Copyright (c) 2024 + * + * 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 "c_types.h" +#include "user_interface.h" +#include "espconn.h" +#include "mem.h" +#include "osapi.h" +#include "upgrade.h" + +#include "at_custom.h" + +#ifdef AT_UPGRADE_SUPPORT +#ifdef AT_ESP_UPGRADE + +#define AT_OTA_SERVER "iot.espressif.cn" + +#if (SPI_FLASH_SIZE_MAP == 2) +#define AT_OTA_TOKEN CONFIG_AT_512_512_TOKEN +#elif (SPI_FLASH_SIZE_MAP == 5) +#define AT_OTA_TOKEN CONFIG_AT_1024_1024_TOKEN +#else +#error "The flash map is not supported for OTA" +#endif + +#define pheadbuffer "Connection: keep-alive\r\n\ +Cache-Control: no-cache\r\n\ +User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36 \r\n\ +Accept: */*\r\n\ +Authorization: token %s\r\n\ +Accept-Encoding: gzip,deflate,sdch\r\n\ +Accept-Language: zh-CN,zh;q=0.8\r\n\r\n" + +/**/ + + +struct espconn *pespconn = NULL; +struct upgrade_server_info *upServer = NULL; + +static os_timer_t at_delay_check; +static struct espconn *pTcpServer = NULL; +static ip_addr_t host_ip; +static bool s_got_version = false; +static uint8_t s_rom_version[12] = {0}; + +/****************************************************************************** + * FunctionName : user_esp_platform_upgrade_cb + * Description : Processing the downloaded data from the server + * Parameters : pespconn -- the espconn used to connetion with the host + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_rsp(void *arg) +{ + struct upgrade_server_info *server = arg; + + + if(server->upgrade_flag == true) + { + os_printf("device_upgrade_success\r\n"); + at_response_ok(); + system_upgrade_reboot(); + } + else + { + os_printf("device_upgrade_failed\r\n"); + at_response_error(); + } + + s_got_version = false; + os_memset(s_rom_version, 0, 12); + os_free(server->url); + server->url = NULL; + os_free(server); + server = NULL; +} +/** + * @brief Tcp client disconnect success callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_discon_cb(void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + uint8_t idTemp = 0; + + if(pespconn->proto.tcp != NULL) + { + os_free(pespconn->proto.tcp); + } + if(pespconn != NULL) + { + os_free(pespconn); + } + + os_printf("disconnect\r\n"); + + if(system_upgrade_start(upServer) == false) + { + at_response_error(); + } + else + { + at_port_print_irom_str("+CIPUPDATE:4\r\n"); + } +} + +/** + * @brief Udp server receive data callback function. + * @param arg: contain the ip link information + * @retval None + */ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_recv(void *arg, char *pusrdata, unsigned short len) +{ + if (!s_got_version) { + char *pstr = (char *)os_strstr(pusrdata, "recommended_rom_version\": \""); + if (pstr) { + pstr += 27; + char *pstr_end = (char *)os_strstr(pstr, "\""); + os_memcpy(s_rom_version, pstr, pstr_end - pstr); + os_printf("found version: %s\r\n", s_rom_version); + s_got_version = true; + } + } + if (s_got_version) { + struct espconn *pespconn = (struct espconn *)arg; + char temp[32] = {0}; + uint8_t user_bin[12] = {0}; + uint8_t i = 0; + + os_timer_disarm(&at_delay_check); + at_port_print_irom_str("+CIPUPDATE:3\r\n"); + + upServer = (struct upgrade_server_info *)os_zalloc(sizeof(struct upgrade_server_info)); + + upServer->upgrade_version[5] = '\0'; + + upServer->pespconn = pespconn; + + os_memcpy(upServer->ip, pespconn->proto.tcp->remote_ip, 4); + + upServer->port = pespconn->proto.tcp->remote_port; + + upServer->check_cb = at_upDate_rsp; + upServer->check_times = 180000; + + if(upServer->url == NULL) + { + upServer->url = (uint8 *) os_zalloc(1024); + } + + if(system_upgrade_userbin_check() == UPGRADE_FW_BIN1) + { + os_memcpy(user_bin, "user2.bin", 10); + } + else if(system_upgrade_userbin_check() == UPGRADE_FW_BIN2) + { + os_memcpy(user_bin, "user1.bin", 10); + } + + os_sprintf(upServer->url, + "GET /v1/device/rom/?action=download_rom&version=%s&filename=%s HTTP/1.1\r\nHost: "IPSTR":80\r\n"pheadbuffer"", + s_rom_version, user_bin, IP2STR(upServer->ip), AT_OTA_TOKEN); + + espconn_disconnect(pespconn); + } +} + +LOCAL void ICACHE_FLASH_ATTR +at_upDate_wait(void *arg) +{ + struct espconn *pespconn = arg; + os_timer_disarm(&at_delay_check); + if(pespconn != NULL) + { + espconn_disconnect(pespconn); + } + else + { + at_response_error(); + } +} + +/****************************************************************************** + * FunctionName : user_esp_platform_sent_cb + * Description : Data has been sent successfully and acknowledged by the remote host. + * Parameters : arg -- Additional argument to pass to the callback function + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +at_upDate_sent_cb(void *arg) +{ + struct espconn *pespconn = arg; + os_timer_disarm(&at_delay_check); + os_timer_setfn(&at_delay_check, (os_timer_func_t *)at_upDate_wait, pespconn); + os_timer_arm(&at_delay_check, 5000, 0); + os_printf("at_upDate_sent_cb\r\n"); +} + +/** + * @brief Tcp client connect success callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_connect_cb(void *arg) +{ + struct espconn *pespconn = (struct espconn *)arg; + uint8_t user_bin[9] = {0}; + char *temp = NULL; + + at_port_print_irom_str("+CIPUPDATE:2\r\n"); + + + espconn_regist_disconcb(pespconn, at_upDate_discon_cb); + espconn_regist_recvcb(pespconn, at_upDate_recv);//////// + espconn_regist_sentcb(pespconn, at_upDate_sent_cb); + + temp = (uint8 *) os_zalloc(512); + + os_sprintf(temp,"GET /v1/device/rom/?is_format_simple=true HTTP/1.0\r\nHost: "IPSTR":80\r\n"pheadbuffer"", + IP2STR(pespconn->proto.tcp->remote_ip), AT_OTA_TOKEN); + + espconn_sent(pespconn, temp, os_strlen(temp)); + os_free(temp); +} + +/** + * @brief Tcp client connect repeat callback function. + * @param arg: contain the ip link information + * @retval None + */ +static void ICACHE_FLASH_ATTR +at_upDate_recon_cb(void *arg, sint8 errType) +{ + struct espconn *pespconn = (struct espconn *)arg; + + at_response_error(); + if(pespconn->proto.tcp != NULL) + { + os_free(pespconn->proto.tcp); + } + os_free(pespconn); + os_printf("disconnect\r\n"); + + if(upServer != NULL) + { + os_free(upServer); + upServer = NULL; + } + at_response_error(); + +} + +/****************************************************************************** + * FunctionName : upServer_dns_found + * Description : dns found callback + * Parameters : name -- pointer to the name that was looked up. + * ipaddr -- pointer to an ip_addr_t containing the IP address of + * the hostname, or NULL if the name could not be found (or on any + * other error). + * callback_arg -- a user-specified callback argument passed to + * dns_gethostbyname + * Returns : none +*******************************************************************************/ +LOCAL void ICACHE_FLASH_ATTR +upServer_dns_found(const char *name, ip_addr_t *ipaddr, void *arg) +{ + struct espconn *pespconn = (struct espconn *) arg; +// char temp[32]; + if(ipaddr == NULL) + { + at_response_error(); + return; + } + at_port_print_irom_str("+CIPUPDATE:1\r\n"); + + + if(host_ip.addr == 0 && ipaddr->addr != 0) + { + if(pespconn->type == ESPCONN_TCP) + { + os_memcpy(pespconn->proto.tcp->remote_ip, &ipaddr->addr, 4); + espconn_regist_connectcb(pespconn, at_upDate_connect_cb); + espconn_regist_reconcb(pespconn, at_upDate_recon_cb); + espconn_connect(pespconn); + } + } +} + +void ICACHE_FLASH_ATTR +at_exeCmdCiupdate(uint8_t id) +{ + pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn)); + pespconn->type = ESPCONN_TCP; + pespconn->state = ESPCONN_NONE; + pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp)); + pespconn->proto.tcp->local_port = espconn_port(); + pespconn->proto.tcp->remote_port = 80; + + espconn_gethostbyname(pespconn, AT_OTA_SERVER, &host_ip, upServer_dns_found); +} +#endif +#endif