增加命令行配置WIFI账号密码功能
parent
d26526d3c4
commit
34640c343a
|
@ -45,7 +45,8 @@
|
|||
"*.inc": "cpp",
|
||||
"*.ipp": "cpp",
|
||||
"istream": "cpp",
|
||||
"typeinfo": "cpp"
|
||||
"typeinfo": "cpp",
|
||||
"esp_wifi.h": "c"
|
||||
},
|
||||
"idf.portWin": "COM8",
|
||||
"idf.openOcdConfigs": [
|
||||
|
|
|
@ -37,13 +37,9 @@ static void HAL_Sensor_Init()
|
|||
|
||||
void HAL_Init()
|
||||
{
|
||||
printf("Config_Init\n");
|
||||
Config_Init();
|
||||
printf("SD_Init\n");
|
||||
SD_Init();
|
||||
printf("Power_Init\n");
|
||||
Power_Init();
|
||||
printf("Button_Init\n");
|
||||
Button_Init();
|
||||
|
||||
#if CONFIG_SENSOR_ENABLE
|
||||
|
@ -53,7 +49,6 @@ void HAL_Init()
|
|||
#ifndef _WIN32
|
||||
ShellSupport_Init();
|
||||
#endif
|
||||
|
||||
taskManager.Register(Power_Update, 1000);
|
||||
taskManager.Register(Button_Update, 10);
|
||||
taskManager.Register(IMU_Update, 10);
|
||||
|
|
|
@ -29,28 +29,27 @@ void Config_Init()
|
|||
}
|
||||
|
||||
Config_InitFlag = true;
|
||||
size_t length = 64;
|
||||
/* If load wifi name fail. config the default name. and password */
|
||||
if(Config_GetString("WIFI_NAME", StringBuff, &length) == 0){
|
||||
if(Config_GetString("WIFI_NAME", StringBuff, 64) == 0){
|
||||
Config_SetString("WIFI_NAME", "WIFI_DAFAULT_NAME");
|
||||
}
|
||||
if(Config_GetString("WIFI_PWD", StringBuff, &length) == 0){
|
||||
if(Config_GetString("WIFI_PWD", StringBuff, 64) == 0){
|
||||
Config_SetString("WIFI_PWD", "WIFI_DAFAULT_PWD");
|
||||
}
|
||||
if(Config_GetString("DEV_IDX", StringBuff, &length) == 0){
|
||||
if(Config_GetString("DEV_IDX", StringBuff, 64) == 0){
|
||||
Config_SetString("DEV_IDX", "0");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t Config_GetString(const char* key, char* str, size_t* length)
|
||||
uint8_t Config_GetString(const char* key, char* str, size_t len)
|
||||
{
|
||||
if(!Config_InitFlag){
|
||||
return 0;
|
||||
}
|
||||
|
||||
esp_err_t err = nvs_get_str(nvs_hal, key, str, length);
|
||||
|
||||
size_t length = len;
|
||||
esp_err_t err = nvs_get_str(nvs_hal, key, str, &length);
|
||||
if(err != ESP_OK)
|
||||
{
|
||||
printf("Cofig_GetStrig:: nvs_get_str error\n");
|
||||
|
|
|
@ -17,11 +17,16 @@ struct sockaddr_in saddr = { 0 };
|
|||
int sock = -1;
|
||||
char buff[UDP_BUFF_LEN] = " ";
|
||||
char ConfigString[64] = {0};
|
||||
char ssid[32] = {0};
|
||||
char password[64] = {0};
|
||||
|
||||
void Network_Init()
|
||||
{
|
||||
Config_GetString("WIFI_NAME", ssid, 32);
|
||||
Config_GetString("WIFI_PWD", password, 64);
|
||||
|
||||
/* Connect WIFI first. */
|
||||
WIFI_Connect();
|
||||
WIFI_Connect(ssid, password);
|
||||
/* Init socket to send data. */
|
||||
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||
if (sock < 0) {
|
||||
|
@ -36,8 +41,7 @@ void Network_Init()
|
|||
void Network_UdpSendData()
|
||||
{
|
||||
int err = 0;
|
||||
size_t length = 64;
|
||||
Config_GetString("DEV_IDX", ConfigString, &length);
|
||||
Config_GetString("DEV_IDX", ConfigString, 64);
|
||||
while (1)
|
||||
{
|
||||
float yaw = 0.0f, roll = 0.0f, pitch = 0.0f;
|
||||
|
|
|
@ -32,11 +32,11 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|
|
|||
int PrintWifiConfig(){
|
||||
char StringBuff[64] = {0};
|
||||
size_t length = 64;
|
||||
uint8_t ret = Config_GetString("WIFI_NAME", StringBuff, &length);
|
||||
uint8_t ret = Config_GetString("WIFI_NAME", StringBuff, 64);
|
||||
if(ret){
|
||||
printf("Config WIFI Name = %s\n", StringBuff);
|
||||
}
|
||||
ret = Config_GetString("WIFI_PWD", StringBuff, &length);
|
||||
ret = Config_GetString("WIFI_PWD", StringBuff, 64);
|
||||
if(ret){
|
||||
printf("Config WIFI Password = %s\n", StringBuff);
|
||||
}
|
||||
|
@ -66,8 +66,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|
|
|||
|
||||
int PrintDevIndex(){
|
||||
char StringBuff[64] = {0};
|
||||
size_t length = 64;
|
||||
uint8_t ret = Config_GetString("DEV_IDX", StringBuff, &length);
|
||||
uint8_t ret = Config_GetString("DEV_IDX", StringBuff, 64);
|
||||
if(ret){
|
||||
printf("Config device idx = %s \n", StringBuff);
|
||||
}else{
|
||||
|
|
|
@ -134,7 +134,7 @@ void Memory_DumpInfo();
|
|||
|
||||
/* Config */
|
||||
void Config_Init();
|
||||
uint8_t Config_GetString(const char* key, char* str, size_t* length);
|
||||
uint8_t Config_GetString(const char* key, char* str, size_t len);
|
||||
void Config_SetInt();
|
||||
void Config_GetInt();
|
||||
uint8_t Config_SetString(const char* key, const char* str);
|
||||
|
|
|
@ -8,9 +8,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
uint8_t Library_WIFI_Init(char* ssid, char* password);
|
||||
|
||||
uint8_t WIFI_Connect(void);
|
||||
uint8_t WIFI_Connect(char* ssid, char* password);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "WIFINetwork.h"
|
||||
/* ESP32 Library support. */
|
||||
|
@ -9,14 +10,11 @@
|
|||
#include "freertos/event_groups.h"
|
||||
|
||||
|
||||
|
||||
/* The event group allows multiple bits for each event, but we only care about two events:
|
||||
* - we are connected to the AP with an IP
|
||||
* - we failed to connect after the maximum amount of retries */
|
||||
|
||||
#define CFG_MAXIMUM_RETRY 1000 /* 配置最大重新连接次数 */
|
||||
#define CFG_WIFI_SSID "logzhan" // 配置默认连接的WIFI的SSID
|
||||
#define CFG_WIFI_PASS "19931203" // 配置默认连接的WIFI的密码
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
@ -26,8 +24,6 @@ static int s_retry_num = 0;
|
|||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = CFG_WIFI_SSID,
|
||||
.password = CFG_WIFI_PASS,
|
||||
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
.pmf_cfg = {
|
||||
.capable = true,
|
||||
|
@ -45,11 +41,11 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
|||
if (s_retry_num < CFG_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
printf("retry to connect to the AP\r\n");
|
||||
//printf("retry to connect to the AP\r\n");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
printf("connect to the AP fail\r\n");
|
||||
//printf("connect to the AP fail\r\n");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
|
@ -58,21 +54,7 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initializing the esp32 wifi network by gaving wifi ssid and
|
||||
* password.
|
||||
* @param ssid : Wifi name which you want to connect.
|
||||
* @param password : The wifi's password which you want to connect.
|
||||
* @return
|
||||
* @date 2022-09-04
|
||||
* @author zhanli
|
||||
*/
|
||||
uint8_t Library_WIFI_Init(char* ssid, char* password){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
uint8_t WIFI_Connect(){
|
||||
uint8_t WIFI_Connect(char* ssid, char* password){
|
||||
|
||||
ESP_LOGI(TAG, "LIB_WIFIConnect");
|
||||
|
||||
|
@ -105,6 +87,10 @@ uint8_t WIFI_Connect(){
|
|||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
/* Config esp32 ssid password and authmode. */
|
||||
ESP_LOGI(TAG, "esp_wifi_set_config");
|
||||
|
||||
strcpy((char*)(wifi_config.sta.ssid), ssid);
|
||||
strcpy((char*)(wifi_config.sta.password), password);
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||
/* Start run the esp32 wifi. */
|
||||
ESP_LOGI(TAG, "esp_wifi_start");
|
||||
|
@ -125,12 +111,10 @@ uint8_t WIFI_Connect(){
|
|||
*/
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
CFG_WIFI_SSID, CFG_WIFI_PASS);
|
||||
// xTaskCreate(create_multicast_ipv4_socket, "udp_client", 4096, NULL, 5, NULL);
|
||||
// xTaskCreate(udp_send_data, "udp_send", 4096, NULL, 5, NULL);
|
||||
ssid, password);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
CFG_WIFI_SSID, CFG_WIFI_PASS);
|
||||
ssid, password);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 49 KiB |
56
README.md
56
README.md
|
@ -1,13 +1,11 @@
|
|||
# GeekTrack
|
||||
# **GeekTrack**
|
||||
|
||||
**功能描述:一个无线姿态追踪模块,可以追踪姿态。可以用于全身动作捕捉也可以用于人体步态追踪, GeekTrack实际是GeekMotion阉割屏幕减少尺寸的版本,目的是为了方便固定在身体上,用于姿态追踪**
|
||||
## 一、功能描述:
|
||||
|
||||
**GeekMotion:** https://github.com/Logzhan/GeekMoton
|
||||
|
||||
状态:PCB已经打样测试完成,设备WIFI正常,信号对比PCB天线弱一些。IMU、气压计读取数据正常、SD卡识别正常。
|
||||
一个无线姿态追踪模块,可以追踪姿态。可以用于全身动作捕捉也可以用于人体步态追踪, GeekTrack实际是GeekMotion阉割屏幕减少尺寸的版本,目的是为了方便固定在身体上,用于姿态追踪
|
||||
|
||||
- WIFI通信功能
|
||||
- IMU、MAG传感器。
|
||||
- IMU、MAG传感器、气压传感器、温度传感器
|
||||
- LettleShell命令行模块,可以采用命令行和ESP32交互。
|
||||
- 计步器
|
||||
- 运动识别(待实现)
|
||||
|
@ -28,11 +26,53 @@
|
|||
- 历史命令行记忆
|
||||
- ...
|
||||
|
||||
**更新日志:**
|
||||
注意:命令行被log覆盖的时候按下回车即可。
|
||||
|
||||
**2022-09-03 :** 1)上传第一版原理图和PCB图
|
||||
## 二、使用方法
|
||||
|
||||
WIFI的配置(通过命令行):
|
||||
|
||||
```shell
|
||||
# 命令行设置WIFI账号和密码
|
||||
set_wifi_cfg "your wifi ssid" "your wifi password"
|
||||
# 设置完成后重启生效
|
||||
reboot
|
||||
```
|
||||
|
||||
配置设备索引:可以用数字表示设备的索引,数字可以为0~65536
|
||||
|
||||
```shell
|
||||
set_dev_idx "device_type_num"
|
||||
```
|
||||
|
||||
设备传感器信息的发送,默认UDP端口9000:
|
||||
|
||||
```shell
|
||||
# dev_Index yaw roll pitch
|
||||
0 -75.127640 5.829678 -67.846695
|
||||
0 -75.029457 5.810158 -67.830681
|
||||
0 -74.926865 5.784514 -67.806129
|
||||
```
|
||||
|
||||
## 三、更新日志
|
||||
|
||||
**2022-09-03 :** 上传第一版原理图和PCB图
|
||||
|
||||
**2022-09-19 :** 第一版固件调试通过
|
||||
|
||||
**2022-09-24 :**
|
||||
|
||||
1. 优化app_main, 精简总行数 < 40
|
||||
2. 调整结构,迁移网络部分到HAL_Network.cpp
|
||||
3. 删除GeekTrack无用的关于lvgl部分
|
||||
4. 删除无用的lvgl仿真器
|
||||
5. 增加NVS存储获取设备索引信息(Idx,可以描述设备0~n)
|
||||
6. UDP发送增加Idx识别信息
|
||||
7. 增加NVS设置Idx
|
||||
|
||||
**2022-09-25:** 增加NVS设置WIFI ssid和WIFI 密码功能
|
||||
|
||||
## 四、编译说明
|
||||
|
||||
**lettleShell移植支持说明:** 需要适配esp32的ld文件。
|
||||
|
||||
|
|
Loading…
Reference in New Issue