From 89ddfc0603163dcb9e5674bf7c78aa9eac47755b Mon Sep 17 00:00:00 2001 From: windowsair Date: Tue, 18 Jan 2022 22:50:38 +0800 Subject: [PATCH] fix(wifi & uart): - wifi failed to connect - uart baud change --- main/uart_bridge.c | 12 +++++++----- main/wifi_handle.c | 11 ++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/main/uart_bridge.c b/main/uart_bridge.c index e41b3ab..c46a5eb 100644 --- a/main/uart_bridge.c +++ b/main/uart_bridge.c @@ -236,16 +236,18 @@ void uart_bridge_task() { netbuf_data(netbuf, (void *)&buffer, &len_buf); // write to uart if (is_first_time_recv) { // change bard rate - if (len_buf > 2 && buffer[len_buf - 2] == '\r' && buffer[len_buf - 1] == '\n') { - buffer[len_buf - 2] = '\0'; - int baudrate = atoi(buffer); + if (len_buf > 1 && len_buf < 8) { + char tmp_buff[8]; + memcpy(tmp_buff, buffer, len_buf); + tmp_buff[len_buf] = '\0'; + int baudrate = atoi(tmp_buff); if (baudrate > 0 && baudrate < 2000000) { - printf("change bard:%d\r\n", baudrate); + ESP_LOGI(UART_TAG, "change baud:%d\r\n", baudrate); uart_set_baudrate(UART_NUM_0, baudrate); uart_set_baudrate(UART_NUM_1, baudrate); } } - is_first_time_recv = true; + is_first_time_recv = false; } uart_write_bytes(UART_NUM_1, (const char *)buffer, len_buf); } while (netbuf_next(netbuf) >= 0); diff --git a/main/wifi_handle.c b/main/wifi_handle.c index a1ad7ab..9b499cd 100644 --- a/main/wifi_handle.c +++ b/main/wifi_handle.c @@ -3,6 +3,7 @@ #include #include "main/wifi_configuration.h" +#include "main/uart_bridge.h" #include "components/DAP/include/gpio_op.h" @@ -80,17 +81,21 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) { } static void ssid_change() { - wifi_config_t wifi_config; - if (ssid_index > WIFI_LIST_SIZE - 1) { ssid_index = 0; } + wifi_config_t wifi_config = { + .sta = { + .ssid = "", + .password = "", + }, + }; + strcpy((char *)wifi_config.sta.ssid, wifi_list[ssid_index].ssid); strcpy((char *)wifi_config.sta.password, wifi_list[ssid_index].password); ssid_index++; ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config)); - ESP_ERROR_CHECK(esp_wifi_start()); } static void wait_for_ip() {