增加网页功能
This commit is contained in:
parent
4b7b1275aa
commit
2c21a0b322
@ -1,2 +1,10 @@
|
||||
idf_component_register(SRCS "usb_serial_echo_main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
|
||||
file(GLOB PORT_SRCS "wifi/*.c" )
|
||||
|
||||
file(GLOB HTML_SRCS "wifi/www/*.html" )
|
||||
|
||||
|
||||
idf_component_register(SRCS "main.c" ${PORT_SRCS}
|
||||
EMBED_FILES ${HTML_SRCS}
|
||||
INCLUDE_DIRS "."
|
||||
INCLUDE_DIRS "wifi/")
|
||||
|
||||
253
main/main.c
253
main/main.c
@ -31,11 +31,8 @@
|
||||
#include "driver/uart.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
static const char *TAG = "uart_events";
|
||||
#include "wifi_task.h"
|
||||
|
||||
#define EXAMPLE_ESP_WIFI_SSID "RONGTA"
|
||||
#define EXAMPLE_ESP_WIFI_PASS "rongta305"
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
|
||||
|
||||
#define EX_UART_NUM UART_NUM_0
|
||||
#define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
|
||||
@ -45,239 +42,8 @@ static const char *TAG = "uart_events";
|
||||
|
||||
#define RD_BUF_SIZE (BUF_SIZE)
|
||||
static QueueHandle_t uart0_queue;
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
static int s_retry_num = 0;
|
||||
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG,"connect to the AP fail");
|
||||
} 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));
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_sta(void)
|
||||
{
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
/* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (password len => 8).
|
||||
* If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
|
||||
* to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
|
||||
* WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
|
||||
*/
|
||||
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
.sae_h2e_identifier = "",
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK(esp_wifi_start() );
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define PORT 23
|
||||
#define KEEPALIVE_IDLE 5
|
||||
#define KEEPALIVE_INTERVAL 5
|
||||
#define KEEPALIVE_COUNT 3
|
||||
|
||||
|
||||
static void do_retransmit(const int sock)
|
||||
{
|
||||
int len;
|
||||
char rx_buffer[128];
|
||||
|
||||
do {
|
||||
len = recv(sock, rx_buffer, sizeof(rx_buffer) - 1, 0);
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG, "Error occurred during receiving: errno %d", errno);
|
||||
} else if (len == 0) {
|
||||
ESP_LOGW(TAG, "Connection closed");
|
||||
} else {
|
||||
rx_buffer[len] = 0; // Null-terminate whatever is received and treat it like a string
|
||||
ESP_LOGI(TAG, "Received %d bytes: %s", len, rx_buffer);
|
||||
// uart_write_bytes(EX_UART_NUM, (const char *) rx_buffer, len);
|
||||
// send() can return less bytes than supplied length.
|
||||
// Walk-around for robust implementation.
|
||||
// int to_write = len;
|
||||
// while (to_write > 0) {
|
||||
// int written = uart_write_bytes(EX_UART_NUM, (const char *) (rx_buffer + (len - to_write)), to_write);
|
||||
// // int written = send(sock, rx_buffer + (len - to_write), to_write, 0);
|
||||
// // if (written < 0) {
|
||||
// // ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno);
|
||||
// // // Failed to retransmit, giving up
|
||||
// // return;
|
||||
// // }
|
||||
// to_write -= written;
|
||||
// }
|
||||
}
|
||||
} while (len > 0);
|
||||
}
|
||||
static int sock;
|
||||
static void tcp_server_task(void *pvParameters)
|
||||
{
|
||||
char addr_str[128];
|
||||
int addr_family = (int)pvParameters;
|
||||
int ip_protocol = 0;
|
||||
int keepAlive = 1;
|
||||
int keepIdle = KEEPALIVE_IDLE;
|
||||
int keepInterval = KEEPALIVE_INTERVAL;
|
||||
int keepCount = KEEPALIVE_COUNT;
|
||||
struct sockaddr_storage dest_addr;
|
||||
|
||||
#ifdef CONFIG_LWIP_IPV4
|
||||
if (addr_family == AF_INET) {
|
||||
struct sockaddr_in *dest_addr_ip4 = (struct sockaddr_in *)&dest_addr;
|
||||
dest_addr_ip4->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
dest_addr_ip4->sin_family = AF_INET;
|
||||
dest_addr_ip4->sin_port = htons(PORT);
|
||||
ip_protocol = IPPROTO_IP;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
if (addr_family == AF_INET6) {
|
||||
struct sockaddr_in6 *dest_addr_ip6 = (struct sockaddr_in6 *)&dest_addr;
|
||||
bzero(&dest_addr_ip6->sin6_addr.un, sizeof(dest_addr_ip6->sin6_addr.un));
|
||||
dest_addr_ip6->sin6_family = AF_INET6;
|
||||
dest_addr_ip6->sin6_port = htons(PORT);
|
||||
ip_protocol = IPPROTO_IPV6;
|
||||
}
|
||||
#endif
|
||||
|
||||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0) {
|
||||
ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
int opt = 1;
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||
#if defined(CONFIG_EXAMPLE_IPV4) && defined(CONFIG_EXAMPLE_IPV6)
|
||||
// Note that by default IPV6 binds to both protocols, it is must be disabled
|
||||
// if both protocols used at the same time (used in CI)
|
||||
setsockopt(listen_sock, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Socket created");
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
|
||||
if (err != 0) {
|
||||
ESP_LOGE(TAG, "Socket unable to bind: errno %d", errno);
|
||||
ESP_LOGE(TAG, "IPPROTO: %d", addr_family);
|
||||
goto CLEAN_UP;
|
||||
}
|
||||
ESP_LOGI(TAG, "Socket bound, port %d", PORT);
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0) {
|
||||
ESP_LOGE(TAG, "Error occurred during listen: errno %d", errno);
|
||||
goto CLEAN_UP;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
||||
ESP_LOGI(TAG, "Socket listening");
|
||||
|
||||
struct sockaddr_storage source_addr; // Large enough for both IPv4 or IPv6
|
||||
socklen_t addr_len = sizeof(source_addr);
|
||||
sock = accept(listen_sock, (struct sockaddr *)&source_addr, &addr_len);
|
||||
if (sock < 0) {
|
||||
ESP_LOGE(TAG, "Unable to accept connection: errno %d", errno);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set tcp keepalive option
|
||||
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &keepAlive, sizeof(int));
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &keepIdle, sizeof(int));
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &keepInterval, sizeof(int));
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &keepCount, sizeof(int));
|
||||
// Convert ip address to string
|
||||
#ifdef CONFIG_EXAMPLE_IPV4
|
||||
if (source_addr.ss_family == PF_INET) {
|
||||
inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr, addr_str, sizeof(addr_str) - 1);
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
if (source_addr.ss_family == PF_INET6) {
|
||||
inet6_ntoa_r(((struct sockaddr_in6 *)&source_addr)->sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
}
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Socket accepted ip address: %s", addr_str);
|
||||
|
||||
do_retransmit(sock);
|
||||
|
||||
shutdown(sock, 0);
|
||||
close(sock);
|
||||
}
|
||||
|
||||
CLEAN_UP:
|
||||
close(listen_sock);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
static const char *TAG = "main";
|
||||
|
||||
|
||||
static void echo_task(void *arg)
|
||||
@ -420,18 +186,21 @@ void app_main(void)
|
||||
};
|
||||
// ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, 4, 5, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
//Install UART driver, and get the queue.
|
||||
uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
|
||||
uart_param_config(EX_UART_NUM, &uart_config);
|
||||
xTaskCreate(echo_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
|
||||
// uart_driver_install(EX_UART_NUM, BUF_SIZE * 2, BUF_SIZE * 2, 20, &uart0_queue, 0);
|
||||
// uart_param_config(EX_UART_NUM, &uart_config);
|
||||
// xTaskCreate(echo_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
|
||||
//Create a task to handler UART event from ISR
|
||||
xTaskCreate(uart_event_task, "uart_event_task", 2048*10, NULL, 12, NULL);
|
||||
// xTaskCreate(uart_event_task, "uart_event_task", 2048*10, NULL, 12, NULL);
|
||||
|
||||
// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||
// wifi_init_sta();
|
||||
wifi_init_softap();
|
||||
|
||||
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||
start_web_server();
|
||||
// xTaskCreate(tcp_server_task, "tcp_server", 4096, (void*)AF_INET, 5, NULL);
|
||||
|
||||
|
||||
#if 0
|
||||
const loader_esp32_config_t config = {
|
||||
.baud_rate = 115200,
|
||||
.uart_port = UART_NUM_1,
|
||||
@ -452,5 +221,5 @@ void app_main(void)
|
||||
}else{
|
||||
ESP_LOGE(TAG, "connect_to_target initialization failed.");
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
70
main/wifi/wifi_ap.c
Normal file
70
main/wifi/wifi_ap.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include "wifi_task.h"
|
||||
|
||||
static const char *TAG = "wifi softAP";
|
||||
|
||||
#define EXAMPLE_ESP_WIFI_SSID "ESP32_Online_Link"
|
||||
#define EXAMPLE_ESP_WIFI_PASS "12345678"
|
||||
#define EXAMPLE_ESP_WIFI_CHANNEL 1
|
||||
#define EXAMPLE_MAX_STA_CONN 4
|
||||
|
||||
|
||||
static void wifi_event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
|
||||
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
|
||||
ESP_LOGI(TAG, "station "MACSTR" join, AID=%d",
|
||||
MAC2STR(event->mac), event->aid);
|
||||
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
|
||||
wifi_event_ap_stadisconnected_t* event = (wifi_event_ap_stadisconnected_t*) event_data;
|
||||
ESP_LOGI(TAG, "station "MACSTR" leave, AID=%d, reason=%d",
|
||||
MAC2STR(event->mac), event->aid, event->reason);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_softap(void)
|
||||
{
|
||||
// ESP_ERROR_CHECK(esp_netif_init());
|
||||
// ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_create_default_wifi_ap();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&wifi_event_handler,
|
||||
NULL,
|
||||
NULL));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.ap = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.ssid_len = strlen(EXAMPLE_ESP_WIFI_SSID),
|
||||
.channel = EXAMPLE_ESP_WIFI_CHANNEL,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
.max_connection = EXAMPLE_MAX_STA_CONN,
|
||||
#ifdef CONFIG_ESP_WIFI_SOFTAP_SAE_SUPPORT
|
||||
.authmode = WIFI_AUTH_WPA3_PSK,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
#else /* CONFIG_ESP_WIFI_SOFTAP_SAE_SUPPORT */
|
||||
.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
#endif
|
||||
.pmf_cfg = {
|
||||
.required = true,
|
||||
},
|
||||
},
|
||||
};
|
||||
if (strlen(EXAMPLE_ESP_WIFI_PASS) == 0) {
|
||||
wifi_config.ap.authmode = WIFI_AUTH_OPEN;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_softap finished. SSID:%s password:%s channel:%d",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS, EXAMPLE_ESP_WIFI_CHANNEL);
|
||||
}
|
||||
|
||||
|
||||
296
main/wifi/wifi_html.c
Normal file
296
main/wifi/wifi_html.c
Normal file
@ -0,0 +1,296 @@
|
||||
#include "wifi_task.h"
|
||||
#include "esp_http_server.h"
|
||||
#include "esp_vfs.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
static const char *TAG = "wifi_html";
|
||||
|
||||
|
||||
static esp_err_t index_get_handler(httpd_req_t *req)
|
||||
{
|
||||
extern const unsigned char wifi_config_start[] asm("_binary_wifi_html_start");
|
||||
extern const unsigned char wifi_config_end[] asm("_binary_wifi_html_end");
|
||||
const size_t wifi_config_size = (wifi_config_end - wifi_config_start);
|
||||
|
||||
/* Add file upload form and script which on execution sends a POST request to /upload */
|
||||
httpd_resp_set_type(req,HTTPD_TYPE_TEXT);
|
||||
httpd_resp_send(req, (const char *)wifi_config_start, wifi_config_size);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t Home_get_handler(httpd_req_t *req)
|
||||
{
|
||||
extern const unsigned char home_start[] asm("_binary_home_html_start");
|
||||
extern const unsigned char home_end[] asm("_binary_home_html_end");
|
||||
const size_t home_size = (home_end - home_start);
|
||||
|
||||
/* Add file upload form and script which on execution sends a POST request to /upload */
|
||||
httpd_resp_set_type(req,HTTPD_TYPE_TEXT);
|
||||
httpd_resp_send(req, (const char *)home_start, home_size);
|
||||
return ESP_OK;
|
||||
|
||||
}
|
||||
|
||||
static esp_err_t upgrade_ota_bin(httpd_req_t *req)
|
||||
{
|
||||
extern const unsigned char upload_script_start[] asm("_binary_upload_script_html_start");
|
||||
extern const unsigned char upload_script_end[] asm("_binary_upload_script_html_end");
|
||||
const size_t upload_script_size = (upload_script_end - upload_script_start);
|
||||
|
||||
/* Add file upload form and script which on execution sends a POST request to /upload */
|
||||
httpd_resp_set_type(req,HTTPD_TYPE_TEXT);
|
||||
httpd_resp_send(req, (const char *)upload_script_start, upload_script_size);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t Save_file_handler(httpd_req_t *req)
|
||||
{
|
||||
|
||||
extern const unsigned char file_server_start[] asm("_binary_file_server_html_start");
|
||||
extern const unsigned char file_server_end[] asm("_binary_file_server_html_end");
|
||||
const size_t file_server_size = (file_server_end - file_server_start);
|
||||
|
||||
/* Add file upload form and script which on execution sends a POST request to /upload */
|
||||
httpd_resp_set_type(req,HTTPD_TYPE_TEXT);
|
||||
httpd_resp_send(req, (const char *)file_server_start, file_server_size);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
char wifi_name[20] = {0};
|
||||
char wifi_password[12] = {0};
|
||||
static esp_err_t echo_post_handler(httpd_req_t *req)
|
||||
{
|
||||
char buf[100];
|
||||
// char ssid[10];
|
||||
// char pswd[10];
|
||||
bool wifi_write = false;
|
||||
int ret, remaining = req->content_len;
|
||||
ESP_LOGI(TAG,"req->content_len:%d",req->content_len);
|
||||
while (remaining > 0) {
|
||||
/* Read the data for the request */
|
||||
if ((ret = httpd_req_recv(req, buf,
|
||||
MIN(remaining, sizeof(buf)))) <= 0) {
|
||||
if (ret == HTTPD_SOCK_ERR_TIMEOUT) {
|
||||
/* Retry receiving if timeout occurred */
|
||||
continue;
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Send back the same data */
|
||||
httpd_resp_send_chunk(req, buf, ret);
|
||||
remaining -= ret;
|
||||
|
||||
cJSON *root = cJSON_Parse(buf);
|
||||
// int ssid = cJSON_GetObjectItem(root, "wifi_name")->valueint;
|
||||
// int code = cJSON_GetObjectItem(root, "wifi_code")->valueint;
|
||||
|
||||
char *ssid = cJSON_GetObjectItem(root, "wifi_name")->valuestring;
|
||||
char *code = cJSON_GetObjectItem(root, "wifi_code")->valuestring;
|
||||
int len1 = strlen(ssid);
|
||||
int len2 = strlen(code);
|
||||
memcpy(wifi_name,ssid,strlen(ssid));
|
||||
memcpy(wifi_password,code,strlen(code));
|
||||
wifi_name[len1] = '\0';
|
||||
wifi_password[len2] = '\0';
|
||||
cJSON_Delete(root);
|
||||
// ESP_LOGI(TAG, "json load finished. SSID:%d password:%d ",ssid,code);
|
||||
// ESP_LOGI(TAG, "json load finished. SSID:%s password:%s ",user_id,user_code);
|
||||
printf("\r\nwifi_ssid:");
|
||||
for(int i = 0;i<len1;i++){
|
||||
printf("%c",wifi_name[i]);
|
||||
}
|
||||
|
||||
printf("\r\nwifi_code:");
|
||||
for(int i = 0;i<len2;i++){
|
||||
printf("%c",wifi_password[i]);
|
||||
}
|
||||
|
||||
// esp_err_t e = httpd_query_key_value(buf,"wifi_name",wifi_name,sizeof(wifi_name));
|
||||
// if(e == ESP_OK) {
|
||||
// printf("ssid = %s\r\n",wifi_name);
|
||||
// }
|
||||
// else {
|
||||
// printf("error = %d\r\n",e);
|
||||
// }
|
||||
|
||||
// e = httpd_query_key_value(buf,"wifi_code",wifi_password,sizeof(wifi_password));
|
||||
// if(e == ESP_OK) {
|
||||
// printf("pswd = %s\r\n",wifi_password);
|
||||
// }
|
||||
// else {
|
||||
// printf("error = %d\r\n",e);
|
||||
// }
|
||||
// sprintf(esp_wifi_info.ssid,"%s",wifi_name);
|
||||
// sprintf(esp_wifi_info.password,"%s",wifi_password);
|
||||
// esp_wifi_info.reboot = false;
|
||||
// wifi_config_data.SubType = 0x40;
|
||||
// wifi_config_data.addr = 0;
|
||||
// Write_ESPFlash(wifi_config_data.SubType,wifi_config_data.addr,(uint8_t *)&wifi_config_data,sizeof(struct save_flash_t) + sizeof(wifi_info_t));
|
||||
|
||||
/* Log data received */
|
||||
ESP_LOGI(TAG, "=========== RECEIVED DATA ==========");
|
||||
ESP_LOGI(TAG, "%.*s", ret, buf);
|
||||
ESP_LOGI(TAG, "====================================");
|
||||
ESP_LOGI(TAG, "Prepare to restart system!");
|
||||
wifi_write = true;
|
||||
}
|
||||
|
||||
// End response
|
||||
httpd_resp_send_chunk(req, NULL, 0);
|
||||
if(strcmp(wifi_name ,"\0")!=0 && strcmp(wifi_password,"\0")!=0)
|
||||
{
|
||||
//xSemaphoreGive(ap_sem);
|
||||
// ESP_LOGI(TAG,"ssid:%s password:%s",esp_wifi_info.ssid,esp_wifi_info.password);
|
||||
ESP_LOGI(TAG, "set wifi name and password successfully! goto station mode");
|
||||
if(wifi_write == true)esp_restart();
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
static esp_err_t upgrade_post_handler(httpd_req_t *req)
|
||||
{
|
||||
int remaining = req->content_len;
|
||||
char* buff;
|
||||
uint16_t received = 0;
|
||||
|
||||
//ota_bin_data.buf = malloc(8192);
|
||||
|
||||
ESP_LOGI(TAG,"req->url:%s",req->uri);
|
||||
ESP_LOGI(TAG,"req->content_len:%d",req->content_len);
|
||||
// if(Search_Binfile(req->uri,strlen(req->uri)) == true)
|
||||
// {
|
||||
// //ESP_LOGI(TAG,"received:%d",received);
|
||||
// buff = (char*)ota_tx_data.data;
|
||||
// ota_tx_data.type = TYPE_MES_HEAD;
|
||||
// ota_tx_data.size = req->content_len;
|
||||
// xQueueSend(ota_data_queue, &ota_tx_data, portMAX_DELAY);
|
||||
// xEventGroupSetBits(esp_event_group,OTA_EVENT);
|
||||
// while (remaining > 0)
|
||||
// {
|
||||
// if ((received = httpd_req_recv(req, &buff[0], MIN(remaining, 4096))))
|
||||
// {
|
||||
// ota_tx_data.type = TYPE_WIFI_HTTP;
|
||||
// // ota_bin_data.buf[received] = '\0';
|
||||
// ota_tx_data.size = received;
|
||||
// //ESP_LOGI(TAG,"received:%d %c",received,http_file_data.buf[0]);
|
||||
// xQueueSend(ota_data_queue, &ota_tx_data, portMAX_DELAY);
|
||||
// remaining -= received;
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// buff = http_file_data.buff;
|
||||
// sprintf(http_file_data.file_name,req->uri);
|
||||
// http_file_data.type = TYPE_START_OTA;
|
||||
// http_file_data.file_size = req->content_len;
|
||||
// xQueueSend(web_data_queue, &http_file_data, portMAX_DELAY);
|
||||
// while (remaining > 0)
|
||||
// {
|
||||
// if ((received = httpd_req_recv(req, &buff[0], MIN(remaining, 8192))))
|
||||
// {
|
||||
// http_file_data.type = TYPE_START_OTA|TYPE_DATA;
|
||||
// // ota_bin_data.buf[received] = '\0';
|
||||
// http_file_data.buff_size = received;
|
||||
// //ESP_LOGI(TAG,"received:%d %c",received,http_file_data.buf[0]);
|
||||
// xQueueSend(web_data_queue, &http_file_data, portMAX_DELAY);
|
||||
// remaining -= received;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
//free(ota_bin_data.buf);
|
||||
ESP_LOGI(TAG,"upgrade ok %d",remaining);
|
||||
/* Redirect onto root to see the updated file list */
|
||||
httpd_resp_set_status(req, "303 See Other");
|
||||
httpd_resp_set_hdr(req, "Location", "/ota");
|
||||
httpd_resp_sendstr(req, "File uploaded successfully");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/* Scratch buffer size */
|
||||
#define SCRATCH_BUFSIZE 8192
|
||||
|
||||
struct file_server_data {
|
||||
/* Base path of file storage */
|
||||
char base_path[ESP_VFS_PATH_MAX + 1];
|
||||
|
||||
/* Scratch buffer for temporary storage during file transfer */
|
||||
char scratch[SCRATCH_BUFSIZE];
|
||||
};
|
||||
|
||||
esp_err_t start_web_server(void)
|
||||
{
|
||||
static struct file_server_data *server_data = NULL;
|
||||
/* Allocate memory for server data */
|
||||
server_data = calloc(1, sizeof(struct file_server_data));
|
||||
if (!server_data) {
|
||||
ESP_LOGE(TAG, "Failed to allocate memory for server data");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
strlcpy(server_data->base_path, "/data",
|
||||
sizeof(server_data->base_path));
|
||||
httpd_handle_t server = NULL;
|
||||
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
|
||||
/* Use the URI wildcard matching function in order to
|
||||
* allow the same handler to respond to multiple different
|
||||
* target URIs which match the wildcard scheme */
|
||||
|
||||
config.uri_match_fn = httpd_uri_match_wildcard;
|
||||
|
||||
ESP_LOGI(TAG, "Starting HTTP Server");
|
||||
if (httpd_start(&server, &config) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to start file server!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
//start_file_server("/sdcard",server);
|
||||
//return ESP_OK;
|
||||
httpd_uri_t index_page = {
|
||||
.uri = "/", //192.168.1.4
|
||||
.method = HTTP_GET,
|
||||
.handler = Home_get_handler,
|
||||
/* Let's pass response string in user
|
||||
* context to demonstrate it's usage */
|
||||
.user_ctx = server_data
|
||||
};
|
||||
httpd_register_uri_handler(server, &index_page);
|
||||
// httpd_uri_t upgrade_ota = {
|
||||
// .uri = "/ota", //192.168.1.4
|
||||
// .method = HTTP_GET,
|
||||
// .handler = upgrade_ota_bin,
|
||||
// /* Let's pass response string in user
|
||||
// * context to demonstrate it's usage */
|
||||
// .user_ctx = NULL,
|
||||
// };
|
||||
// httpd_register_uri_handler(server, &upgrade_ota);
|
||||
|
||||
httpd_uri_t home_page = {
|
||||
.uri = "/config", //192.168.1.4
|
||||
.method = HTTP_GET,
|
||||
.handler = index_get_handler,
|
||||
/* Let's pass response string in user
|
||||
* context to demonstrate it's usage */
|
||||
.user_ctx = NULL,
|
||||
};
|
||||
httpd_register_uri_handler(server, &home_page);
|
||||
|
||||
httpd_uri_t echo = {
|
||||
.uri = "/config",
|
||||
.method = HTTP_POST,
|
||||
.handler = echo_post_handler,
|
||||
.user_ctx = server_data,
|
||||
};
|
||||
httpd_register_uri_handler(server, &echo);
|
||||
|
||||
// static const httpd_uri_t upgrade_post = {
|
||||
// .uri = "/upload/*",
|
||||
// .method = HTTP_POST,
|
||||
// .handler = upgrade_post_handler,
|
||||
// .user_ctx = NULL
|
||||
// };
|
||||
// httpd_register_uri_handler(server, &upgrade_post);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
116
main/wifi/wifi_sta.c
Normal file
116
main/wifi/wifi_sta.c
Normal file
@ -0,0 +1,116 @@
|
||||
#include "wifi_task.h"
|
||||
|
||||
|
||||
static const char *TAG = "wifi_sta";
|
||||
|
||||
#define EXAMPLE_ESP_WIFI_SSID "Yu886"
|
||||
#define EXAMPLE_ESP_WIFI_PASS "2023yu2023"
|
||||
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
|
||||
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected*/
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
static int s_retry_num = 0;
|
||||
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
|
||||
|
||||
static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
}
|
||||
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
|
||||
{
|
||||
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
|
||||
{
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAG, "retry to connect to the AP");
|
||||
}
|
||||
else
|
||||
{
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGI(TAG, "connect to the AP fail");
|
||||
}
|
||||
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));
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_station(void)
|
||||
{
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
esp_netif_create_default_wifi_sta();
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = EXAMPLE_ESP_WIFI_SSID,
|
||||
.password = EXAMPLE_ESP_WIFI_PASS,
|
||||
/* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (password len => 8).
|
||||
* If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value
|
||||
* to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to
|
||||
* WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.
|
||||
*/
|
||||
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
|
||||
.sae_pwe_h2e = WPA3_SAE_PWE_BOTH,
|
||||
.sae_h2e_identifier = "",
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT)
|
||||
{
|
||||
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
}
|
||||
else if (bits & WIFI_FAIL_BIT)
|
||||
{
|
||||
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
|
||||
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGE(TAG, "UNEXPECTED EVENT");
|
||||
}
|
||||
}
|
||||
142
main/wifi/wifi_task.c
Normal file
142
main/wifi/wifi_task.c
Normal file
@ -0,0 +1,142 @@
|
||||
#include "wifi_task.h"
|
||||
|
||||
static const char *TAG = "wifi_task";
|
||||
|
||||
#define PORT 23
|
||||
#define KEEPALIVE_IDLE 5
|
||||
#define KEEPALIVE_INTERVAL 5
|
||||
#define KEEPALIVE_COUNT 3
|
||||
|
||||
|
||||
static void do_retransmit(const int sock)
|
||||
{
|
||||
int len;
|
||||
char rx_buffer[128];
|
||||
|
||||
do {
|
||||
len = recv(sock, rx_buffer, sizeof(rx_buffer) - 1, 0);
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG, "Error occurred during receiving: errno %d", errno);
|
||||
} else if (len == 0) {
|
||||
ESP_LOGW(TAG, "Connection closed");
|
||||
} else {
|
||||
rx_buffer[len] = 0; // Null-terminate whatever is received and treat it like a string
|
||||
ESP_LOGI(TAG, "Received %d bytes: %s", len, rx_buffer);
|
||||
// uart_write_bytes(EX_UART_NUM, (const char *) rx_buffer, len);
|
||||
// send() can return less bytes than supplied length.
|
||||
// Walk-around for robust implementation.
|
||||
// int to_write = len;
|
||||
// while (to_write > 0) {
|
||||
// int written = uart_write_bytes(EX_UART_NUM, (const char *) (rx_buffer + (len - to_write)), to_write);
|
||||
// // int written = send(sock, rx_buffer + (len - to_write), to_write, 0);
|
||||
// // if (written < 0) {
|
||||
// // ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno);
|
||||
// // // Failed to retransmit, giving up
|
||||
// // return;
|
||||
// // }
|
||||
// to_write -= written;
|
||||
// }
|
||||
}
|
||||
} while (len > 0);
|
||||
}
|
||||
static int sock;
|
||||
static void tcp_server_task(void *pvParameters)
|
||||
{
|
||||
char addr_str[128];
|
||||
int addr_family = (int)pvParameters;
|
||||
int ip_protocol = 0;
|
||||
int keepAlive = 1;
|
||||
int keepIdle = KEEPALIVE_IDLE;
|
||||
int keepInterval = KEEPALIVE_INTERVAL;
|
||||
int keepCount = KEEPALIVE_COUNT;
|
||||
struct sockaddr_storage dest_addr;
|
||||
|
||||
#ifdef CONFIG_LWIP_IPV4
|
||||
if (addr_family == AF_INET) {
|
||||
struct sockaddr_in *dest_addr_ip4 = (struct sockaddr_in *)&dest_addr;
|
||||
dest_addr_ip4->sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
dest_addr_ip4->sin_family = AF_INET;
|
||||
dest_addr_ip4->sin_port = htons(PORT);
|
||||
ip_protocol = IPPROTO_IP;
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
if (addr_family == AF_INET6) {
|
||||
struct sockaddr_in6 *dest_addr_ip6 = (struct sockaddr_in6 *)&dest_addr;
|
||||
bzero(&dest_addr_ip6->sin6_addr.un, sizeof(dest_addr_ip6->sin6_addr.un));
|
||||
dest_addr_ip6->sin6_family = AF_INET6;
|
||||
dest_addr_ip6->sin6_port = htons(PORT);
|
||||
ip_protocol = IPPROTO_IPV6;
|
||||
}
|
||||
#endif
|
||||
|
||||
int listen_sock = socket(addr_family, SOCK_STREAM, ip_protocol);
|
||||
if (listen_sock < 0) {
|
||||
ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
|
||||
vTaskDelete(NULL);
|
||||
return;
|
||||
}
|
||||
int opt = 1;
|
||||
setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
|
||||
#if defined(CONFIG_EXAMPLE_IPV4) && defined(CONFIG_EXAMPLE_IPV6)
|
||||
// Note that by default IPV6 binds to both protocols, it is must be disabled
|
||||
// if both protocols used at the same time (used in CI)
|
||||
setsockopt(listen_sock, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Socket created");
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
|
||||
if (err != 0) {
|
||||
ESP_LOGE(TAG, "Socket unable to bind: errno %d", errno);
|
||||
ESP_LOGE(TAG, "IPPROTO: %d", addr_family);
|
||||
goto CLEAN_UP;
|
||||
}
|
||||
ESP_LOGI(TAG, "Socket bound, port %d", PORT);
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0) {
|
||||
ESP_LOGE(TAG, "Error occurred during listen: errno %d", errno);
|
||||
goto CLEAN_UP;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
||||
ESP_LOGI(TAG, "Socket listening");
|
||||
|
||||
struct sockaddr_storage source_addr; // Large enough for both IPv4 or IPv6
|
||||
socklen_t addr_len = sizeof(source_addr);
|
||||
sock = accept(listen_sock, (struct sockaddr *)&source_addr, &addr_len);
|
||||
if (sock < 0) {
|
||||
ESP_LOGE(TAG, "Unable to accept connection: errno %d", errno);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set tcp keepalive option
|
||||
setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &keepAlive, sizeof(int));
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_KEEPIDLE, &keepIdle, sizeof(int));
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, &keepInterval, sizeof(int));
|
||||
setsockopt(sock, IPPROTO_TCP, TCP_KEEPCNT, &keepCount, sizeof(int));
|
||||
// Convert ip address to string
|
||||
#ifdef CONFIG_EXAMPLE_IPV4
|
||||
if (source_addr.ss_family == PF_INET) {
|
||||
inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr, addr_str, sizeof(addr_str) - 1);
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
if (source_addr.ss_family == PF_INET6) {
|
||||
inet6_ntoa_r(((struct sockaddr_in6 *)&source_addr)->sin6_addr, addr_str, sizeof(addr_str) - 1);
|
||||
}
|
||||
#endif
|
||||
ESP_LOGI(TAG, "Socket accepted ip address: %s", addr_str);
|
||||
|
||||
do_retransmit(sock);
|
||||
|
||||
shutdown(sock, 0);
|
||||
close(sock);
|
||||
}
|
||||
|
||||
CLEAN_UP:
|
||||
close(listen_sock);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
34
main/wifi/wifi_task.h
Normal file
34
main/wifi/wifi_task.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef WIFI_TASK_H
|
||||
#define WIFI_TASK_H
|
||||
|
||||
#include "stdio.h"
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_mac.h"
|
||||
|
||||
#include "nvs_flash.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/sys.h"
|
||||
#include <lwip/netdb.h>
|
||||
|
||||
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "driver/uart.h"
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
void wifi_init_station(void);
|
||||
void wifi_init_softap(void);
|
||||
esp_err_t start_web_server(void);
|
||||
|
||||
#endif
|
||||
80
main/wifi/www/file_server.html
Normal file
80
main/wifi/www/file_server.html
Normal file
@ -0,0 +1,80 @@
|
||||
<table class="fixed" border="0">
|
||||
<col width="1000px" /><col width="500px" />
|
||||
<tr><td>
|
||||
<h2>ESP32 File Server</h2>
|
||||
</td><td>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="newfile">Upload a file</label>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<input id="newfile" type="file" onchange="setpath()" style="width:100%;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="filepath">Set path on server</label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="filepath" type="text" style="width:100%;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
<script>
|
||||
function setpath() {
|
||||
var default_path = document.getElementById("newfile").files[0].name;
|
||||
document.getElementById("filepath").value = default_path;
|
||||
}
|
||||
function upload() {
|
||||
var filePath = document.getElementById("filepath").value;
|
||||
var upload_path = "/save_file/" + filePath;
|
||||
var fileInput = document.getElementById("newfile").files;
|
||||
|
||||
/* Max size of an individual file. Make sure this
|
||||
* value is same as that set in file_server.c */
|
||||
var MAX_FILE_SIZE = 2000*1024;
|
||||
var MAX_FILE_SIZE_STR = "2000KB";
|
||||
|
||||
if (fileInput.length == 0) {
|
||||
alert("No file selected!");
|
||||
} else if (filePath.length == 0) {
|
||||
alert("File path on server is not set!");
|
||||
} else if (filePath.indexOf(' ') >= 0) {
|
||||
alert("File path on server cannot have spaces!");
|
||||
} else if (filePath[filePath.length-1] == '/') {
|
||||
alert("File name not specified after path!");
|
||||
} else if (fileInput[0].size > 2000*1024) {
|
||||
alert("File size must be less than 2000KB!");
|
||||
} else {
|
||||
document.getElementById("newfile").disabled = true;
|
||||
document.getElementById("filepath").disabled = true;
|
||||
document.getElementById("upload").disabled = true;
|
||||
|
||||
var file = fileInput[0];
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (xhttp.readyState == 4) {
|
||||
if (xhttp.status == 200) {
|
||||
document.open();
|
||||
document.write(xhttp.responseText);
|
||||
document.close();
|
||||
} else if (xhttp.status == 0) {
|
||||
alert("Server closed the connection abruptly!");
|
||||
location.reload()
|
||||
} else {
|
||||
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||
location.reload()
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.open("POST", upload_path, true);
|
||||
xhttp.send(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
96
main/wifi/www/home.html
Normal file
96
main/wifi/www/home.html
Normal file
@ -0,0 +1,96 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
||||
<title>在线配置</title>
|
||||
<style type="text/css">
|
||||
* { margin: 0; padding: 0; }
|
||||
html { height: 100%; }
|
||||
h2 {text-align: center;color: #fff;line-height: 2.2;}
|
||||
body { height: 100%; background-color: #1F6F4A; 50% 50% no-repeat; background-size: cover;}
|
||||
.dowebok { position: absolute; left: 50%; top: 30%; width: 380px; height: 500px; margin: -200px 0 0 -200px; border: 3px solid #fff; border-radius: 10px; overflow: hidden;}
|
||||
|
||||
.form-item { position: relative; width: 360px; margin: 0 auto; padding-bottom: 20px;}
|
||||
.form-item input { width: 288px; height: 48px; padding-left: 10px; border: 1px solid #fff; border-radius: 25px; font-size: 18px; color: #fff; background-color: transparent; outline: none;}
|
||||
.send_button { width: 360px; height: 50px; border: 0; border-radius: 25px; font-size: 18px; color: #1f6f4a; outline: none; cursor: pointer; background-color: #fff; }
|
||||
|
||||
.tip { display: none; position: absolute; left: 20px; top: 52px; font-size: 14px; color: #f50; }
|
||||
.reg-bar { width: 360px; margin: 20px auto 0; font-size: 14px; overflow: hidden;}
|
||||
.reg-bar a { color: #fff; text-decoration: none; }
|
||||
.reg-bar a:hover { text-decoration: underline; }
|
||||
.reg-bar .reg { float: left; }
|
||||
.reg-bar .forget { float: right; }
|
||||
.dowebok ::-webkit-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok ::-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-ms-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
* { box-sizing: border-box; }
|
||||
.dowebok { position: static; width: auto; height: auto; margin: 0 30px; border: 0; border-radius: 0; }
|
||||
.logo { margin: 50px auto; }
|
||||
.form-item { width: auto; }
|
||||
.form-item input, .form-item button, .reg-bar { width: 100%; }
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="dowebok">
|
||||
<h2>ESP32 Web 在 线 工 具</h2>
|
||||
<form style='text-align: center;padding-top: 20px' name='input' action='/' method='POST'>
|
||||
<!-- <div class="form-item">
|
||||
<input id="username" type="text" name='ssid' autocomplete="off" placeholder="WiFi名称">
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<input id="password" type="password" name='password' autocomplete="off" placeholder="WiFi密码">
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<input id="retry" type="text" name='retry' autocomplete="off" placeholder="重连次数">
|
||||
</div> -->
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="Online_distribution_network" type="button" value='在线配网' onclick="location.href='/config'">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="Online_OTA_bin" type='button' value='在线OTA' onclick="location.href='/ota'">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="Online_Send_file" type='button' value='在线传输文件' onclick="location.href='/file'">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="send_button" type='submit' value='系统配置'>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="user_text">
|
||||
<br>
|
||||
<!-- <p><h3>如何获取cityCode:</h3></p> -->
|
||||
<!-- <p>
|
||||
<h5>
|
||||
1
|
||||
</h5>
|
||||
</p>
|
||||
<p>
|
||||
<h5>
|
||||
2
|
||||
</h5>
|
||||
</p> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
129
main/wifi/www/upload_script.html
Normal file
129
main/wifi/www/upload_script.html
Normal file
@ -0,0 +1,129 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
||||
<title>在线配置</title>
|
||||
<style type="text/css">
|
||||
* { margin: 0; padding: 0; }
|
||||
html { height: 100%; }
|
||||
h2 {text-align: center;color: #fff;line-height: 2.2;}
|
||||
body { height: 100%; background-color: #1F6F4A; 50% 50% no-repeat; background-size: cover;}
|
||||
.dowebok { position: absolute; left: 50%; top: 30%; width: 380px; height: 500px; margin: -200px 0 0 -200px; border: 3px solid #fff; border-radius: 10px; overflow: hidden;}
|
||||
|
||||
.form-item { position: relative; width: 360px; margin: 0 auto; padding-bottom: 20px;}
|
||||
.form-item input { width: 288px; height: 48px; padding-left: 10px; border: 1px solid #fff; border-radius: 25px; font-size: 18px; color: #fff; background-color: transparent; outline: none;}
|
||||
.send_button { width: 360px; height: 50px; border: 0; border-radius: 25px; font-size: 18px; color: #1f6f4a; outline: none; cursor: pointer; background-color: #fff; }
|
||||
|
||||
.tip { display: none; position: absolute; left: 20px; top: 52px; font-size: 14px; color: #f50; }
|
||||
.reg-bar { width: 360px; margin: 20px auto 0; font-size: 14px; overflow: hidden;}
|
||||
.reg-bar a { color: #fff; text-decoration: none; }
|
||||
.reg-bar a:hover { text-decoration: underline; }
|
||||
.reg-bar .reg { float: left; }
|
||||
.reg-bar .forget { float: right; }
|
||||
.dowebok ::-webkit-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok ::-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-ms-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
* { box-sizing: border-box; }
|
||||
.dowebok { position: static; width: auto; height: auto; margin: 0 30px; border: 0; border-radius: 0; }
|
||||
.logo { margin: 50px auto; }
|
||||
.form-item { width: auto; }
|
||||
.form-item input, .form-item button, .reg-bar { width: 100%; }
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="dowebok">
|
||||
<h2>ESP32S2 OTA Bin Server</h2>
|
||||
<!-- <table border="0">
|
||||
|
||||
</table> -->
|
||||
<tr>
|
||||
<td>
|
||||
<label for="newfile">Upload a file</label>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<input id="newfile" type="file" accept=".bin" onchange="setpath()" style="width:100%;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="filepath">Set path on server </label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="filepath" type="text" style="width:100%;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- <form style='text-align: center;padding-top: 20px' action='/ota' method='POST'>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
</td>
|
||||
</form> -->
|
||||
<form style='text-align: center;padding-top: 20px' name='input' action='/config' method='POST'>
|
||||
<div class="form-item">
|
||||
<div id="">
|
||||
<input id="return_page" type='button' value='返回' onclick="location.href='/'">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
function setpath() {
|
||||
var default_path = document.getElementById("newfile").files[0].name;
|
||||
document.getElementById("filepath").value = default_path;
|
||||
}
|
||||
function upload() {
|
||||
var filePath = document.getElementById("filepath").value;
|
||||
var upload_path = "/upload/" + filePath;
|
||||
var fileInput = document.getElementById("newfile").files;
|
||||
|
||||
/* Max size of an individual file. Make sure this
|
||||
* value is same as that set in file_server.c */
|
||||
var MAX_FILE_SIZE = 20*1024*1024;
|
||||
var MAX_FILE_SIZE_STR = "20MB";
|
||||
|
||||
if (fileInput.length == 0) {
|
||||
alert("No file selected!");
|
||||
} else if (filePath.length == 0) {
|
||||
alert("File path on server is not set!");
|
||||
} else if (filePath.indexOf(' ') >= 0) {
|
||||
alert("File path on server cannot have spaces!");
|
||||
} else if (filePath[filePath.length-1] == '/') {
|
||||
alert("File name not specified after path!");
|
||||
} else if (fileInput[0].size > MAX_FILE_SIZE) {
|
||||
alert("File size must be less than " + MAX_FILE_SIZE_STR);
|
||||
} else {
|
||||
document.getElementById("newfile").disabled = true;
|
||||
document.getElementById("filepath").disabled = true;
|
||||
document.getElementById("upload").disabled = true;
|
||||
|
||||
var file = fileInput[0];
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (xhttp.readyState == 4) {
|
||||
if (xhttp.status == 200) {
|
||||
document.open();
|
||||
document.write(xhttp.responseText);
|
||||
document.close();
|
||||
} else if (xhttp.status == 0) {
|
||||
alert("Server closed the connection abruptly!");
|
||||
location.reload()
|
||||
} else {
|
||||
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||
location.reload()
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.open("POST", upload_path, true);
|
||||
xhttp.send(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
82
main/wifi/www/upload_script_copy.html
Normal file
82
main/wifi/www/upload_script_copy.html
Normal file
@ -0,0 +1,82 @@
|
||||
<table class="fixed" border="0">
|
||||
<col width="1000px" /><col width="500px" />
|
||||
<meta charset='UTF-8'>
|
||||
<title>在线OTA更新</title>
|
||||
<tr><td>
|
||||
<h2>ESP32S2 OTA Bin Server</h2>
|
||||
</td><td>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="newfile">Upload a file</label>
|
||||
</td>
|
||||
<td colspan="2">
|
||||
<input id="newfile" type="file" accept=".bin" onchange="setpath()" style="width:100%;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="filepath">Set path on server</label>
|
||||
</td>
|
||||
<td>
|
||||
<input id="filepath" type="text" style="width:100%;">
|
||||
</td>
|
||||
<td>
|
||||
<button id="upload" type="button" onclick="upload()">Upload</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
<script>
|
||||
function setpath() {
|
||||
var default_path = document.getElementById("newfile").files[0].name;
|
||||
document.getElementById("filepath").value = default_path;
|
||||
}
|
||||
function upload() {
|
||||
var filePath = document.getElementById("filepath").value;
|
||||
var upload_path = "/upload/" + filePath;
|
||||
var fileInput = document.getElementById("newfile").files;
|
||||
|
||||
/* Max size of an individual file. Make sure this
|
||||
* value is same as that set in file_server.c */
|
||||
var MAX_FILE_SIZE = 20*1024*1024;
|
||||
var MAX_FILE_SIZE_STR = "20MB";
|
||||
|
||||
if (fileInput.length == 0) {
|
||||
alert("No file selected!");
|
||||
} else if (filePath.length == 0) {
|
||||
alert("File path on server is not set!");
|
||||
} else if (filePath.indexOf(' ') >= 0) {
|
||||
alert("File path on server cannot have spaces!");
|
||||
} else if (filePath[filePath.length-1] == '/') {
|
||||
alert("File name not specified after path!");
|
||||
} else if (fileInput[0].size > MAX_FILE_SIZE) {
|
||||
alert("File size must be less than " + MAX_FILE_SIZE_STR);
|
||||
} else {
|
||||
document.getElementById("newfile").disabled = true;
|
||||
document.getElementById("filepath").disabled = true;
|
||||
document.getElementById("upload").disabled = true;
|
||||
|
||||
var file = fileInput[0];
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (xhttp.readyState == 4) {
|
||||
if (xhttp.status == 200) {
|
||||
document.open();
|
||||
document.write(xhttp.responseText);
|
||||
document.close();
|
||||
} else if (xhttp.status == 0) {
|
||||
alert("Server closed the connection abruptly!");
|
||||
location.reload()
|
||||
} else {
|
||||
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||
location.reload()
|
||||
}
|
||||
}
|
||||
};
|
||||
xhttp.open("POST", upload_path, true);
|
||||
xhttp.send(file);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
47
main/wifi/www/wifi.html
Normal file
47
main/wifi/www/wifi.html
Normal file
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset='UTF-8'>
|
||||
<table class="fixed" border="0">
|
||||
|
||||
<col width="1000px" /><col width="500px" />
|
||||
<h3>wifi 密码配置</h3>
|
||||
<div>
|
||||
<label for="name">wifi名称</label>
|
||||
<input type="text" id="wifi" name="car_name" placeholder="ssid">
|
||||
<br>
|
||||
<label for="type">密码</label>
|
||||
<input type="text" id="code" name="car_type" placeholder="password">
|
||||
<br>
|
||||
<button id ="send_WIFI" type="button" onclick="send_wifi()">提交</button>
|
||||
</div>
|
||||
</table>
|
||||
<script>
|
||||
function setpath() {
|
||||
var default_path = document.getElementById("newfile").files[0].name;
|
||||
document.getElementById("filepath").value = default_path;
|
||||
}
|
||||
|
||||
function send_wifi() {
|
||||
var input_ssid = document.getElementById("wifi").value;
|
||||
var input_code = document.getElementById("code").value;
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.open("POST", "/config", true);
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (xhttp.readyState == 4) {
|
||||
if (xhttp.status == 200) {
|
||||
console.log(xhttp.responseText);
|
||||
} else if (xhttp.status == 0) {
|
||||
alert("Server closed the connection abruptly!");
|
||||
location.reload()
|
||||
} else {
|
||||
alert(xhttp.status + " Error!\n" + xhttp.responseText);
|
||||
location.reload()
|
||||
}
|
||||
}
|
||||
};
|
||||
var data = {
|
||||
"wifi_name":input_ssid,
|
||||
"wifi_code":input_code
|
||||
}
|
||||
xhttp.send(JSON.stringify(data));
|
||||
}
|
||||
</script>
|
||||
84
main/wifi/www/wifi_config.html
Normal file
84
main/wifi/www/wifi_config.html
Normal file
@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang='en'>
|
||||
<head>
|
||||
<meta charset='UTF-8'>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
||||
<title>在线配置</title>
|
||||
<style type="text/css">
|
||||
* { margin: 0; padding: 0; }
|
||||
html { height: 100%; }
|
||||
h2 {text-align: center;color: #fff;line-height: 2.2;}
|
||||
body { height: 100%; background-color: #1F6F4A; 50% 50% no-repeat; background-size: cover;}
|
||||
.dowebok { position: absolute; left: 50%; top: 30%; width: 380px; height: 500px; margin: -200px 0 0 -200px; border: 3px solid #fff; border-radius: 10px; overflow: hidden;}
|
||||
|
||||
.form-item { position: relative; width: 360px; margin: 0 auto; padding-bottom: 20px;}
|
||||
.form-item input { width: 288px; height: 48px; padding-left: 10px; border: 1px solid #fff; border-radius: 25px; font-size: 18px; color: #fff; background-color: transparent; outline: none;}
|
||||
.send_button { width: 360px; height: 50px; border: 0; border-radius: 25px; font-size: 18px; color: #1f6f4a; outline: none; cursor: pointer; background-color: #fff; }
|
||||
|
||||
.tip { display: none; position: absolute; left: 20px; top: 52px; font-size: 14px; color: #f50; }
|
||||
.reg-bar { width: 360px; margin: 20px auto 0; font-size: 14px; overflow: hidden;}
|
||||
.reg-bar a { color: #fff; text-decoration: none; }
|
||||
.reg-bar a:hover { text-decoration: underline; }
|
||||
.reg-bar .reg { float: left; }
|
||||
.reg-bar .forget { float: right; }
|
||||
.dowebok ::-webkit-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok ::-moz-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
.dowebok :-ms-input-placeholder { font-size: 18px; line-height: 1.4; color: #fff;}
|
||||
|
||||
@media screen and (max-width: 500px) {
|
||||
* { box-sizing: border-box; }
|
||||
.dowebok { position: static; width: auto; height: auto; margin: 0 30px; border: 0; border-radius: 0; }
|
||||
.logo { margin: 50px auto; }
|
||||
.form-item { width: auto; }
|
||||
.form-item input, .form-item button, .reg-bar { width: 100%; }
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="dowebok">
|
||||
<h2>ESP32 WIFI 配网</h2>
|
||||
<form style='text-align: center;padding-top: 20px' name='input' action='/' method='POST'>
|
||||
<div class="form-item">
|
||||
<input id="username" type="text" name='ssid' autocomplete="off" placeholder="WiFi名称">
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<input id="password" type="password" name='password' autocomplete="off" placeholder="WiFi密码">
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<input id="retry" type="text" name='retry' autocomplete="off" placeholder="重连次数">
|
||||
</div>
|
||||
|
||||
<!-- “设置” 和 “返回” 按钮并列 -->
|
||||
<div class="form-item btn-group">
|
||||
<input id="set_button" type="submit" value='设置' class="send_button">
|
||||
<input id="back_button" type="button" value='返回' class="send_button" onclick="window.location.href='/'">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.btn-group {
|
||||
display: flex;
|
||||
justify-content: center; /* 水平居中 */
|
||||
gap: 20px; /* 按钮之间的间距 */
|
||||
}
|
||||
|
||||
.send_button {
|
||||
display: block; /* 让 width 生效 */
|
||||
width: 150px;
|
||||
height: 50px;
|
||||
border: 0;
|
||||
border-radius: 25px;
|
||||
font-size: 18px;
|
||||
color: #1f6f4a;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
background-color: #fff;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
30
sdkconfig
30
sdkconfig
@ -591,7 +591,6 @@ CONFIG_COMPILER_ORPHAN_SECTIONS_PLACE=y
|
||||
#
|
||||
# CONFIG_APPTRACE_DEST_JTAG is not set
|
||||
CONFIG_APPTRACE_DEST_NONE=y
|
||||
# CONFIG_APPTRACE_DEST_UART0 is not set
|
||||
# CONFIG_APPTRACE_DEST_UART1 is not set
|
||||
# CONFIG_APPTRACE_DEST_UART2 is not set
|
||||
# CONFIG_APPTRACE_DEST_USB_CDC is not set
|
||||
@ -1120,15 +1119,17 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
|
||||
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
|
||||
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
|
||||
# CONFIG_ESP_CONSOLE_UART_DEFAULT is not set
|
||||
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_ESP_CONSOLE_USB_CDC is not set
|
||||
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
|
||||
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
|
||||
CONFIG_ESP_CONSOLE_NONE=y
|
||||
# CONFIG_ESP_CONSOLE_NONE is not set
|
||||
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y
|
||||
# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set
|
||||
CONFIG_ESP_CONSOLE_UART_NUM=-1
|
||||
CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM=-1
|
||||
CONFIG_ESP_CONSOLE_UART=y
|
||||
CONFIG_ESP_CONSOLE_UART_NUM=0
|
||||
CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM=0
|
||||
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
|
||||
CONFIG_ESP_INT_WDT=y
|
||||
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_ESP_INT_WDT_CHECK_CPU1=y
|
||||
@ -1398,13 +1399,14 @@ CONFIG_HEAP_TRACING_OFF=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL=4
|
||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
||||
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y
|
||||
# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set
|
||||
# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set
|
||||
CONFIG_LOG_MAXIMUM_LEVEL=4
|
||||
CONFIG_LOG_MAXIMUM_LEVEL=3
|
||||
# CONFIG_LOG_MASTER_LEVEL is not set
|
||||
CONFIG_LOG_COLORS=y
|
||||
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
|
||||
@ -2100,11 +2102,13 @@ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=160
|
||||
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=3584
|
||||
# CONFIG_CONSOLE_UART_DEFAULT is not set
|
||||
CONFIG_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_CONSOLE_UART_CUSTOM is not set
|
||||
CONFIG_CONSOLE_UART_NONE=y
|
||||
CONFIG_ESP_CONSOLE_UART_NONE=y
|
||||
CONFIG_CONSOLE_UART_NUM=-1
|
||||
# CONFIG_CONSOLE_UART_NONE is not set
|
||||
# CONFIG_ESP_CONSOLE_UART_NONE is not set
|
||||
CONFIG_CONSOLE_UART=y
|
||||
CONFIG_CONSOLE_UART_NUM=0
|
||||
CONFIG_CONSOLE_UART_BAUDRATE=115200
|
||||
CONFIG_INT_WDT=y
|
||||
CONFIG_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_INT_WDT_CHECK_CPU1=y
|
||||
|
||||
@ -480,8 +480,8 @@ CONFIG_ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB=y
|
||||
#
|
||||
# Boot ROM Behavior
|
||||
#
|
||||
CONFIG_BOOT_ROM_LOG_ALWAYS_ON=y
|
||||
# CONFIG_BOOT_ROM_LOG_ALWAYS_OFF is not set
|
||||
# CONFIG_BOOT_ROM_LOG_ALWAYS_ON is not set
|
||||
CONFIG_BOOT_ROM_LOG_ALWAYS_OFF=y
|
||||
# CONFIG_BOOT_ROM_LOG_ON_GPIO_HIGH is not set
|
||||
# CONFIG_BOOT_ROM_LOG_ON_GPIO_LOW is not set
|
||||
# end of Boot ROM Behavior
|
||||
@ -591,7 +591,6 @@ CONFIG_COMPILER_ORPHAN_SECTIONS_PLACE=y
|
||||
#
|
||||
# CONFIG_APPTRACE_DEST_JTAG is not set
|
||||
CONFIG_APPTRACE_DEST_NONE=y
|
||||
# CONFIG_APPTRACE_DEST_UART0 is not set
|
||||
# CONFIG_APPTRACE_DEST_UART1 is not set
|
||||
# CONFIG_APPTRACE_DEST_UART2 is not set
|
||||
# CONFIG_APPTRACE_DEST_USB_CDC is not set
|
||||
@ -1120,15 +1119,17 @@ CONFIG_ESP_MAIN_TASK_AFFINITY_CPU0=y
|
||||
# CONFIG_ESP_MAIN_TASK_AFFINITY_NO_AFFINITY is not set
|
||||
CONFIG_ESP_MAIN_TASK_AFFINITY=0x0
|
||||
CONFIG_ESP_MINIMAL_SHARED_STACK_SIZE=2048
|
||||
# CONFIG_ESP_CONSOLE_UART_DEFAULT is not set
|
||||
CONFIG_ESP_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_ESP_CONSOLE_USB_CDC is not set
|
||||
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y
|
||||
# CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is not set
|
||||
# CONFIG_ESP_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_ESP_CONSOLE_NONE is not set
|
||||
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y
|
||||
CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED=y
|
||||
CONFIG_ESP_CONSOLE_UART_NUM=-1
|
||||
CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM=4
|
||||
# CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG is not set
|
||||
CONFIG_ESP_CONSOLE_UART=y
|
||||
CONFIG_ESP_CONSOLE_UART_NUM=0
|
||||
CONFIG_ESP_CONSOLE_ROM_SERIAL_PORT_NUM=0
|
||||
CONFIG_ESP_CONSOLE_UART_BAUDRATE=115200
|
||||
CONFIG_ESP_INT_WDT=y
|
||||
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_ESP_INT_WDT_CHECK_CPU1=y
|
||||
@ -2100,11 +2101,13 @@ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ=160
|
||||
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
|
||||
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2304
|
||||
CONFIG_MAIN_TASK_STACK_SIZE=3584
|
||||
# CONFIG_CONSOLE_UART_DEFAULT is not set
|
||||
CONFIG_CONSOLE_UART_DEFAULT=y
|
||||
# CONFIG_CONSOLE_UART_CUSTOM is not set
|
||||
# CONFIG_CONSOLE_UART_NONE is not set
|
||||
# CONFIG_ESP_CONSOLE_UART_NONE is not set
|
||||
CONFIG_CONSOLE_UART_NUM=-1
|
||||
CONFIG_CONSOLE_UART=y
|
||||
CONFIG_CONSOLE_UART_NUM=0
|
||||
CONFIG_CONSOLE_UART_BAUDRATE=115200
|
||||
CONFIG_INT_WDT=y
|
||||
CONFIG_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_INT_WDT_CHECK_CPU1=y
|
||||
|
||||
Loading…
Reference in New Issue
Block a user