improve at firmware
This commit is contained in:
@@ -15,9 +15,9 @@ int esp8266_tencent_firmware_module_info_set(device_info_t *info, tls_mode_t mod
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCDEVINFOSET:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCDEVINFOSET=%d,\"%s\",\"%s\",\"%s\"\r\n",
|
||||
mode, info->product_id, info->device_name, info->device_serc);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -31,10 +31,10 @@ int esp8266_tencent_firmware_module_mqtt_conn(mqtt_param_t init_params)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTCONN:OK");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTCONN=%d,%d,%d,%d,%d\r\n", init_params.tls_mode,
|
||||
init_params.command_timeout, init_params.keep_alive_interval_ms,
|
||||
init_params.clean_session, init_params.auto_connect_enable);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -61,14 +61,14 @@ int esp8266_tencent_firmware_module_mqtt_publ(const char *topic, qos_t qos, char
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, ">");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+TCMQTTPUBL=\"%s\",%d,%d\r\n", topic, qos, strlen(payload)-2);
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
tos_at_raw_data_send(&echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_raw_data_send_until(&echo, 1000, (uint8_t *)payload, strlen(payload));
|
||||
if (echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -82,8 +82,8 @@ int esp8266_tencent_firmware_module_mqtt_pub(const char *topic, qos_t qos, char
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTPUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 1000, "AT+TCMQTTPUB=\"%s\",%d,\"%s\"\r\n", topic, qos, payload);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -95,8 +95,8 @@ int esp8266_tencent_firmware_module_mqtt_sub(char *topic, qos_t qos)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTSUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTSUB=\"%s\",%d\r\n", topic, qos);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -108,8 +108,8 @@ int esp8266_tencent_firmware_module_mqtt_unsub(const char *topic)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCMQTTUNSUB:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCMQTTUNSUB=\"%s\"\r\n", topic);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -130,8 +130,7 @@ int esp8266_tencent_firmware_module_mqtt_state_get(mqtt_state_t *state)
|
||||
}
|
||||
|
||||
str = strstr(echo.buffer, "+TCMQTTSTATE:");
|
||||
if (!str)
|
||||
{
|
||||
if (!str) {
|
||||
return -1;
|
||||
}
|
||||
sscanf(str, "+TCMQTTSTATE:%d", &ret_state);
|
||||
@@ -164,10 +163,10 @@ int esp8266_tencent_firmware_join_ap(const char *ssid, const char *pwd)
|
||||
int try = 0;
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "WIFI CONNECTED");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 10000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec(&echo, 15000, "AT+CWJAP=\"%s\",\"%s\"\r\n", ssid, pwd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -181,8 +180,8 @@ static int esp8266_tencent_firmware_restore(void)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "ready");
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 5000, "AT+RESTORE\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 5000, "AT+RESTORE\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -221,10 +220,10 @@ static int esp8266_tencent_firmware_net_mode_set(sal_net_mode_t mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "no change");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
while (try++ < 10) {
|
||||
tos_at_cmd_exec(&echo, 1000, cmd);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status == AT_ECHO_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -281,8 +280,8 @@ int esp8266_tencent_firmware_ota_set(ota_mode_t mode, char *version)
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "+TCOTASET:OK");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCOTASET=%d,\"%s\"\r\n", mode, version);
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
@@ -304,8 +303,8 @@ int esp8266_tencent_firmware_ota_read_fwinfo(ota_fw_info_t *ota_fw_info)
|
||||
|
||||
tos_at_echo_create(&echo, echo_buffer, sizeof(echo_buffer), "+TCFWINFO:");
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
tos_at_cmd_exec_until(&echo, 2000, "AT+TCFWINFO?\r\n");
|
||||
if (echo.status == AT_ECHO_STATUS_EXPECT) {
|
||||
|
||||
sscanf(echo_buffer, "%*[^\"]%*c%[^\"]%*[^,]%*c%[^,]%*[^\"]%*c%[^\"]", ota_fw_info->fw_version, FileSize, ota_fw_info->fw_md5);
|
||||
for(int i = 0; i<10; i++)
|
||||
@@ -478,9 +477,9 @@ int esp8266_tencent_firmware_start_smartconfig(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCSTARTSMART\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -504,10 +503,10 @@ int esp8266_tencent_firmware_stop_smartconfig(void)
|
||||
{
|
||||
at_echo_t echo;
|
||||
|
||||
tos_at_echo_create(&echo, NULL, 0, "OK");
|
||||
tos_at_echo_create(&echo, NULL, 0, NULL);
|
||||
|
||||
tos_at_cmd_exec(&echo, 2000, "AT+TCSTOPSMART\r\n");
|
||||
if (echo.status != AT_ECHO_STATUS_OK && echo.status != AT_ECHO_STATUS_EXPECT) {
|
||||
if (echo.status != AT_ECHO_STATUS_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user