mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-27 21:00:57 +03:00
Merged with httpd - work in progress
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
idf_component_register( SRC_DIRS .
|
||||
INCLUDE_DIRS .
|
||||
PRIV_REQUIRES json tools newlib console esp_common freertos
|
||||
REQUIRES nvs_flash
|
||||
PRIV_REQUIRES tools newlib console esp_common freertos
|
||||
REQUIRES nvs_flash json
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -7,5 +7,6 @@ idf_component_register( SRCS
|
||||
platform_console.c
|
||||
INCLUDE_DIRS .
|
||||
REQUIRES nvs_flash
|
||||
PRIV_REQUIRES console tools services spi_flash app_update platform_config vfs pthread wifi-manager platform_config codecs newlib )
|
||||
target_link_libraries(__idf_platform_console ${build_dir}/esp-idf/$<TARGET_PROPERTY:RECOVERY_PREFIX>/lib$<TARGET_PROPERTY:RECOVERY_PREFIX>.a )
|
||||
PRIV_REQUIRES console tools services spi_flash app_update platform_config vfs pthread wifi-manager platform_config newlib telnet display)
|
||||
target_link_libraries(${COMPONENT_LIB} ${build_dir}/esp-idf/$<TARGET_PROPERTY:RECOVERY_PREFIX>/lib$<TARGET_PROPERTY:RECOVERY_PREFIX>.a )
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
idf_component_register( SRC_DIRS .
|
||||
INCLUDE_DIRS .
|
||||
PRIV_REQUIRES console squeezelite pthread tools platform_config)
|
||||
PRIV_REQUIRES console codecs squeezelite newlib pthread tools platform_config)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=feof")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=fdopen")
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "gds_text.h"
|
||||
#include "gds_font.h"
|
||||
#include "display.h"
|
||||
#include "cmd_squeezelite.h"
|
||||
|
||||
#include "config.h"
|
||||
pthread_t thread_console;
|
||||
static void * console_thread();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
idf_component_register(SRC_DIRS .
|
||||
INCLUDE_DIRS .
|
||||
REQUIRES app_update esp_https_ota
|
||||
PRIV_REQUIRES console tools platform_config spi_flash vfs console freertos platform_console
|
||||
PRIV_REQUIRES console tools display services platform_config spi_flash vfs console freertos platform_console
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "squeezelite-ota.h"
|
||||
#include "config.h"
|
||||
#include "platform_config.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdarg.h>
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "gds.h"
|
||||
#include "gds_text.h"
|
||||
#include "gds_draw.h"
|
||||
#include "platform_esp32.h"
|
||||
|
||||
extern const char * get_certificate();
|
||||
|
||||
@@ -782,9 +783,9 @@ esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t
|
||||
|
||||
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length)
|
||||
{
|
||||
#if RECOVERY_APPLICATION
|
||||
return process_recovery_ota(bin_url,bin_buffer,length);
|
||||
#else
|
||||
if(is_recovery_running){
|
||||
return process_recovery_ota(bin_url,bin_buffer,length);
|
||||
}
|
||||
if(!bin_url){
|
||||
ESP_LOGE(TAG,"missing URL parameter. Unable to start OTA");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@@ -802,5 +803,5 @@ esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length)
|
||||
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
|
||||
return guided_factory();
|
||||
return ESP_OK;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
// tasks
|
||||
#define OTA_TASK_PRIOTITY 6
|
||||
|
||||
esp_err_t start_ota(const char * bin_url);
|
||||
|
||||
const char * ota_get_status();
|
||||
uint8_t ota_get_pct_complete();
|
||||
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
idf_component_register( SRC_DIRS . external a1s tas57xx
|
||||
INCLUDE_DIRS . a1s
|
||||
PRIV_REQUIRES newlib
|
||||
PRIV_REQUIRES
|
||||
codecs
|
||||
newlib
|
||||
esp_common
|
||||
esp-dsp
|
||||
platform_config
|
||||
bluetooth
|
||||
codecs
|
||||
|
||||
services
|
||||
raop
|
||||
display
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
idf_component_register( SRC_DIRS .
|
||||
INCLUDE_DIRS .
|
||||
INCLUDE_DIRS . ${IDF_PATH}/components/esp_http_server/src ${IDF_PATH}/components/esp_http_server/src/port/esp32 ${IDF_PATH}/components/esp_http_server/src/util ${IDF_PATH}/components/esp_http_server/src/
|
||||
REQUIRES squeezelite-ota json mdns
|
||||
PRIV_REQUIRES tools services platform_config esp_common json newlib freertos spi_flash nvs_flash mdns pthread wpa_supplicant platform_console
|
||||
PRIV_REQUIRES tools services platform_config esp_common json newlib freertos spi_flash nvs_flash mdns pthread wpa_supplicant platform_console esp_http_server
|
||||
EMBED_FILES style.css code.js index.html bootstrap.min.css.gz jquery.min.js.gz popper.min.js.gz bootstrap.min.js.gz
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ function to process requests, decode URLs, serve files, etc. etc.
|
||||
#include "esp_system.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "config.h"
|
||||
#include "platform_config.h"
|
||||
#include "sys/param.h"
|
||||
#include "esp_vfs.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
@@ -663,11 +663,13 @@ esp_err_t config_post_handler(httpd_req_t *req){
|
||||
cJSON_Delete(root);
|
||||
if(bOTA) {
|
||||
|
||||
#if RECOVERY_APPLICATION
|
||||
ESP_LOGW_LOC(TAG, "Starting process OTA for url %s",otaURL);
|
||||
#else
|
||||
ESP_LOGW_LOC(TAG, "Restarting system to process OTA for url %s",otaURL);
|
||||
#endif
|
||||
if(is_recovery_running){
|
||||
ESP_LOGW_LOC(TAG, "Starting process OTA for url %s",otaURL);
|
||||
}
|
||||
else {
|
||||
ESP_LOGW_LOC(TAG, "Restarting system to process OTA for url %s",otaURL);
|
||||
}
|
||||
|
||||
wifi_manager_reboot_ota(otaURL);
|
||||
free(otaURL);
|
||||
}
|
||||
@@ -805,82 +807,83 @@ esp_err_t recovery_post_handler(httpd_req_t *req){
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#if RECOVERY_APPLICATION
|
||||
|
||||
esp_err_t flash_post_handler(httpd_req_t *req){
|
||||
ESP_LOGD_LOC(TAG, "serving [%s]", req->uri);
|
||||
char success[]="File uploaded. Flashing started.";
|
||||
if(!is_user_authenticated(req)){
|
||||
// todo: redirect to login page
|
||||
// return ESP_OK;
|
||||
}
|
||||
esp_err_t err = httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
|
||||
if(err != ESP_OK){
|
||||
return err;
|
||||
}
|
||||
char * binary_buffer = malloc(req->content_len);
|
||||
if(binary_buffer == NULL){
|
||||
ESP_LOGE(TAG, "File too large : %d bytes", req->content_len);
|
||||
/* Respond with 400 Bad Request */
|
||||
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST,
|
||||
"Binary file too large. Unable to allocate memory!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
ESP_LOGI(TAG, "Receiving ota binary file");
|
||||
/* Retrieve the pointer to scratch buffer for temporary storage */
|
||||
char *buf = ((rest_server_context_t *)(req->user_ctx))->scratch;
|
||||
esp_err_t err =ESP_OK;
|
||||
if(is_recovery_running){
|
||||
ESP_LOGD_LOC(TAG, "serving [%s]", req->uri);
|
||||
char success[]="File uploaded. Flashing started.";
|
||||
if(!is_user_authenticated(req)){
|
||||
// todo: redirect to login page
|
||||
// return ESP_OK;
|
||||
}
|
||||
err = httpd_resp_set_type(req, HTTPD_TYPE_TEXT);
|
||||
if(err != ESP_OK){
|
||||
return err;
|
||||
}
|
||||
char * binary_buffer = malloc(req->content_len);
|
||||
if(binary_buffer == NULL){
|
||||
ESP_LOGE(TAG, "File too large : %d bytes", req->content_len);
|
||||
/* Respond with 400 Bad Request */
|
||||
httpd_resp_send_err(req, HTTPD_400_BAD_REQUEST,
|
||||
"Binary file too large. Unable to allocate memory!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
ESP_LOGI(TAG, "Receiving ota binary file");
|
||||
/* Retrieve the pointer to scratch buffer for temporary storage */
|
||||
char *buf = ((rest_server_context_t *)(req->user_ctx))->scratch;
|
||||
|
||||
char *head=binary_buffer;
|
||||
int received;
|
||||
char *head=binary_buffer;
|
||||
int received;
|
||||
|
||||
/* Content length of the request gives
|
||||
* the size of the file being uploaded */
|
||||
int remaining = req->content_len;
|
||||
/* Content length of the request gives
|
||||
* the size of the file being uploaded */
|
||||
int remaining = req->content_len;
|
||||
|
||||
while (remaining > 0) {
|
||||
while (remaining > 0) {
|
||||
|
||||
ESP_LOGI(TAG, "Remaining size : %d", remaining);
|
||||
/* Receive the file part by part into a buffer */
|
||||
if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) {
|
||||
if (received == HTTPD_SOCK_ERR_TIMEOUT) {
|
||||
/* Retry if timeout occurred */
|
||||
continue;
|
||||
ESP_LOGI(TAG, "Remaining size : %d", remaining);
|
||||
/* Receive the file part by part into a buffer */
|
||||
if ((received = httpd_req_recv(req, buf, MIN(remaining, SCRATCH_BUFSIZE))) <= 0) {
|
||||
if (received == HTTPD_SOCK_ERR_TIMEOUT) {
|
||||
/* Retry if timeout occurred */
|
||||
continue;
|
||||
}
|
||||
FREE_RESET(binary_buffer);
|
||||
ESP_LOGE(TAG, "File reception failed!");
|
||||
/* Respond with 500 Internal Server Error */
|
||||
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to receive file");
|
||||
err = ESP_FAIL;
|
||||
goto bail_out;
|
||||
}
|
||||
FREE_RESET(binary_buffer);
|
||||
ESP_LOGE(TAG, "File reception failed!");
|
||||
/* Respond with 500 Internal Server Error */
|
||||
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "Failed to receive file");
|
||||
err = ESP_FAIL;
|
||||
|
||||
/* Write buffer content to file on storage */
|
||||
if (received ) {
|
||||
memcpy(head,buf,received );
|
||||
head+=received;
|
||||
}
|
||||
|
||||
/* Keep track of remaining size of
|
||||
* the file left to be uploaded */
|
||||
remaining -= received;
|
||||
}
|
||||
|
||||
/* Close file upon upload completion */
|
||||
ESP_LOGI(TAG, "File reception complete. Invoking OTA process.");
|
||||
err = start_ota(NULL, binary_buffer, req->content_len);
|
||||
if(err!=ESP_OK){
|
||||
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "OTA processing failed");
|
||||
goto bail_out;
|
||||
}
|
||||
|
||||
/* Write buffer content to file on storage */
|
||||
if (received ) {
|
||||
memcpy(head,buf,received );
|
||||
head+=received;
|
||||
}
|
||||
|
||||
/* Keep track of remaining size of
|
||||
* the file left to be uploaded */
|
||||
remaining -= received;
|
||||
//todo: handle this in ajax. For now, just send the root page
|
||||
httpd_resp_send(req, (const char *)success, strlen(success));
|
||||
}
|
||||
|
||||
/* Close file upon upload completion */
|
||||
ESP_LOGI(TAG, "File reception complete. Invoking OTA process.");
|
||||
err = start_ota(NULL, binary_buffer, req->content_len);
|
||||
if(err!=ESP_OK){
|
||||
httpd_resp_send_err(req, HTTPD_500_INTERNAL_SERVER_ERROR, "OTA processing failed");
|
||||
goto bail_out;
|
||||
}
|
||||
|
||||
//todo: handle this in ajax. For now, just send the root page
|
||||
httpd_resp_send(req, (const char *)success, strlen(success));
|
||||
|
||||
bail_out:
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
char * get_ap_ip_address(){
|
||||
static char ap_ip_address[IP4ADDR_STRLEN_MAX]={};
|
||||
|
||||
|
||||
@@ -88,9 +88,7 @@ esp_err_t connect_delete_handler(httpd_req_t *req);
|
||||
esp_err_t reboot_ota_post_handler(httpd_req_t *req);
|
||||
esp_err_t reboot_post_handler(httpd_req_t *req);
|
||||
esp_err_t recovery_post_handler(httpd_req_t *req);
|
||||
#if RECOVERY_APPLICATION
|
||||
esp_err_t flash_post_handler(httpd_req_t *req);
|
||||
#endif
|
||||
esp_err_t status_get_handler(httpd_req_t *req);
|
||||
esp_err_t messages_get_handler(httpd_req_t *req);
|
||||
|
||||
@@ -111,13 +109,13 @@ typedef struct rest_server_context {
|
||||
* @brief RTOS task for the HTTP server. Do not start manually.
|
||||
* @see void http_server_start()
|
||||
*/
|
||||
void CODE_RAM_LOCATION http_server(void *pvParameters);
|
||||
void http_server(void *pvParameters);
|
||||
|
||||
/* @brief helper function that processes one HTTP request at a time */
|
||||
void CODE_RAM_LOCATION http_server_netconn_serve(struct netconn *conn);
|
||||
void http_server_netconn_serve(struct netconn *conn);
|
||||
|
||||
/* @brief create the task for the http server */
|
||||
esp_err_t CODE_RAM_LOCATION http_server_start();
|
||||
esp_err_t http_server_start();
|
||||
|
||||
/**
|
||||
* @brief gets a char* pointer to the first occurence of header_name withing the complete http request request.
|
||||
@@ -130,9 +128,9 @@ esp_err_t CODE_RAM_LOCATION http_server_start();
|
||||
* @param len the size of the header value if found.
|
||||
* @return pointer to the beginning of the header value.
|
||||
*/
|
||||
char* CODE_RAM_LOCATION http_server_get_header(char *request, char *header_name, int *len);
|
||||
char* http_server_get_header(char *request, char *header_name, int *len);
|
||||
|
||||
void CODE_RAM_LOCATION strreplace(char *src, char *str, char *rep);
|
||||
void strreplace(char *src, char *str, char *rep);
|
||||
/* @brief lock the json config object */
|
||||
bool http_server_lock_json_object(TickType_t xTicksToWait);
|
||||
/* @brief unlock the json config object */
|
||||
|
||||
@@ -1440,7 +1440,7 @@ void wifi_manager( void * pvParameters ){
|
||||
break;
|
||||
case ORDER_RESTART_OTA_URL:
|
||||
ESP_LOGD(TAG, "Calling start_ota.");
|
||||
start_ota(msg.param);
|
||||
start_ota(msg.param, NULL, 0);
|
||||
free(msg.param);
|
||||
break;
|
||||
|
||||
|
||||
@@ -42,17 +42,6 @@ extern "C" {
|
||||
#include "squeezelite-ota.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
#ifndef RECOVERY_APPLICATION
|
||||
#error "RECOVERY_APPLICATION not defined. Defaulting to squeezelite"
|
||||
#endif
|
||||
|
||||
#if RECOVERY_APPLICATION==1
|
||||
#elif RECOVERY_APPLICATION==0
|
||||
#else
|
||||
#error "unknown configuration"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Defines the maximum size of a SSID name. 32 is IEEE standard.
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "freertos/task.h"
|
||||
#include "config.h"
|
||||
#include "messaging.h"
|
||||
#include "platform_esp32.h"
|
||||
static const char TAG[] = "http_server";
|
||||
|
||||
static httpd_handle_t _server = NULL;
|
||||
@@ -74,13 +75,10 @@ void register_regular_handlers(httpd_handle_t server){
|
||||
httpd_uri_t connect_delete = { .uri = "/connect.json", .method = HTTP_DELETE, .handler = connect_delete_handler, .user_ctx = rest_context };
|
||||
httpd_register_uri_handler(server, &connect_delete);
|
||||
|
||||
#if RECOVERY_APPLICATION
|
||||
|
||||
httpd_uri_t flash_post = { .uri = "/flash.json", .method = HTTP_POST, .handler = flash_post_handler, .user_ctx = rest_context };
|
||||
httpd_register_uri_handler(server, &flash_post);
|
||||
#endif
|
||||
|
||||
|
||||
if(is_recovery_running){
|
||||
httpd_uri_t flash_post = { .uri = "/flash.json", .method = HTTP_POST, .handler = flash_post_handler, .user_ctx = rest_context };
|
||||
httpd_register_uri_handler(server, &flash_post);
|
||||
}
|
||||
// from https://github.com/tripflex/wifi-captive-portal/blob/master/src/mgos_wifi_captive_portal.c
|
||||
// https://unix.stackexchange.com/questions/432190/why-isnt-androids-captive-portal-detection-triggering-a-browser-window
|
||||
// Known HTTP GET requests to check for Captive Portal
|
||||
|
||||
Reference in New Issue
Block a user