This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uart): Support console input cmd
- Loading branch information
Showing
14 changed files
with
466 additions
and
181 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
examples/solo/example_solo/components/databases/app_entry.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
examples/solo/example_solo/components/databases/app_entry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
File renamed without changes.
7 changes: 0 additions & 7 deletions
7
examples/solo/example_solo/components/factory_restore/CMakeLists.txt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
examples/solo/example_solo/components/factory_restore/Kconfig.projbuild
This file was deleted.
Oops, something went wrong.
121 changes: 0 additions & 121 deletions
121
examples/solo/example_solo/components/factory_restore/factory_restore.c
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
examples/solo/example_solo/components/transports/component.mk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
COMPONENT_ADD_INCLUDEDIRS := ./ | ||
COMPONENT_SRCDIRS := ./ |
Oops, something went wrong.