Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
feat(uart): Support console input cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ESP-YJM committed May 19, 2020
1 parent e0aab74 commit 5e75ccd
Show file tree
Hide file tree
Showing 14 changed files with 466 additions and 181 deletions.
164 changes: 164 additions & 0 deletions examples/solo/example_solo/components/databases/app_entry.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, 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 <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "esp_log.h"
#include "esp_system.h"
#include "transport_uart.h"
#include "transport_data.h"
#include "conn_mgr.h"
#include "iot_import.h"

static const char *TAG = "app_entry";

#define AWSS_SC_NAME "active_awss"
#define AWSS_SOFTAP_NAME "dev_ap"
#define AWSS_RESET_NAME "reset"
#define AWSS_CONN_NAME "netmgr connect"
#define AWSS_CONFIG_NAME "linkkey"
#define AWSS_KV_RST "awss.rst"
static bool s_conn_mgr_exist = false;

int app_check_config_pk(void)
{
char PRODUCT_KEY[IOTX_PRODUCT_KEY_LEN + 1] = {0};

int ret = HAL_GetProductKey(PRODUCT_KEY);

if (!ret || !strlen(PRODUCT_KEY)) {
ESP_LOGE(TAG, "Please first input four config");
return 0;
}

return 1;
}

static void app_get_config_input_len(const char *param, uint32_t *len)
{
uint32_t i = 0;
for (i = 0; i < strlen(param); i ++) {
if (param[i] == ' ' || param[i] == '\r' || param[i] == '\n') {
break;
}
}
*len = i;
}

void start_conn_mgr(void)
{
s_conn_mgr_exist = true;
conn_mgr_start();
s_conn_mgr_exist = false;
vTaskDelete(NULL);
}

void app_get_input_param(char *param, size_t param_len)
{
if (!param) {
ESP_LOGE(TAG, "Input error");
return;
}

if (strstr(param, AWSS_CONFIG_NAME)) {
uint32_t len = 0;
char buf[64 + 1] = {0};

char *input = param + strlen(AWSS_CONFIG_NAME) + 1;
app_get_config_input_len(input, &len);
strncpy(buf, input, len);
ESP_LOGI(TAG, "ProductKey: %s", buf);
HAL_SetProductKey(buf);

input += len + 1;
app_get_config_input_len(input, &len);
memset(buf, 0, 65);
strncpy(buf, input, len);
ESP_LOGI(TAG, "DeviceName: %s", buf);
HAL_SetDeviceName(buf);

input += len + 1;
app_get_config_input_len(input, &len);
memset(buf, 0, 65);
strncpy(buf, input, len);
ESP_LOGI(TAG, "DeviceSecret: %s", buf);
HAL_SetDeviceSecret(buf);

input += len + 1;
app_get_config_input_len(input, &len);
memset(buf, 0, 65);
strncpy(buf, input, len);
ESP_LOGI(TAG, "ProductSecret: %s", buf);
HAL_SetProductSecret(buf);
return;
}

if (!app_check_config_pk()) {
return;
}

conn_mgr_stop();

if (strstr(param, AWSS_SC_NAME)) {
ESP_LOGI(TAG, "Set smartconfig and zero config");
if (s_conn_mgr_exist) {
ESP_LOGE(TAG, "In AWSS config can't set sc mode");
return;
}
conn_mgr_set_sc_mode(CONN_SC_ZERO_MODE);
} else if (strstr(param, AWSS_SOFTAP_NAME)) {
ESP_LOGI(TAG, "Set softap config");
if (s_conn_mgr_exist) {
ESP_LOGE(TAG, "In AWSS config can't set sc mode");
return;
}
conn_mgr_set_sc_mode(CONN_SOFTAP_MODE);
} else if (strstr(param, AWSS_RESET_NAME)) {
char rst = 0x01;
conn_mgr_reset_wifi_config();
HAL_Kv_Set(AWSS_KV_RST, &rst, sizeof(rst), 0);
esp_restart();
} else if (strstr(param, AWSS_CONN_NAME)) {
uint32_t len = 0;
char buf[64 + 1] = {0};

char *input = param + strlen(AWSS_CONN_NAME) + 1;
app_get_config_input_len(input, &len);
strncpy(buf, input, len);
ESP_LOGI(TAG, "SSID: %s", buf);
HAL_Kv_Set(STA_SSID_KEY, buf, 32, 0);

input += len + 1;
app_get_config_input_len(input, &len);
memset(buf, 0 ,65);
strncpy(buf, input, len);
ESP_LOGI(TAG, "Password: %s", buf);
HAL_Kv_Set(STA_PASSWORD_KEY, buf, 64, 0);
} else {
ESP_LOGE(TAG, "Can't recongize cmd");
return;
}

xTaskCreate(start_conn_mgr, "conn_mgr", 3072, NULL, 5, NULL);
}
39 changes: 39 additions & 0 deletions examples/solo/example_solo/components/databases/app_entry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, 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.
*
*/
#ifndef _APP_ENTRY_H__
#define _APP_ENTRY_H__

#include "stdint.h"
#ifdef __cplusplus
extern "C" {
#endif

void app_get_input_param(char *param, size_t param_len);
int app_check_config_pk(void);
void start_conn_mgr(void);;
#ifdef __cplusplus
}
#endif

#endif

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "iot_export_linkkit.h"
#include "cJSON.h"
#include "esp_log.h"

#include "transport_uart.h"

#define USER_EXAMPLE_YIELD_TIMEOUT_MS (200)

Expand Down Expand Up @@ -324,9 +324,12 @@ static int user_fota_event_handler(int type, const char *version)

if (type == 0) {
EXAMPLE_TRACE("New Firmware Version: %s", version);

extern bool transport_task_exist_flag;
transport_task_exist_flag = true;
if (IOT_Linkkit_Query(user_example_ctx->master_devid, ITM_MSG_QUERY_FOTA_DATA, (unsigned char *)buffer, buffer_length) == SUCCESS_RETURN) {
HAL_Reboot();
} else {
transport_uart_task_create();
}
}

Expand Down
2 changes: 2 additions & 0 deletions examples/solo/example_solo/components/transports/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
COMPONENT_ADD_INCLUDEDIRS := ./
COMPONENT_SRCDIRS := ./
Loading

0 comments on commit 5e75ccd

Please sign in to comment.