0
0
Fork 0

feat(wifi) fast connect on boot and disconnection

- add json api get tools's ap info
 - cleanup some unused code, change printf to ESP_LOG
This commit is contained in:
kerms 2024-04-01 12:39:50 +08:00
parent 2ac6d894b8
commit c5f46accc3
14 changed files with 84 additions and 379 deletions

177
README.md
View File

@ -1,7 +1,3 @@
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/120061980-49274280-c092-11eb-9916-4965f6c48388.png"/></p>
![image](https://user-images.githubusercontent.com/17078589/107857220-05ecef00-6e68-11eb-9fa0-506b32052dba.png)
[中文](README_CN.md)
## Introduce
@ -21,7 +17,6 @@ For Keil users, we now also support [elaphureLink](https://github.com/windowsair
## Feature
1. SoC Compatibility
- [x] ESP32
- [x] ESP32C3
2. Debug Communication Mode
@ -32,8 +27,6 @@ For Keil users, we now also support [elaphureLink](https://github.com/windowsair
- [x] USB-HID
- [x] WCID & WinUSB (Default)
4. Debug Trace (Uart)
- [x] Uart TCP Bridge
5. More..
- [x] SWD protocol based on SPI acceleration (Up to 40MHz)
@ -46,13 +39,6 @@ For Keil users, we now also support [elaphureLink](https://github.com/windowsair
### WIFI
The default connected WIFI SSID is `DAP` or `OTA` , password `12345678`
Support for specifying multiple possible WAP. It can be added here: [wifi_configuration.h](project_components/wifi_manager/wifi_configuration.h)
You can also specify your IP in the above file (We recommend using the static address binding feature of the router).
![WIFI](https://user-images.githubusercontent.com/17078589/118365659-517e7880-b5d0-11eb-9a5b-afe43348c2ba.png)
There is built-in ipv4 only mDNS server. You can access the device using `dap.local`.
@ -61,46 +47,6 @@ There is built-in ipv4 only mDNS server. You can access the device using `dap.lo
### Debugger
<details>
<summary>ESP32</summary>
| SWD | |
|----------------|--------|
| SWCLK | GPIO14 |
| SWDIO | GPIO13 |
| TVCC | 3V3 |
| GND | GND |
--------------
| JTAG | |
|--------------------|---------|
| TCK | GPIO14 |
| TMS | GPIO13 |
| TDI | GPIO18 |
| TDO | GPIO19 |
| nTRST \(optional\) | GPIO25 |
| nRESET | GPIO26 |
| TVCC | 3V3 |
| GND | GND |
--------------
| Other | |
|--------------------|---------------|
| LED\_WIFI\_STATUS | GPIO27 |
| Tx | GPIO23 |
| Rx | GPIO22 |
> Rx and Tx is used for uart bridge, not enabled by default.
</details>
<details>
<summary>ESP32C3</summary>
@ -126,14 +72,6 @@ There is built-in ipv4 only mDNS server. You can access the device using `dap.lo
| TVCC | 3V3 |
| GND | GND |
--------------
| Other | |
|--------------------|---------------|
| LED\_WIFI\_STATUS | GPIO10 |
| Tx | GPIO19 |
| Rx | GPIO18 |
</details>
@ -145,19 +83,15 @@ There is built-in ipv4 only mDNS server. You can access the device using `dap.lo
You can build locally or use Github Action to build online and then download firmware to flash.
### Build with Github Action Online
See: [Build with Github Action](https://github.com/windowsair/wireless-esp8266-dap/wiki/Build-with-Github-Action)
### General build and Flash
<details>
<summary>ESP32/ESP32C3</summary>
<summary>ESP32C3</summary>
1. Get esp-idf
For now, please use esp-idf v4.4.2 : https://github.com/espressif/esp-idf/releases/tag/v4.4.2
For now, please use esp-idf v5.2.1 : https://github.com/espressif/esp-idf/releases/tag/v5.2.1
2. Build & Flash
@ -168,7 +102,7 @@ The following example shows a possible way to build:
```bash
# Set build target
idf.py set-target esp32
idf.py set-target esp32c3
# Build
idf.py build
# Flash
@ -266,109 +200,6 @@ Note that if you want to use a 40MHz SPI acceleration, you need to specify the s
> Keil's timing handling is somewhat different from OpenOCD's. For example, OpenOCD lacks the SWD line reset sequence before reading the `IDCODE` registers.
### System OTA
When this project is updated, you can update the firmware over the air.
Visit the following website for OTA operations: [online OTA](http://corsacota.surge.sh/?address=dap.local:3241)
For most devices, you don't need to care about flash size. However, improper setting of the flash size may cause the OTA to fail. In this case, please change the flash size with `idf.py menuconfig`, or modify `sdkconfig`:
```
# Choose a flash size.
CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
# Then set a flash size
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
```
If flash size is 2MB, the sdkconfig file might look like this:
```
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
```
For devices with 1MB flash size such as ESP8285, the following changes must be made:
```
CONFIG_PARTITION_TABLE_FILENAME="partitions_two_ota.1MB.csv"
CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="1MB"
CONFIG_ESP8266_BOOT_COPY_APP=y
```
The flash size of the board can be checked with the esptool.py tool:
```bash
esptool.py -p (PORT) flash_id
```
### Uart TCP Bridge
This feature provides a bridge between TCP and Uart:
```
Send data -> TCP -> Uart TX -> external devices
Recv data <- TCP <- Uart Rx <- external devices
```
![uart_tcp_bridge](https://user-images.githubusercontent.com/17078589/150290065-05173965-8849-4452-ab7e-ec7649f46620.jpg)
When the TCP connection is established, bridge will try to resolve the text sent for the first packet. When the text is a valid baud rate, bridge will switch to it.
For example, sending the ASCII text `115200` will switch the baud rate to 115200.
For performance reasons, this feature is not enabled by default. You can modify [wifi_configuration.h](main/wifi_configuration.h) to turn it on.
----
## Develop
Check other branches to know the latest development progress.
Any kind of contribute is welcome, including but not limited to new features, ideas about circuits, documentation.
You can also ask questions to make this project better.
- [New issues](https://github.com/windowsair/wireless-esp8266-dap/issues)
- [New pull](https://github.com/windowsair/wireless-esp8266-dap/pulls)
### Issue
2020.12.1
TCP transmission speed needs to be further improved.
2020.11.11
Winusb is now available, but it is very slow.
2020.2.4
Due to the limitation of USB-HID (I'm not sure if this is a problem with USBIP or Windows), now each URB packet can only reach 255 bytes (About 1MBps bandwidth), which has not reached the upper limit of ESP8266 transmission bandwidth.
I now have an idea to construct a Man-in-the-middle between the two to forward traffic, thereby increasing the bandwidth of each transmission.
2020.1.31
At present, the adaptation to WCID, WinUSB, etc. has all been completed. However, when transmitting data on the endpoint, we received an error message from USBIP. This is most likely a problem with the USBIP project itself.
Due to the completeness of the USBIP protocol document, we have not yet understood its role in the Bulk transmission process, which may also lead to errors in subsequent processes.
We will continue to try to make it work on USB HID. Once the USBIP problem is solved, we will immediately transfer it to work on WinUSB
------
## Credit
@ -376,6 +207,7 @@ We will continue to try to make it work on USB HID. Once the USBIP problem is so
Credits to the following project, people and organizations:
> - https://www.github.com/windowsair/wireless-esp8266-dap origin of this project
> - https://github.com/thevoidnn/esp8266-wifi-cmsis-dap for adapter firmware based on CMSIS-DAP v1.0
> - https://github.com/ARM-software/CMSIS_5 for CMSIS
> - https://github.com/cezanne/usbip-win for usbip windows
@ -390,4 +222,3 @@ Credits to the following project, people and organizations:
## License
[Apache2.0 LICENSE](LICENSE)

View File

@ -1,10 +1,3 @@
<p align="center"><b>请注意:不同语言版本的翻译可能落后于项目的原始文档。请以原始文档为准。</b></p>
<p align="center"><img src="https://user-images.githubusercontent.com/17078589/120061980-49274280-c092-11eb-9916-4965f6c48388.png"/></p>
![image](https://user-images.githubusercontent.com/17078589/107857220-05ecef00-6e68-11eb-9fa0-506b32052dba.png)
## 简介
只需要**一枚ESP芯片**即可开始无线调试通过USBIP协议栈和CMSIS-DAP协议栈实现。
@ -20,7 +13,6 @@
## 特性
1. 支持的ESP芯片
- [x] ESP32
- [x] ESP32C3
2. 支持的调试接口:
@ -42,63 +34,15 @@
### WIFI连接
固件默认的WIFI SSID是`DAP`或者`OTA`,密码是`12345678`。
你可以在[wifi_configuration.h](main/wifi_configuration.h)文件中添加多个无线接入点。
你还可以在上面的配置文件中修改IP地址但是我们更推荐你通过在路由器上绑定静态IP地址
![WIFI](https://user-images.githubusercontent.com/17078589/118365659-517e7880-b5d0-11eb-9a5b-afe43348c2ba.png)
固件中已经内置了一个mDNS服务。你可以通过`dap.local`的地址访问到设备。
![mDNS](https://user-images.githubusercontent.com/17078589/149659052-7b29533f-9660-4811-8125-f8f50490d762.png)
### 调试接口连接
<details>
<summary>ESP32</summary>
| SWD | |
|----------------|--------|
| SWCLK | GPIO14 |
| SWDIO | GPIO13 |
| TVCC | 3V3 |
| GND | GND |
--------------
| JTAG | |
|--------------------|---------|
| TCK | GPIO14 |
| TMS | GPIO13 |
| TDI | GPIO18 |
| TDO | GPIO19 |
| nTRST \(optional\) | GPIO25 |
| nRESET | GPIO26 |
| TVCC | 3V3 |
| GND | GND |
--------------
| Other | |
|--------------------|---------------|
| LED\_WIFI\_STATUS | GPIO27 |
| Tx | GPIO23 |
| Rx | GPIO22 |
> Rx和Tx用于TCP转发的串口默认不开启该功能。
</details>
<details>
<summary>ESP32C3</summary>
@ -124,16 +68,6 @@
| TVCC | 3V3 |
| GND | GND |
--------------
| Other | |
|--------------------|---------------|
| LED\_WIFI\_STATUS | GPIO10 |
| Tx | GPIO19 |
| Rx | GPIO18 |
> Rx和Tx用于TCP转发的串口默认不开启该功能。
</details>
@ -145,44 +79,15 @@
你可以在本地构建或使用Github Action在线构建固件然后下载固件进行烧写。
### 使用Github Action在线构建固件
详见:[Build with Github Action](https://github.com/windowsair/wireless-esp8266-dap/wiki/Build-with-Github-Action)
### 在本地构建并烧写
<details>
<summary>ESP8266</summary>
1. 获取ESP8266 SDK
项目中已经随附了一个SDK。请不要使用其他版本的SDK。
2. 编译和烧写
使用ESP-IDF编译系统进行构建。
更多的信息,请见:[Build System](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html "Build System")
下面例子展示了在Windows上完成这些任务的一种可行方法
```bash
# 编译
python ./idf.py build
# 烧写
python ./idf.py -p /dev/ttyS5 flash
```
</details>
<details>
<summary>ESP32/ESP32C3</summary>
<summary>ESP32C3</summary>
1. 获取esp-idf
目前请考虑使用esp-idf v4.4.2 https://github.com/espressif/esp-idf/releases/tag/v4.4.2
目前请考虑使用esp-idf v5.2.1 https://github.com/espressif/esp-idf/releases/tag/v5.2.1
2. 编译和烧写
@ -193,6 +98,7 @@ python ./idf.py -p /dev/ttyS5 flash
下面例子展示了在Windows上完成这些任务的一种可行方法
```bash
idf.py set-target esp32c3
# 编译
idf.py build
# 烧写
@ -209,7 +115,6 @@ idf.py -p /dev/ttyS5 flash
## 使用
1. 获取USBIP项目
@ -256,13 +161,10 @@ idf.py -p /dev/ttyS5 flash
- Logitech Arx Control
- ...
对于ESP8266, 这无异于UDP洪水攻击...😰
周围的射频环境同样会造成影响,此外距离、网卡性能等也可能是需要考虑的。
## 文档
### 速度策略
@ -290,82 +192,16 @@ idf.py -p /dev/ttyS5 flash
> Keil的操作时序与OpenOCD的有些不同。例如OpenOCD在读取 "IDCODE "寄存器之前缺少SWD线复位序列。
### 系统 OTA
当这个项目被更新时,你可以通过无线方式更新固件。
请访问以下网站了解OTA操作。[在线OTA](http://corsacota.surge.sh/?address=dap.local:3241)
对于大多数ESP8266设备你不需要关心闪存的大小。然而闪存大小设置不当可能会导致OTA失败。在这种情况下请用`idf.py menuconfig`改变闪存大小,或者修改`sdkconfig`
```
# 选择一个flash大小
CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
# 然后设置flash大小
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
```
如果闪存大小为2MBsdkconfig文件会看起来像这样
```
CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="2MB"
```
对于闪存大小为1MB的设备如ESP8285必须做以下修改。
```
CONFIG_PARTITION_TABLE_FILENAME="partitions_two_ota.1MB.csv"
CONFIG_ESPTOOLPY_FLASHSIZE_1MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="1MB"
CONFIG_ESP8266_BOOT_COPY_APP=y
```
可以用esptool.py工具检查你使用的ESP设备闪存大小
```bash
esptool.py -p (PORT) flash_id
```
### TCP转发的串口
该功能在TCP和Uart之间提供了一个桥梁
```
发送数据 -> TCP -> Uart TX -> 外部设备
接收数据 <- TCP <- Uart Rx <- 外部设备
```
![uart_tcp_bridge](https://user-images.githubusercontent.com/17078589/150290065-05173965-8849-4452-ab7e-ec7649f46620.jpg)
当TCP连接建立后ESP芯片将尝试解决首次发送的文本。当文本是一个有效的波特率时转发器就会切换到该波特率。例如发送ASCII文本`115200`会将波特率切换为115200。
由于性能原因,该功能默认不启用。你可以修改 [wifi_configuration.h](main/wifi_configuration.h) 来打开它。
----
## 开发
请查看其他分支以了解最新的开发进展。我们欢迎任何形式的贡献,包括但不限于新功能、关于电路的想法和文档。
如果你有什么想法,欢迎在下面提出:
- [新的Issues](https://github.com/windowsair/wireless-esp8266-dap/issues)
- [新的pull request](https://github.com/windowsair/wireless-esp8266-dap/pulls)
# 致谢
归功于以下项目、人员和组织。
> - https://www.github.com/windowsair/wireless-esp8266-dap origin of this project
> - https://github.com/thevoidnn/esp8266-wifi-cmsis-dap for adapter firmware based on CMSIS-DAP v1.0
> - https://github.com/ARM-software/CMSIS_5 for CMSIS
> - https://github.com/cezanne/usbip-win for usbip windows
- [@windowsair](https://github.com/windowsair/wireless-esp8266-dap)
- [@windowsair](https://www.github.com/windowsair/wireless-esp8266-dap)
- [@HeavenSpree](https://www.github.com/HeavenSpree)
- [@Zy19930907](https://www.github.com/Zy19930907)
- [@caiguang1997](https://www.github.com/caiguang1997)

View File

@ -42,7 +42,7 @@ void *static_buffer_get(uint32_t tick_wait)
void static_buffer_put(void *ptr)
{
printf("put buf %d\n", uxQueueMessagesWaiting(buf_queue));
//printf("put buf %d\n", uxQueueMessagesWaiting(buf_queue));
if (unlikely(xQueueSend(buf_queue, &ptr, 0) != pdTRUE)) {
assert(0);
}

View File

@ -83,14 +83,14 @@ static int8_t opened_socket = 0;
static esp_err_t web_server_on_open(httpd_handle_t hd, int sockfd)
{
opened_socket++;
printf("%d open, now: %d\n", sockfd, opened_socket);
ESP_LOGI(TAG, "%d open, now: %d", sockfd, opened_socket);
return ESP_OK;
}
static void web_server_on_close(httpd_handle_t hd, int sockfd)
{
opened_socket--;
printf("%d closed, now: %d\n", sockfd, opened_socket);
ESP_LOGI(TAG, "%d closed, now: %d", sockfd, opened_socket);
close(sockfd);
}

View File

@ -48,7 +48,7 @@ int uri_module_exit(httpd_handle_t server)
int uri_module_add(uint8_t priority, uri_module_func init, uri_module_func exit)
{
ESP_LOGE(TAG, "adding module %p", init);
ESP_LOGI(TAG, "adding module %p", init);
if (module_count >= URI_MODULE_MAX) {
ESP_LOGE(TAG, "too much module > URI_MODULE_MAX");

View File

@ -1,8 +1,9 @@
#include "wifi_api.h"
#include "wifi_manager.h"
#include "wifi_configuration.h"
#include <esp_wifi.h>
void wifi_api_get_ap_info(wifi_api_ap_info_t *ap_info)
void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info)
{
wifi_ap_record_t ap_record;
esp_wifi_sta_get_ap_info(&ap_record);
@ -18,6 +19,16 @@ void wifi_api_get_ap_info(wifi_api_ap_info_t *ap_info)
ip4_addr_set(&ap_info->netmask, &ip_info.netmask);
}
void wifi_api_ap_get_info(wifi_api_ap_info_t *ap_info)
{
strncpy(ap_info->ssid, WIFI_DEFAULT_AP_SSID, strlen(WIFI_DEFAULT_AP_SSID)+1);
esp_wifi_get_mac(WIFI_IF_AP, (uint8_t *) &ap_info->mac);
IP4_ADDR_EXPAND(&ap_info->ip, WIFI_DEFAULT_AP_IP);
IP4_ADDR_EXPAND(&ap_info->gateway, WIFI_DEFAULT_AP_GATEWAY);
IP4_ADDR_EXPAND(&ap_info->netmask, WIFI_DEFAULT_AP_NETMASK);
ap_info->rssi = 0;
}
static int rssi_comp(const void *a, const void *b)
{
const wifi_api_ap_info_t *r1 = a;

View File

@ -7,10 +7,11 @@
typedef enum wifi_api_json_cmd_t {
UNKNOWN = 0,
WIFI_API_JSON_GET_AP_INFO,
WIFI_API_JSON_STA_GET_AP_INFO,
WIFI_API_JSON_CONNECT,
WIFI_API_JSON_GET_SCAN,
WIFI_API_JSON_DISCONNECT,
WIFI_API_JSON_AP_GET_INFO,
} wifi_api_json_cmd_t;
typedef struct wifi_api_ap_info_t {
@ -22,7 +23,9 @@ typedef struct wifi_api_ap_info_t {
signed char rssi;
} wifi_api_ap_info_t;
void wifi_api_get_ap_info(wifi_api_ap_info_t *ap_info);
void wifi_api_sta_get_ap_info(wifi_api_ap_info_t *ap_info);
void wifi_api_ap_get_info(wifi_api_ap_info_t *ap_info);
typedef void (*wifi_api_scan_done_cb)(uint16_t found, wifi_api_ap_info_t *aps, void *arg);

View File

@ -5,8 +5,11 @@
#include "wifi_json_utils.h"
#include <stdio.h>
#include <esp_log.h>
static int wifi_api_json_get_ap_info(api_json_req_t *req);
#define TAG __FILENAME__
static int wifi_api_json_sta_get_ap_info(api_json_req_t *req);
static int wifi_api_json_get_scan(api_json_req_t *req);
@ -14,6 +17,8 @@ static int wifi_api_json_connect(api_json_req_t *req);
static int wifi_api_json_disconnect(api_json_req_t *req);
static int wifi_api_json_ap_get_info(api_json_req_t *req);
static int async_helper_cb(void *arg)
{
@ -37,25 +42,36 @@ static int on_json_req(uint16_t cmd, api_json_req_t *req, api_json_module_async_
case UNKNOWN:
default:
break;
case WIFI_API_JSON_GET_AP_INFO:
return wifi_api_json_get_ap_info(req);
case WIFI_API_JSON_STA_GET_AP_INFO:
return wifi_api_json_sta_get_ap_info(req);
case WIFI_API_JSON_CONNECT:
return set_async(req, async, wifi_api_json_connect);
case WIFI_API_JSON_GET_SCAN:
return set_async(req, async, wifi_api_json_get_scan);
case WIFI_API_JSON_DISCONNECT:
return wifi_api_json_disconnect(req);
case WIFI_API_JSON_AP_GET_INFO:
return wifi_api_json_ap_get_info(req);
break;
}
printf("cmd %d not executed\n", cmd);
ESP_LOGI(TAG, "cmd %d not executed\n", cmd);
return API_JSON_BAD_REQUEST;
}
static int wifi_api_json_sta_get_ap_info(api_json_req_t *req)
{
wifi_api_ap_info_t ap_info;
wifi_api_sta_get_ap_info(&ap_info);
req->out = wifi_api_json_serialize_ap_info(&ap_info, WIFI_API_JSON_STA_GET_AP_INFO);
return 0;
}
static int wifi_api_json_get_ap_info(api_json_req_t *req)
static int wifi_api_json_ap_get_info(api_json_req_t *req)
{
wifi_api_ap_info_t ap_info;
wifi_api_get_ap_info(&ap_info);
req->out = wifi_api_json_serialize_ap_info(&ap_info);
wifi_api_ap_get_info(&ap_info);
req->out = wifi_api_json_serialize_ap_info(&ap_info, WIFI_API_JSON_AP_GET_INFO);
return 0;
}
@ -65,7 +81,7 @@ static int wifi_api_json_get_scan(api_json_req_t *req)
uint16_t max_count = 20;
int err;
printf("get scan\n");
ESP_LOGI(TAG, "get scan\n");
err = wifi_api_get_scan_list(&max_count, ap_info);
if (err == ESP_ERR_NOT_FINISHED) {
@ -73,7 +89,7 @@ static int wifi_api_json_get_scan(api_json_req_t *req)
return 1;
}
printf("scan ok\n");
ESP_LOGI(TAG, "scan ok\n");
req->out = wifi_api_json_serialize_scan_list(ap_info, max_count);
return 0;
@ -91,7 +107,7 @@ int wifi_api_json_connect(api_json_req_t *req)
return 1;
}
printf("trigger connect\n");
ESP_LOGI(TAG, "trigger connect\n");
return wifi_api_connect(ssid, password);
};

View File

@ -1,11 +1,17 @@
#ifndef WIFI_CONFIGURATION_H_GUARD
#define WIFI_CONFIGURATION_H_GUARD
#define WIFI_DEFAULT_HOSTNAME "无线DAP"
#define WIFI_DEFAULT_AP_SSID "无线DAP"
#define WIFI_DEFAULT_AP_PASS "12345678"
#define WIFI_DEFAULT_HOSTNAME "无线DAP"
#define WIFI_DEFAULT_AP_IP 192, 168, 1, 1
#define WIFI_DEFAULT_AP_GATEWAY 192, 168, 1, 1
#define WIFI_DEFAULT_AP_NETMASK 255, 255, 255, 0
#define WIFI_DEFAULT_STA_SSID "example_ssid"
#define WIFI_DEFAULT_STA_PASS "12345678"
#define IP4_ADDR_EXPAND(...) IP4_ADDR(__VA_ARGS__)
#endif //WIFI_CONFIGURATION_H_GUARD

View File

@ -9,13 +9,13 @@ static void wifi_api_json_set_header(cJSON *root, uint16_t cmd)
cJSON_AddNumberToObject(root, "module", WIFI_API_MODULE_ID);
}
cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info)
cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info, wifi_api_json_cmd_t cmd)
{
cJSON *root;
root = cJSON_CreateObject();
wifi_api_json_set_header(root, WIFI_API_JSON_GET_AP_INFO);
wifi_api_json_set_header(root, cmd);
cJSON_AddStringToObject(root, "ip", ip4addr_ntoa(&ap_info->ip));
cJSON_AddStringToObject(root, "gateway", ip4addr_ntoa(&ap_info->gateway));
cJSON_AddStringToObject(root, "netmask", ip4addr_ntoa(&ap_info->netmask));

View File

@ -3,7 +3,7 @@
#include "wifi_api.h"
cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info);
cJSON *wifi_api_json_serialize_ap_info(wifi_api_ap_info_t *ap_info, wifi_api_json_cmd_t cmd);
cJSON *wifi_api_json_serialize_scan_list(wifi_api_ap_info_t *aps_info, uint16_t count);

View File

@ -36,7 +36,8 @@ typedef struct wifi_ctx_t {
};
uint8_t is_endless_connect:1;
uint8_t auto_reconnect:1;
uint8_t reserved:6;
uint8_t do_fast_connect:1; /* 0 delay connect on boot or just disconnected, else 5 seconds delay from each connection try */
uint8_t reserved:5;
} wifi_ctx_t;
static esp_netif_t *ap_netif;
@ -84,13 +85,14 @@ void wifi_manager_init(void)
if (set_default_sta_cred() == 0) {
do_connect = 1;
ctx.do_fast_connect = 1;
}
/* TODO: Read from nvs */
esp_netif_ip_info_t ip_info;
IP4_ADDR(&ip_info.ip, 192, 168, 1, 1);
IP4_ADDR(&ip_info.gw, 192, 168, 1, 1);
IP4_ADDR(&ip_info.netmask, 255, 255, 255, 0);
IP4_ADDR_EXPAND(&ip_info.ip, WIFI_DEFAULT_AP_IP);
IP4_ADDR_EXPAND(&ip_info.gw, WIFI_DEFAULT_AP_GATEWAY);
IP4_ADDR_EXPAND(&ip_info.netmask, WIFI_DEFAULT_AP_NETMASK);
err = esp_netif_dhcps_stop(ap_netif);
if (err) {
@ -120,6 +122,9 @@ void wifi_manager_init(void)
}
}
/**
* @brief called by wifi_event_handler on scan done
* */
static void wifi_event_scan_channel_done(uint16_t number, wifi_ap_record_t *aps)
{
ctx.scan.nr_aps_in_channel = number;
@ -145,8 +150,7 @@ static int scan_loop()
return 1;
}
/* shadow wifi_event_scan_channel_done() called */
vTaskDelay(100);
vTaskDelay(pdMS_TO_TICKS(100));
ret = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000));
if (ret == 0) {
/* timeout */
@ -166,6 +170,7 @@ int wifi_manager_get_scan_list(uint16_t *number, wifi_ap_record_t *aps)
if (ctx.is_endless_connect == 0) {
return 1;
}
/* Is in connecting mode */
ESP_LOGI(TAG, "deleting connecting %p", ctx.task);
vTaskDelete(ctx.task);
/* in case lock is released when deleting the task */
@ -219,7 +224,6 @@ static void try_connect_done(void *arg, wifi_event_sta_connected_t *event)
ctx.conn.need_unlock = 0;
xSemaphoreGive(ctx.lock);
}
ESP_LOGI(TAG, "event done %p", ctx.task);
}
int set_default_sta_cred()
@ -295,7 +299,12 @@ static void reconnection_task(void *arg)
do {
ESP_LOGI(TAG, "reco task: try connect, task %p", xTaskGetCurrentTaskHandle());
err = wifi_event_trigger_connect(0, try_connect_done, NULL);
if (ctx.do_fast_connect) {
err = wifi_event_trigger_connect(5, try_connect_done, NULL);
} else {
err = wifi_event_trigger_connect(0, try_connect_done, NULL);
}
if (err) {
ESP_LOGE(TAG, "trigger connect err: %s", esp_err_to_name(err));
break;
@ -339,6 +348,7 @@ static void disconn_handler(void)
}
ESP_LOGI(TAG, "start reconn task");
ctx.do_fast_connect = 1;
xTaskCreate(reconnection_task, "reconn task", 4 * 1024, NULL, 7, NULL);
}

View File

@ -5,9 +5,6 @@
void wifi_manager_init();
int wifi_set_ap_cred(const char *ssid, const char *password);
int wifi_set_sta_cred(const char *ssid, const char *password);
void *wifi_manager_get_ap_netif();
void *wifi_manager_get_sta_netif();

View File

@ -10,11 +10,6 @@ typedef struct nvs_wifi_credential_t {
int wifi_data_get_last_conn_cred(wifi_credential_t *ap_credential);
int wifi_get_ap_password_of_ssid(wifi_credential_t *ap_credential);
int wifi_save_ap_credential(wifi_credential_t *ap_credential);
int wifi_rm_ap_credential(const char *ssid);
void wifi_cache_enable(uint8_t en);
#endif //WIFI_STORAGE_H_GUARD