fix(wifi & uart):
- wifi failed to connect - uart baud change
This commit is contained in:
parent
08d5a81383
commit
89ddfc0603
|
@ -236,16 +236,18 @@ void uart_bridge_task() {
|
||||||
netbuf_data(netbuf, (void *)&buffer, &len_buf);
|
netbuf_data(netbuf, (void *)&buffer, &len_buf);
|
||||||
// write to uart
|
// write to uart
|
||||||
if (is_first_time_recv) { // change bard rate
|
if (is_first_time_recv) { // change bard rate
|
||||||
if (len_buf > 2 && buffer[len_buf - 2] == '\r' && buffer[len_buf - 1] == '\n') {
|
if (len_buf > 1 && len_buf < 8) {
|
||||||
buffer[len_buf - 2] = '\0';
|
char tmp_buff[8];
|
||||||
int baudrate = atoi(buffer);
|
memcpy(tmp_buff, buffer, len_buf);
|
||||||
|
tmp_buff[len_buf] = '\0';
|
||||||
|
int baudrate = atoi(tmp_buff);
|
||||||
if (baudrate > 0 && baudrate < 2000000) {
|
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_0, baudrate);
|
||||||
uart_set_baudrate(UART_NUM_1, 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);
|
uart_write_bytes(UART_NUM_1, (const char *)buffer, len_buf);
|
||||||
} while (netbuf_next(netbuf) >= 0);
|
} while (netbuf_next(netbuf) >= 0);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#include "main/wifi_configuration.h"
|
#include "main/wifi_configuration.h"
|
||||||
|
#include "main/uart_bridge.h"
|
||||||
|
|
||||||
#include "components/DAP/include/gpio_op.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() {
|
static void ssid_change() {
|
||||||
wifi_config_t wifi_config;
|
|
||||||
|
|
||||||
if (ssid_index > WIFI_LIST_SIZE - 1) {
|
if (ssid_index > WIFI_LIST_SIZE - 1) {
|
||||||
ssid_index = 0;
|
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.ssid, wifi_list[ssid_index].ssid);
|
||||||
strcpy((char *)wifi_config.sta.password, wifi_list[ssid_index].password);
|
strcpy((char *)wifi_config.sta.password, wifi_list[ssid_index].password);
|
||||||
ssid_index++;
|
ssid_index++;
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wait_for_ip() {
|
static void wait_for_ip() {
|
||||||
|
|
Loading…
Reference in New Issue