@@ -12,7 +12,7 @@ static char value[FILE_NAME_LEN];
1212static char retainAction[2 ];
1313int refreshVal = 5000 ; // msecs
1414
15- static httpd_handle_t httpServer = NULL ; // web server port
15+ static httpd_handle_t httpServer = NULL ; // web server port
1616static int fdWs = -1 ; // websocket sockfd
1717bool useHttps = false ;
1818bool useSecure = false ;
@@ -501,74 +501,66 @@ static esp_err_t customOrNotFoundHandler(httpd_req_t *req, httpd_err_code_t err)
501501
502502void startWebServer () {
503503 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);
505505#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- }
512506 if (useHttps) {
513507 // HTTPS server
514508 httpd_ssl_config_t config = HTTPD_SSL_CONFIG_DEFAULT ();
515509#if CONFIG_IDF_TARGET_ESP32S3
516510 config.httpd .stack_size = SERVER_STACK_SIZE;
517511#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+
522517 // config.user_cb = https_server_user_callback;
523518 config.httpd .server_port = HTTPS_PORT;
524- config.httpd .ctrl_port = HTTPS_PORT;
525519 config.httpd .lru_purge_enable = true ; // close least used socket
526520 config.httpd .max_uri_handlers = MAX_HANDLERS;
527521 config.httpd .max_open_sockets = HTTP_CLIENTS + MAX_STREAMS;
528522 config.httpd .task_priority = HTTP_PRI;
529523 // config.httpd.uri_match_fn = httpd_uri_match_wildcard;
530524 res = httpd_ssl_start (&httpServer, &config);
531525 } else {
526+ #else
527+ if (!useHttps) {
532528#endif
533529 // HTTP server
534530 httpd_config_t config = HTTPD_DEFAULT_CONFIG ();
535531#if CONFIG_IDF_TARGET_ESP32S3
536532 config.stack_size = SERVER_STACK_SIZE;
537- #endif
533+ #endif
538534 config.server_port = HTTP_PORT;
539- config.ctrl_port = HTTP_PORT;
540- config.lru_purge_enable = true ;
535+ config.lru_purge_enable = true ;
541536 config.max_uri_handlers = MAX_HANDLERS;
542537 config.max_open_sockets = HTTP_CLIENTS + MAX_STREAMS;
543538 config.task_priority = HTTP_PRI;
544539 // config.uri_match_fn = httpd_uri_match_wildcard;
545540 res = httpd_start (&httpServer, &config);
546- #if INCLUDE_CERTS
547541 }
548- #endif
549-
550542 httpd_uri_t indexUri = {.uri = " /" , .method = HTTP_GET, .handler = indexHandler, .user_ctx = NULL };
551543 httpd_uri_t webUri = {.uri = " /web" , .method = HTTP_GET, .handler = webHandler, .user_ctx = NULL };
552544 httpd_uri_t controlUri = {.uri = " /control" , .method = HTTP_GET, .handler = controlHandler, .user_ctx = NULL };
553545 httpd_uri_t updateUri = {.uri = " /update" , .method = HTTP_POST, .handler = updateHandler, .user_ctx = NULL };
554546 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 };
556547 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 };
557550 httpd_uri_t sustainUri = {.uri = " /sustain" , .method = HTTP_GET, .handler = appSpecificSustainHandler, .user_ctx = NULL };
558551 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 };
560552
561553 if (res == ESP_OK) {
562554 httpd_register_uri_handler (httpServer, &indexUri);
563555 httpd_register_uri_handler (httpServer, &webUri);
564556 httpd_register_uri_handler (httpServer, &controlUri);
565557 httpd_register_uri_handler (httpServer, &updateUri);
566558 httpd_register_uri_handler (httpServer, &statusUri);
567- httpd_register_uri_handler (httpServer, &wsUri);
568559 httpd_register_uri_handler (httpServer, &uploadUri);
560+ httpd_register_uri_handler (httpServer, &wifiUri);
561+ httpd_register_uri_handler (httpServer, &wsUri);
569562 httpd_register_uri_handler (httpServer, &sustainUri);
570563 httpd_register_uri_handler (httpServer, &checkUri);
571- httpd_register_uri_handler (httpServer, &wifiUri);
572564 httpd_register_err_handler (httpServer, HTTPD_404_NOT_FOUND, customOrNotFoundHandler);
573565
574566 LOG_INF (" Starting web server on port: %u" , useHttps ? HTTPS_PORT : HTTP_PORT);
0 commit comments