@@ -12,7 +12,7 @@ static char value[FILE_NAME_LEN];
12
12
static char retainAction[2 ];
13
13
int refreshVal = 5000 ; // msecs
14
14
15
- static httpd_handle_t httpServer = NULL ; // web server port
15
+ static httpd_handle_t httpServer = NULL ; // web server port
16
16
static int fdWs = -1 ; // websocket sockfd
17
17
bool useHttps = false ;
18
18
bool useSecure = false ;
@@ -501,74 +501,66 @@ static esp_err_t customOrNotFoundHandler(httpd_req_t *req, httpd_err_code_t err)
501
501
502
502
void startWebServer () {
503
503
esp_err_t res = ESP_FAIL;
504
- chunk = psramFound () ? (byte*)ps_malloc (CHUNKSIZE) : (byte*)malloc (CHUNKSIZE);
504
+ chunk = psramFound () ? (byte*)ps_malloc (CHUNKSIZE) : (byte*)malloc (CHUNKSIZE);
505
505
#if INCLUDE_CERTS
506
- size_t prvtkey_len = strlen (prvtkey_pem);
507
- size_t cacert_len = strlen (cacert_pem);
508
- if (useHttps && (!cacert_len || !prvtkey_len)) {
509
- useHttps = false ;
510
- LOG_ALT (" HTTPS not available as server keys not defined, using HTTP" );
511
- }
512
506
if (useHttps) {
513
507
// HTTPS server
514
508
httpd_ssl_config_t config = HTTPD_SSL_CONFIG_DEFAULT ();
515
509
#if CONFIG_IDF_TARGET_ESP32S3
516
510
config.httpd .stack_size = SERVER_STACK_SIZE;
517
511
#endif
518
- config.cacert_pem = (const uint8_t *)cacert_pem;
519
- config.cacert_len = cacert_len + 1 ;
520
- config.prvtkey_pem = (const uint8_t *)prvtkey_pem;
521
- config.prvtkey_len = prvtkey_len + 1 ;
512
+ config.prvtkey_pem = (const uint8_t *)serverCerts[0 ];
513
+ config.prvtkey_len = strlen (serverCerts[0 ]) + 1 ;
514
+ config.servercert = (const uint8_t *)serverCerts[1 ];
515
+ config.servercert_len = strlen (serverCerts[1 ]) + 1 ;
516
+
522
517
// config.user_cb = https_server_user_callback;
523
518
config.httpd .server_port = HTTPS_PORT;
524
- config.httpd .ctrl_port = HTTPS_PORT;
525
519
config.httpd .lru_purge_enable = true ; // close least used socket
526
520
config.httpd .max_uri_handlers = MAX_HANDLERS;
527
521
config.httpd .max_open_sockets = HTTP_CLIENTS + MAX_STREAMS;
528
522
config.httpd .task_priority = HTTP_PRI;
529
523
// config.httpd.uri_match_fn = httpd_uri_match_wildcard;
530
524
res = httpd_ssl_start (&httpServer, &config);
531
525
} else {
526
+ #else
527
+ if (!useHttps) {
532
528
#endif
533
529
// HTTP server
534
530
httpd_config_t config = HTTPD_DEFAULT_CONFIG ();
535
531
#if CONFIG_IDF_TARGET_ESP32S3
536
532
config.stack_size = SERVER_STACK_SIZE;
537
- #endif
533
+ #endif
538
534
config.server_port = HTTP_PORT;
539
- config.ctrl_port = HTTP_PORT;
540
- config.lru_purge_enable = true ;
535
+ config.lru_purge_enable = true ;
541
536
config.max_uri_handlers = MAX_HANDLERS;
542
537
config.max_open_sockets = HTTP_CLIENTS + MAX_STREAMS;
543
538
config.task_priority = HTTP_PRI;
544
539
// config.uri_match_fn = httpd_uri_match_wildcard;
545
540
res = httpd_start (&httpServer, &config);
546
- #if INCLUDE_CERTS
547
541
}
548
- #endif
549
-
550
542
httpd_uri_t indexUri = {.uri = " /" , .method = HTTP_GET, .handler = indexHandler, .user_ctx = NULL };
551
543
httpd_uri_t webUri = {.uri = " /web" , .method = HTTP_GET, .handler = webHandler, .user_ctx = NULL };
552
544
httpd_uri_t controlUri = {.uri = " /control" , .method = HTTP_GET, .handler = controlHandler, .user_ctx = NULL };
553
545
httpd_uri_t updateUri = {.uri = " /update" , .method = HTTP_POST, .handler = updateHandler, .user_ctx = NULL };
554
546
httpd_uri_t statusUri = {.uri = " /status" , .method = HTTP_GET, .handler = statusHandler, .user_ctx = NULL };
555
- httpd_uri_t wsUri = {.uri = " /ws" , .method = HTTP_GET, .handler = wsHandler, .user_ctx = NULL , .is_websocket = true };
556
547
httpd_uri_t uploadUri = {.uri = " /upload" , .method = HTTP_POST, .handler = uploadHandler, .user_ctx = NULL };
548
+ httpd_uri_t wifiUri = {.uri = " /wifi" , .method = HTTP_GET, .handler = setupHandler, .user_ctx = NULL };
549
+ httpd_uri_t wsUri = {.uri = " /ws" , .method = HTTP_GET, .handler = wsHandler, .user_ctx = NULL , .is_websocket = true };
557
550
httpd_uri_t sustainUri = {.uri = " /sustain" , .method = HTTP_GET, .handler = appSpecificSustainHandler, .user_ctx = NULL };
558
551
httpd_uri_t checkUri = {.uri = " /sustain" , .method = HTTP_HEAD, .handler = appSpecificSustainHandler, .user_ctx = NULL };
559
- httpd_uri_t wifiUri = {.uri = " /wifi" , .method = HTTP_GET, .handler = setupHandler, .user_ctx = NULL };
560
552
561
553
if (res == ESP_OK) {
562
554
httpd_register_uri_handler (httpServer, &indexUri);
563
555
httpd_register_uri_handler (httpServer, &webUri);
564
556
httpd_register_uri_handler (httpServer, &controlUri);
565
557
httpd_register_uri_handler (httpServer, &updateUri);
566
558
httpd_register_uri_handler (httpServer, &statusUri);
567
- httpd_register_uri_handler (httpServer, &wsUri);
568
559
httpd_register_uri_handler (httpServer, &uploadUri);
560
+ httpd_register_uri_handler (httpServer, &wifiUri);
561
+ httpd_register_uri_handler (httpServer, &wsUri);
569
562
httpd_register_uri_handler (httpServer, &sustainUri);
570
563
httpd_register_uri_handler (httpServer, &checkUri);
571
- httpd_register_uri_handler (httpServer, &wifiUri);
572
564
httpd_register_err_handler (httpServer, HTTPD_404_NOT_FOUND, customOrNotFoundHandler);
573
565
574
566
LOG_INF (" Starting web server on port: %u" , useHttps ? HTTPS_PORT : HTTP_PORT);
0 commit comments