0
0
Fork 0

fix(wifi & uart):

- wifi failed to connect
- uart baud change
This commit is contained in:
windowsair 2022-01-18 22:50:38 +08:00
parent 08d5a81383
commit 89ddfc0603
2 changed files with 15 additions and 8 deletions

View File

@ -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);

View File

@ -3,6 +3,7 @@
#include <sys/param.h>
#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() {