Compare commits
No commits in common. "3cebcde66ca407542b7063c944a5217b814a2ade" and "7f00c2b3bda61002a2dfb1979a00236f0359cc6e" have entirely different histories.
3cebcde66c
...
7f00c2b3bd
@ -1,6 +0,0 @@
|
|||||||
idf_component_register(SRCS "bsp_flash.c"
|
|
||||||
INCLUDE_DIRS "include"
|
|
||||||
|
|
||||||
REQUIRES driver
|
|
||||||
REQUIRES nvs_flash
|
|
||||||
)
|
|
||||||
@ -1,132 +0,0 @@
|
|||||||
#include "bsp_flash.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
static const char *TAG = "flash.h";
|
|
||||||
|
|
||||||
SemaphoreHandle_t xSemaphore_ESPFlash;
|
|
||||||
void ESPFlash_Init(void)
|
|
||||||
{
|
|
||||||
xSemaphore_ESPFlash = xSemaphoreCreateMutex();// 创建互斥型信号量。
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t Read_ESPFlash(uint8_t SubType,uint32_t addr,uint8_t* buf,uint32_t len)
|
|
||||||
{
|
|
||||||
if(len == 0)return 1;
|
|
||||||
xSemaphoreTake( xSemaphore_ESPFlash, portMAX_DELAY );//获得资源的使用权
|
|
||||||
esp_partition_t* res=esp_partition_find_first(0x01,SubType,NULL);
|
|
||||||
if(res==NULL)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"no partition is found\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(esp_partition_read(res,addr, &buf[0], len)!=ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"SubType: 0x%X 0x%lX",SubType,addr);
|
|
||||||
ESP_LOGI(TAG,"partition read fail\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t IRAM_ATTR Write_ESPFlash(uint8_t SubType,uint32_t addr,uint8_t* buf,uint32_t len)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"SubType: %d %lx",SubType,addr);
|
|
||||||
xSemaphoreTake( xSemaphore_ESPFlash, portMAX_DELAY );//获得资源的使用权
|
|
||||||
esp_partition_t* res=esp_partition_find_first(0x01,SubType,NULL);
|
|
||||||
if(res==NULL)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"no partition is found\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//ESP_LOGI(TAG,"partiton info:\r\n name:%s\r\n size:%x\r\n start address:%x\r\n",res->label,res->size,res->address);
|
|
||||||
}
|
|
||||||
#if 1 //使能后会先擦再写
|
|
||||||
if(esp_partition_erase_range(res,0,4096)!=ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"partition erase fail\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if(esp_partition_write(res,addr, &buf[0], len)!=ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"partition write fail\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t IRAM_ATTR Erase_ESPFlash(uint8_t SubType,uint32_t addr)
|
|
||||||
{
|
|
||||||
xSemaphoreTake( xSemaphore_ESPFlash, portMAX_DELAY );//获得资源的使用权
|
|
||||||
esp_partition_t* res=esp_partition_find_first(0x01,SubType,NULL);
|
|
||||||
if(res==NULL)
|
|
||||||
{
|
|
||||||
//ESP_LOGI(TAG,"no partition is found\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// ESP_LOGI(TAG,"partiton info:\r\n name:%s\r\n size:%lx\r\n start address:%lx\r\n",res->label,res->size,res->address);
|
|
||||||
}
|
|
||||||
if(esp_partition_erase_range(res,addr,4096)!=ESP_OK)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG,"partition erase fail\r\n");
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return 0x0;
|
|
||||||
}else{
|
|
||||||
xSemaphoreGive( xSemaphore_ESPFlash );//释放
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_partiton(void)
|
|
||||||
{
|
|
||||||
uint8_t write_partition_data[16],read_partition_data[20];
|
|
||||||
|
|
||||||
esp_partition_t* res=esp_partition_find_first(0x01,0x41,NULL);
|
|
||||||
|
|
||||||
if(res==NULL)
|
|
||||||
{
|
|
||||||
printf("no partition is found\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("partiton info:\r\n name:%s\r\n size:%lx\r\n start address:%lx\r\n",
|
|
||||||
res->label,res->size,res->address);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(esp_partition_read(res,0, read_partition_data, 16)!=ESP_OK)
|
|
||||||
{
|
|
||||||
printf("partition read fail\r\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("read partition data from :");
|
|
||||||
for(uint8_t i=0;i<16;i++)
|
|
||||||
printf("%X ",read_partition_data[i]);
|
|
||||||
printf("\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
#ifndef __BSP_FLASH_H
|
|
||||||
#define __BSP_FLASH_H
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
|
||||||
#include "freertos/task.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "esp_check.h"
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include "driver/gpio.h"
|
|
||||||
#include "driver/uart.h"
|
|
||||||
#include "esp_partition.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern void test_partiton(void);
|
|
||||||
extern void ESPFlash_Init(void);
|
|
||||||
extern uint32_t Read_ESPFlash(uint8_t SubType,uint32_t addr,uint8_t* buf,uint32_t len);
|
|
||||||
extern uint32_t IRAM_ATTR Write_ESPFlash(uint8_t SubType,uint32_t addr,uint8_t* buf,uint32_t len);
|
|
||||||
extern uint32_t IRAM_ATTR Erase_ESPFlash(uint8_t SubType,uint32_t addr);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
file(GLOB PORT_SRCS "wifi/*.c" )
|
file(GLOB PORT_SRCS "wifi/*.c" )
|
||||||
|
|
||||||
|
file(GLOB HTML_SRCS "wifi/www/*.html" "wifi/file/favicon.ico")
|
||||||
|
|
||||||
file(GLOB FILE_SYS_SRCS "file_system/spiffs.c" )
|
file(GLOB FILE_SYS_SRCS "file_system/spiffs.c" )
|
||||||
|
|
||||||
idf_component_register(SRCS "main.c" ${PORT_SRCS} ${FILE_SYS_SRCS}
|
idf_component_register(SRCS "main.c" ${PORT_SRCS} ${FILE_SYS_SRCS}
|
||||||
|
EMBED_FILES ${HTML_SRCS}
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
INCLUDE_DIRS "file_system/"
|
INCLUDE_DIRS "file_system/"
|
||||||
INCLUDE_DIRS "wifi/")
|
INCLUDE_DIRS "wifi/")
|
||||||
|
|||||||
26
main/main.c
26
main/main.c
@ -34,7 +34,6 @@
|
|||||||
#include "wifi_task.h"
|
#include "wifi_task.h"
|
||||||
#include "spiffs.h"
|
#include "spiffs.h"
|
||||||
|
|
||||||
#include "bsp_flash.h"
|
|
||||||
|
|
||||||
#define EX_UART_NUM UART_NUM_0
|
#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*/
|
#define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
|
||||||
@ -170,23 +169,6 @@ static void uart_event_task(void *pvParameters)
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* load_html2Ram(wifi_html_t html)
|
|
||||||
{
|
|
||||||
uint8_t* buff;
|
|
||||||
if(html.html_data != NULL) {
|
|
||||||
return html.html_data;
|
|
||||||
}else{
|
|
||||||
buff = malloc(html.html_size + 10);
|
|
||||||
Read_ESPFlash(0x41,html.html_addr,&buff[0],html.html_size);
|
|
||||||
// ESP_LOGI(TAG,"html:%s",buff);
|
|
||||||
return buff;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern uint8_t* home_html_data;
|
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -200,8 +182,7 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
|
||||||
init_spiffs();
|
init_spiffs();
|
||||||
ESPFlash_Init();
|
|
||||||
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
|
||||||
gpio_config_t config = {
|
gpio_config_t config = {
|
||||||
.mode = GPIO_MODE_OUTPUT,
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
.pin_bit_mask = 1ULL << 8 | 1ULL << 7,
|
.pin_bit_mask = 1ULL << 8 | 1ULL << 7,
|
||||||
@ -228,16 +209,13 @@ void app_main(void)
|
|||||||
//Create a task to handler UART event from ISR
|
//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);
|
||||||
|
|
||||||
home_html.html_data = load_html2Ram(home_html);
|
|
||||||
wifi_config_html.html_data = load_html2Ram(wifi_config_html);
|
|
||||||
// favicon_ico.html_data = load_html2Ram(favicon_ico);
|
|
||||||
// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
// ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
||||||
wifi_init_softap();
|
wifi_init_softap();
|
||||||
|
|
||||||
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
vTaskDelay(1000/ portTICK_PERIOD_MS);
|
||||||
start_web_server();
|
start_web_server();
|
||||||
// xTaskCreate(tcp_server_task, "tcp_server", 4096, (void*)AF_INET, 5, NULL);
|
// xTaskCreate(tcp_server_task, "tcp_server", 4096, (void*)AF_INET, 5, NULL);
|
||||||
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
const loader_esp32_config_t config = {
|
const loader_esp32_config_t config = {
|
||||||
|
|||||||
@ -6,55 +6,66 @@
|
|||||||
static const char *TAG = "wifi_html";
|
static const char *TAG = "wifi_html";
|
||||||
|
|
||||||
|
|
||||||
uint8_t* home_html_data;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
wifi_html_t home_html = {
|
|
||||||
.html_name = "home.html",
|
|
||||||
.html_addr = 0xb84,
|
|
||||||
.html_size = 4081,
|
|
||||||
};
|
|
||||||
|
|
||||||
wifi_html_t wifi_config_html = {
|
|
||||||
.html_name = "wifi_config.html",
|
|
||||||
.html_addr = 0x44b9,
|
|
||||||
.html_size = 6671,
|
|
||||||
};
|
|
||||||
|
|
||||||
wifi_html_t favicon_ico = {
|
|
||||||
.html_name = "favicon.ico",
|
|
||||||
.html_addr = 0,
|
|
||||||
.html_size = 106008,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static esp_err_t index_get_handler(httpd_req_t *req)
|
static esp_err_t index_get_handler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
|
extern const unsigned char wifi_config_start[] asm("_binary_wifi_config_html_start");
|
||||||
|
extern const unsigned char wifi_config_end[] asm("_binary_wifi_config_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 */
|
/* 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_set_type(req,HTTPD_TYPE_TEXT);
|
||||||
httpd_resp_send(req, (const char *)wifi_config_html.html_data, wifi_config_html.html_size);
|
httpd_resp_send(req, (const char *)wifi_config_start, wifi_config_size);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t Home_get_handler(httpd_req_t *req)
|
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 */
|
/* 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_set_type(req,HTTPD_TYPE_TEXT);
|
||||||
|
httpd_resp_send(req, (const char *)home_start, home_size);
|
||||||
httpd_resp_send(req, (const char*)home_html.html_data, home_html.html_size);
|
|
||||||
return ESP_OK;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/* Handler to respond with an icon file embedded in flash.
|
/* Handler to respond with an icon file embedded in flash.
|
||||||
* Browsers expect to GET website icon at URI /favicon.ico.
|
* Browsers expect to GET website icon at URI /favicon.ico.
|
||||||
* This can be overridden by uploading file with same name */
|
* This can be overridden by uploading file with same name */
|
||||||
static esp_err_t favicon_get_handler(httpd_req_t *req)
|
static esp_err_t favicon_get_handler(httpd_req_t *req)
|
||||||
{
|
{
|
||||||
|
extern const unsigned char favicon_ico_start[] asm("_binary_favicon_ico_start");
|
||||||
|
extern const unsigned char favicon_ico_end[] asm("_binary_favicon_ico_end");
|
||||||
|
const size_t favicon_ico_size = (favicon_ico_end - favicon_ico_start);
|
||||||
httpd_resp_set_type(req, "image/x-icon");
|
httpd_resp_set_type(req, "image/x-icon");
|
||||||
httpd_resp_send(req, (const char *)favicon_ico.html_data, favicon_ico.html_size);
|
httpd_resp_send(req, (const char *)favicon_ico_start, favicon_ico_size);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,18 +27,6 @@
|
|||||||
|
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
|
||||||
typedef struct wifi_html_
|
|
||||||
{
|
|
||||||
char* html_name;
|
|
||||||
uint32_t html_addr;
|
|
||||||
uint32_t html_size;
|
|
||||||
uint8_t* html_data;
|
|
||||||
}wifi_html_t;
|
|
||||||
|
|
||||||
extern wifi_html_t home_html;
|
|
||||||
extern wifi_html_t wifi_config_html;
|
|
||||||
extern wifi_html_t favicon_ico;
|
|
||||||
|
|
||||||
void wifi_init_station(void);
|
void wifi_init_station(void);
|
||||||
void wifi_init_softap(void);
|
void wifi_init_softap(void);
|
||||||
esp_err_t start_web_server(void);
|
esp_err_t start_web_server(void);
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"url": "/file_server.html",
|
|
||||||
"size": 2948,
|
|
||||||
"name": "file_server.html",
|
|
||||||
"address": "0x0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/home.html",
|
|
||||||
"size": 4081,
|
|
||||||
"name": "home.html",
|
|
||||||
"address": "0xb84"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/upload_script.html",
|
|
||||||
"size": 5883,
|
|
||||||
"name": "upload_script.html",
|
|
||||||
"address": "0x1b75"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/upload_script_copy.html",
|
|
||||||
"size": 3046,
|
|
||||||
"name": "upload_script_copy.html",
|
|
||||||
"address": "0x3270"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/wifi.html",
|
|
||||||
"size": 1635,
|
|
||||||
"name": "wifi.html",
|
|
||||||
"address": "0x3e56"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "/wifi_config.html",
|
|
||||||
"size": 6671,
|
|
||||||
"name": "wifi_config.html",
|
|
||||||
"address": "0x44b9"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@ -1,580 +0,0 @@
|
|||||||
<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>
|
|
||||||
<!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>
|
|
||||||
|
|
||||||
<!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>
|
|
||||||
<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>
|
|
||||||
<!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>
|
|
||||||
<!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' onsubmit="send_wifi(event)">
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function send_wifi(event) {
|
|
||||||
// 通过 event.submitter 获取触发提交的按钮
|
|
||||||
let buttonId = event.submitter.id;
|
|
||||||
console.log("触发提交的按钮 ID:", buttonId);
|
|
||||||
|
|
||||||
if (buttonId === "set_button") {//只有设置按钮才能阻塞
|
|
||||||
event.preventDefault(); // 阻止表单提交
|
|
||||||
console.log("send_wifi() 函数被调用了");
|
|
||||||
|
|
||||||
// 获取 WiFi 名称和密码
|
|
||||||
let wifi_name = document.getElementById("username").value;
|
|
||||||
let wifi_password = document.getElementById("password").value;
|
|
||||||
let retry_count = document.getElementById("retry").value;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log("WiFi 名称:", wifi_name);
|
|
||||||
console.log("WiFi 密码:", wifi_password);
|
|
||||||
console.log("重连次数:", retry_count);
|
|
||||||
|
|
||||||
// 你可以在这里添加 AJAX 代码将数据发送到服务器
|
|
||||||
var xhttp = new XMLHttpRequest();
|
|
||||||
xhttp.open("POST", "/config", true);
|
|
||||||
xhttp.setRequestHeader("Content-Type", "application/json"); // 确保以 JSON 格式发送
|
|
||||||
xhttp.onreadystatechange = function() {
|
|
||||||
if (xhttp.readyState == 4) {
|
|
||||||
if (xhttp.status == 200) {
|
|
||||||
// 解析 JSON 响应
|
|
||||||
let response = JSON.parse(xhttp.responseText);
|
|
||||||
console.log("服务器响应:", response);
|
|
||||||
if (response.status === "success") {
|
|
||||||
alert("Wi-Fi 配置成功!");
|
|
||||||
} else {
|
|
||||||
alert("Wi-Fi 配置失败!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (xhttp.status == 0) {
|
|
||||||
alert("服务器连接被关闭,重新加载页面!");
|
|
||||||
location.reload()
|
|
||||||
} else {
|
|
||||||
alert(xhttp.status + " 错误!\n" + xhttp.responseText);
|
|
||||||
location.reload()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// 发送 JSON 数据
|
|
||||||
var data = {
|
|
||||||
"wifi_name": wifi_name,
|
|
||||||
"wifi_code": wifi_password,
|
|
||||||
"retry_count": retry_count
|
|
||||||
};
|
|
||||||
xhttp.send(JSON.stringify(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// function setpath() {
|
|
||||||
// var default_path = document.getElementById("newfile").files[0].name;
|
|
||||||
// document.getElementById("filepath").value = default_path;
|
|
||||||
// }
|
|
||||||
</script>
|
|
||||||
1986
sdkconfig_c3
1986
sdkconfig_c3
File diff suppressed because it is too large
Load Diff
@ -1,60 +1,14 @@
|
|||||||
|
import esptool
|
||||||
|
|
||||||
|
|
||||||
#/Users/yu/.espressif/python_env/idf5.3_py3.9_env/bin/python /Users/yu/esp/v5.3.2/esp-idf/components/esptool_py/esptool/esptool.py -p /dev/tty.wchusbserial54CE0416791 -b 460800 --before default_reset --after hard_reset --chip esp32s3 write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0 bootloader/bootloader.bin 0x10000 usb_serial_jtag_echo.bin 0x8000 partition_table/partition-table.bin 0xd000 ota_data_initial.bin
|
#/Users/yu/.espressif/python_env/idf5.3_py3.9_env/bin/python /Users/yu/esp/v5.3.2/esp-idf/components/esptool_py/esptool/esptool.py -p /dev/tty.wchusbserial54CE0416791 -b 460800 --before default_reset --after hard_reset --chip esp32s3 write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0 bootloader/bootloader.bin 0x10000 usb_serial_jtag_echo.bin 0x8000 partition_table/partition-table.bin 0xd000 ota_data_initial.bin
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import esptool
|
|
||||||
|
|
||||||
def get_files(directory, extra_file=None):
|
esptool.main([
|
||||||
"""获取指定目录下的所有 HTML 文件及其大小,并优先添加额外文件(如 favicon.ico)"""
|
"--chip", "esp32c3",
|
||||||
files = []
|
"--port", "/dev/tty.usbmodem11401",
|
||||||
if extra_file and os.path.exists(extra_file):
|
"--baud", "460800",
|
||||||
filesize = os.path.getsize(extra_file)
|
"write_flash",
|
||||||
files.append((os.path.basename(extra_file), extra_file, filesize))
|
"-z",
|
||||||
|
"0x2d1000", "/Users/yu/esp/esp32c3-usb_serial/main/wifi/www/wifi_config.html"
|
||||||
for filename in sorted(os.listdir(directory)):
|
])
|
||||||
if filename.endswith(".html"):
|
|
||||||
filepath = os.path.join(directory, filename)
|
|
||||||
filesize = os.path.getsize(filepath)
|
|
||||||
files.append((filename, filepath, filesize))
|
|
||||||
return files
|
|
||||||
|
|
||||||
def create_bin_file(directory, files, output_bin="html_files.bin"):
|
|
||||||
"""将 favicon.ico 和所有 HTML 文件按烧录顺序拼接成一个 .bin 文件"""
|
|
||||||
bin_path = os.path.join(directory, output_bin)
|
|
||||||
current_address = 0x0
|
|
||||||
json_data = []
|
|
||||||
|
|
||||||
with open(bin_path, "wb") as bin_file:
|
|
||||||
for filename, filepath, filesize in files:
|
|
||||||
with open(filepath, "rb") as f:
|
|
||||||
file_data = f.read()
|
|
||||||
bin_file.write(file_data)
|
|
||||||
json_data.append({
|
|
||||||
"url": f"/{filename}",
|
|
||||||
"size": filesize,
|
|
||||||
"name": filename,
|
|
||||||
"address": hex(current_address)
|
|
||||||
})
|
|
||||||
current_address += filesize
|
|
||||||
|
|
||||||
with open(os.path.join(directory, "download_html.json"), "w", encoding="utf-8") as json_file:
|
|
||||||
json.dump(json_data, json_file, indent=4, ensure_ascii=False)
|
|
||||||
|
|
||||||
print(f"Generated bin file: {bin_path}")
|
|
||||||
return bin_path
|
|
||||||
|
|
||||||
def write_flash(directory, base_address=0x2D1000, port="COM11", baud=460800):
|
|
||||||
extra_file = os.path.join(os.path.dirname(directory), "file", "favicon.ico")
|
|
||||||
files = get_files(directory)
|
|
||||||
bin_file = create_bin_file(directory, files)
|
|
||||||
|
|
||||||
flash_cmd = ["--chip", "esp32c3", "--port", port, "--baud", str(baud), "write_flash", "-z", hex(base_address), bin_file]
|
|
||||||
|
|
||||||
print("Flashing command:", flash_cmd)
|
|
||||||
esptool.main(flash_cmd)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
directory = r"D:\\esp\\WorkSpace\\esp32c3-usb_serial\\main\\wifi\\www"
|
|
||||||
write_flash(directory)
|
|
||||||
Loading…
Reference in New Issue
Block a user