From cb59b7a685b0107cee0cf4aa1a4043792f7e024f Mon Sep 17 00:00:00 2001 From: Dennis960 <66166638+Dennis960@users.noreply.github.com> Date: Thu, 5 Sep 2024 19:37:33 +0200 Subject: [PATCH] Remove https server because I don't want to have to manage ssl certificates --- Firmware/frontend/src/pages/cloud-page.ts | 64 ++++++++++++++++--- .../src/pages/page-elements/button-element.ts | 1 + .../frontend/src/pages/wifi-scanner-page.ts | 25 ++++---- Firmware/main/CMakeLists.txt | 4 +- Firmware/main/certs/generate-certs.sh | 1 - Firmware/main/certs/prvtkey.pem | 28 -------- Firmware/main/certs/servercert.pem | 19 ------ Firmware/main/configuration_mode_server.c | 53 ++------------- Firmware/main/configuration_mode_server.h | 4 +- Firmware/main/main.c | 2 - Firmware/main/plantstore.c | 33 ++++++++++ Firmware/main/plantstore.h | 3 + Firmware/sdkconfig | 4 +- Server/src/lib/api.ts | 26 ++------ Server/src/routes/selector/+page.svelte | 5 +- .../routes/selector/sensor/new/+page.svelte | 5 +- 16 files changed, 125 insertions(+), 152 deletions(-) delete mode 100755 Firmware/main/certs/generate-certs.sh delete mode 100644 Firmware/main/certs/prvtkey.pem delete mode 100644 Firmware/main/certs/servercert.pem diff --git a/Firmware/frontend/src/pages/cloud-page.ts b/Firmware/frontend/src/pages/cloud-page.ts index 0ee7a73..81ccb51 100644 --- a/Firmware/frontend/src/pages/cloud-page.ts +++ b/Firmware/frontend/src/pages/cloud-page.ts @@ -2,6 +2,7 @@ import { StateController } from "@lit-app/state"; import { html } from "lit"; import { customElement, query, state } from "lit/decorators.js"; import { + BlumyCloudConfiguration, CloudConfiguration, CloudConfigurationType, cloudConfigurationTypes, @@ -181,6 +182,48 @@ export class CloudPage extends BasePage { return success; } + async loadConfigFromQuery(queryParameters: URLSearchParams) { + const token = queryParameters.get("token")!; + const url = queryParameters.get("blumyUrl")!; + queryParameters.delete("token"); + queryParameters.delete("blumyUrl"); + window.history.replaceState( + null, + "", + `${location.pathname}?${queryParameters.toString()}` + ); + const blumyConfiguration: BlumyCloudConfiguration = { + type: "blumy", + token: token, + url: url, + }; + this.configurationStates.blumy.formElement!.setConfig( + blumyConfiguration as never + ); + + const connectionSuccess = await testCloudConnection(blumyConfiguration); + + if (connectionSuccess) { + const res = await setCloudCredentials(blumyConfiguration); + if (!res.ok) { + this.errorText = "Fehler, Gerät antwortet nicht"; + } else { + this.configurationStates.blumy.configuration = + blumyConfiguration; + this.configurationStates.blumy.open = true; + this.configurationStates.blumy.message = { + content: this.configurationStates.blumy.testMessage.success, + type: "success", + }; + } + } else { + this.configurationStates.blumy.message = { + content: this.configurationStates.blumy.testMessage.error, + type: "error", + }; + } + } + async firstUpdated() { this.configurationStates.blumy.formElement = this.cloudFormElement; this.configurationStates.http.formElement = this.httpFormElement; @@ -194,13 +237,16 @@ export class CloudPage extends BasePage { configurationState.open = true; } } + const queryParameters = new URLSearchParams(location.search); + if (queryParameters.has("token") && queryParameters.has("blumyUrl")) { + await this.loadConfigFromQuery(queryParameters); + } this.configurationStates = { ...this.configurationStates }; this.updateConfigured(); } async handleExternalSetup() { - const originHttps = location.origin.replace("http", "https"); - location.href = `https://blumy.cloud/selector?redirect=${location.origin}/?page=5&apiUrl=${originHttps}/api/cloudSetup/blumy`; + location.href = `https://blumy.cloud/selector?redirect=${location.href}`; } render() { @@ -208,12 +254,14 @@ export class CloudPage extends BasePage { Automatische Schnittstellen-Konfiguration - +
+ +

Manuelle Schnittstellen-Konfiguration setTimeout(res, 5000)); } } - interval = setInterval(() => { - this.updateNetworks(); - }, 5000); - constructor() { super(); this.updateNetworks(); @@ -33,7 +34,7 @@ export class WifiScannerPage extends BasePage { disconnectedCallback() { super.disconnectedCallback(); - clearInterval(this.interval); + this.shouldUpdateNetworks = false; } onNetworkClick(e: CustomEvent) { diff --git a/Firmware/main/CMakeLists.txt b/Firmware/main/CMakeLists.txt index cf0c655..8fc61bb 100644 --- a/Firmware/main/CMakeLists.txt +++ b/Firmware/main/CMakeLists.txt @@ -1,4 +1,2 @@ idf_component_register(SRCS "index_html.c" "plantstore.c" "plantfi.c" "configuration_mode_server.c" "peripherals/sensors.c" "peripherals/adc.c" "main.c" - INCLUDE_DIRS "." - EMBED_TXTFILES "certs/servercert.pem" - "certs/prvtkey.pem") + INCLUDE_DIRS ".") diff --git a/Firmware/main/certs/generate-certs.sh b/Firmware/main/certs/generate-certs.sh deleted file mode 100755 index b70e319..0000000 --- a/Firmware/main/certs/generate-certs.sh +++ /dev/null @@ -1 +0,0 @@ -openssl req -newkey rsa:2048 -nodes -keyout prvtkey.pem -x509 -days 3650 -out servercert.pem -subj "/CN=Blumy HTTPS Server" \ No newline at end of file diff --git a/Firmware/main/certs/prvtkey.pem b/Firmware/main/certs/prvtkey.pem deleted file mode 100644 index 0928c41..0000000 --- a/Firmware/main/certs/prvtkey.pem +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDHsxSujHZ3DT6/ -T6uiGVG7fnYQwK2fzvYaPSdOy7g1iO4GfZbOBfQNTQ71XRqvCCPNBijE7Qwur76p -YcQpR36ddlQ1rSl8mOwT/klDUNKXqDqHPseJ8F0PYw8Jgbcv5VbIuZTyDmYysDuW -5Lm6UPWmxZh+DxcORL1YEDs7c0UbUIFpoQoOplGSYSE9MrcOECLXLqVw208WZ4Bm -2J0xwO9u+gbQ9JPU4Zruja3uyHmpw7GYukf9E0Y7gFs6sBLAINqdBLoIscYb0DpL -6AnVXVd+SmmN+JrmyEpjYQzSGBhGIhz/vdyMd9zbqBlxVVv7ju9jAUPlDxcsm624 -mceUjUUvAgMBAAECggEAHkbZlGCJwiFZHufv2trhiD6InPVG0vYDBwBi5MXrOaah -2+G6Svsea3kq6EAY6xTzWe1x90VZ9abB4+wFhx1RUNifX3yk+ms0TmWyat578fAD -YPzqLiYp8yAZfV9UIZKw9oF4gmh0zdY9T/KBRte+dBinjDkyeCsrf94Eyk3UL5Xf -opB1J7gC4ZKOWbdsGdn72cp0YeFvLBdb1fa3rLBn7QLrEP3umvn8Avd3vsOQ8zWg -uL9iCwbmpj2WccHeZRmaYvYsJ49onSmp41+RyFSv4ITf4d4U58HSHRR3soVNf8/c -7tQDzuH4qGTSnyPooer6Y+g3IGXK9LQnzxTsvYWy7QKBgQDrmMymaw8aONnf2YmL -ui2bYFQTOgk1djli5BccQtkBb2Jw2znP556lLzTIWlCbmWGW9L3W2pfAoDTCIO27 -3Knrj35rPO1nnBUHsdtgLhgVliQvgiuZXudJjYaKgbTjn+uyZ5hOmD2ibzcXDkLi -IX8gQrMGXoH5Spglhh8otsPSowKBgQDY/m9FW2CQGyve8MhuN9Imj7RPjYbytk1r -xUYoMblaaKew3DxT+VanJC5qEVcvGnJPyqSad67HsXAj4oiVngIIPX8d1DLyGyO+ -hxECMyjTRwq9FQwAbDpSylbLQOYWr8DVfY4I0879vkCxJN4NGIvbZtDh6a+2rdnM -LMZUaae4BQKBgB8Kq/RFaOEAmpxm8juJ1VaCk7FQ1UPJBvijqvPbTvJkdaj/CZf+ -IaYMGT1IwRQvWm9kYdr8REBqG2l0oz48bdsOtg51IaakJxUzdv8uM5gshyoHUa1M -ltbXIeIAAxB20rxX7/ZzErPjSXPtOhzHYxOiFiqBq0hobrGLAXIA2r5XAoGAY24C -8pbyYlXw/lD6pnZxlzXV+3XwVhru0uksQpK2ShUWcdYY1qmz6RaNJhEYD/9gTeuf -DSC2N864gdj1mQk0CS6UpshrJ8ED2fPt+UIT/OvaodWZEECHYRRSPQRZ6h9SjwDf -KnBTsrWQ0xr/nKSYwUoVgM8hsuVqnUIPBvL65TkCgYB0lALH0hZxos8bPvQvUIzk -+cnXWCIHejWQ3hPtGKOrT2ugyvAKTnvbtreiLDIt67c6SG+8cpZMvOVRxIE2BTLN -LtjMXByDh6xCEvZszAcj17Txmg9kz+LlgNFPUcfjaeqcclbwdajphetzwqpdDTVP -ANp5dThZ5BQUJTgf/8qBQg== ------END PRIVATE KEY----- diff --git a/Firmware/main/certs/servercert.pem b/Firmware/main/certs/servercert.pem deleted file mode 100644 index 0709e47..0000000 --- a/Firmware/main/certs/servercert.pem +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDGzCCAgOgAwIBAgIUQ9eSTZ4LT3UdjZwf+8CQahcRgUMwDQYJKoZIhvcNAQEL -BQAwHTEbMBkGA1UEAwwSQmx1bXkgSFRUUFMgU2VydmVyMB4XDTI0MDkwNTA5MDA1 -MFoXDTM0MDkwMzA5MDA1MFowHTEbMBkGA1UEAwwSQmx1bXkgSFRUUFMgU2VydmVy -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx7MUrox2dw0+v0+rohlR -u352EMCtn872Gj0nTsu4NYjuBn2WzgX0DU0O9V0arwgjzQYoxO0MLq++qWHEKUd+ -nXZUNa0pfJjsE/5JQ1DSl6g6hz7HifBdD2MPCYG3L+VWyLmU8g5mMrA7luS5ulD1 -psWYfg8XDkS9WBA7O3NFG1CBaaEKDqZRkmEhPTK3DhAi1y6lcNtPFmeAZtidMcDv -bvoG0PST1OGa7o2t7sh5qcOxmLpH/RNGO4BbOrASwCDanQS6CLHGG9A6S+gJ1V1X -fkppjfia5shKY2EM0hgYRiIc/73cjHfc26gZcVVb+47vYwFD5Q8XLJutuJnHlI1F -LwIDAQABo1MwUTAdBgNVHQ4EFgQU46/kQsNdMIUViADkWp1Zd0kL0rYwHwYDVR0j -BBgwFoAU46/kQsNdMIUViADkWp1Zd0kL0rYwDwYDVR0TAQH/BAUwAwEB/zANBgkq -hkiG9w0BAQsFAAOCAQEAhz5OC7yEN5Rel9E7AGf5NHKX19Bxg8sKJwFo93QPTgWy -tMIPR2O4HeGxaF0wOBH+CAWYF+/3r/OXSVIs7iz42i0lPZQ7ucagv32vQllBtaiZ -Tlen4dRYRZWIh3guh9UeGHaWjn3x04NgLyPBxoQLH8VO1rGGQbNb1iygzr7uDXEL -4rnqscXyHThCLLp6InKliRIF6GTwFeU5dt4SiKZj+1BxFsRy9pe4r/MC6q/tHdPz -ZI/A/vawdEkQ1VL9d0M1/pYYxTlm+3QQWfRdEFddhECycHqSeC8c28RUWeE0OXX0 -RJiWDPo59gbGZwwQPF43N4SrHcv4lzq6gPSEuXtgJw== ------END CERTIFICATE----- diff --git a/Firmware/main/configuration_mode_server.c b/Firmware/main/configuration_mode_server.c index 0fc3233..297e9b0 100644 --- a/Firmware/main/configuration_mode_server.c +++ b/Firmware/main/configuration_mode_server.c @@ -1,7 +1,6 @@ #include "configuration_mode_server.h" #include "esp_log.h" -#include "esp_https_server.h" #include "cJSON.h" #include "plantfi.h" @@ -213,7 +212,6 @@ esp_err_t post_api_cloudSetup_blumy_handler(httpd_req_t *req) plantstore_setCloudConfigurationBlumy(token, url); const char resp[] = "OK"; - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; } @@ -291,7 +289,6 @@ esp_err_t get_api_cloudSetup_blumy_handler(httpd_req_t *req) char *resp = cJSON_Print(root); cJSON_Delete(root); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); free(resp); return ESP_OK; @@ -355,14 +352,13 @@ esp_err_t post_api_cloudTest_blumy_handler(httpd_req_t *req) const bool connectionOk = plantfi_test_blumy_connection(token, url); char resp[6]; sprintf(resp, "%s", connectionOk ? "true" : "false"); - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; } esp_err_t post_api_cloudDisable_mqtt_handler(httpd_req_t *req) { - plantstore_setCloudConfigurationMqtt("", "", 0, "", "", "", ""); + plantstore_resetCloudConfigurationMqtt(); const char resp[] = "OK"; httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; @@ -370,7 +366,7 @@ esp_err_t post_api_cloudDisable_mqtt_handler(httpd_req_t *req) esp_err_t post_api_cloudDisable_http_handler(httpd_req_t *req) { - plantstore_setCloudConfigurationHttp("", "", ""); + plantstore_resetCloudConfigurationHttp(); const char resp[] = "OK"; httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; @@ -378,9 +374,8 @@ esp_err_t post_api_cloudDisable_http_handler(httpd_req_t *req) esp_err_t post_api_cloudDisable_blumy_handler(httpd_req_t *req) { - plantstore_setCloudConfigurationBlumy("", ""); + plantstore_resetCloudConfigurationBlumy(); const char resp[] = "OK"; - httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); return ESP_OK; } @@ -532,11 +527,10 @@ esp_err_t get_api_sensor_data_handler(httpd_req_t *req) esp_err_t post_api_factoryReset_handler(httpd_req_t *req) { - plantstore_factoryReset(); - const char resp[] = "OK"; httpd_resp_send(req, resp, HTTPD_RESP_USE_STRLEN); + plantstore_factoryReset(); esp_restart(); return ESP_OK; } @@ -899,35 +893,6 @@ void register_uri_handlers(httpd_handle_t server) httpd_register_uri_handler(server, &get); } -/* Function for starting the webserver */ -httpd_handle_t start_https_webserver(void) -{ - ESP_LOGI("HTTP", "Starting HTTPS server"); - /* Empty handle to esp_http_server */ - httpd_handle_t server = NULL; - - /* Generate default configuration */ - httpd_ssl_config_t config = HTTPD_SSL_CONFIG_DEFAULT(); - config.httpd.uri_match_fn = httpd_uri_match_wildcard; - config.httpd.max_uri_handlers = 50; - - extern const unsigned char servercert_start[] asm("_binary_servercert_pem_start"); - extern const unsigned char servercert_end[] asm("_binary_servercert_pem_end"); - config.servercert = servercert_start; - config.servercert_len = servercert_end - servercert_start; - - extern const unsigned char prvtkey_pem_start[] asm("_binary_prvtkey_pem_start"); - extern const unsigned char prvtkey_pem_end[] asm("_binary_prvtkey_pem_end"); - config.prvtkey_pem = prvtkey_pem_start; - config.prvtkey_len = prvtkey_pem_end - prvtkey_pem_start; - - /* Start the httpd server */ - ESP_ERROR_CHECK(httpd_ssl_start(&server, &config)); - register_uri_handlers(server); - /* If server failed to start, handle will be NULL */ - return server; -} - httpd_handle_t start_webserver(void) { ESP_LOGI("HTTP", "Starting HTTP server"); @@ -946,16 +911,6 @@ httpd_handle_t start_webserver(void) return server; } -/* Function for stopping the webserver */ -void stop_https_webserver(httpd_handle_t server) -{ - if (server) - { - /* Stop the httpd server */ - httpd_ssl_stop(server); - } -} - /* Function for stopping the webserver */ void stop_webserver(httpd_handle_t server) { diff --git a/Firmware/main/configuration_mode_server.h b/Firmware/main/configuration_mode_server.h index 450eed1..1c8e543 100644 --- a/Firmware/main/configuration_mode_server.h +++ b/Firmware/main/configuration_mode_server.h @@ -4,7 +4,5 @@ /* Function for starting the webserver */ httpd_handle_t start_webserver(void); -httpd_handle_t start_https_webserver(void); /* Function for stopping the webserver */ -void stop_webserver(httpd_handle_t server); -void stop_https_webserver(httpd_handle_t server); \ No newline at end of file +void stop_webserver(httpd_handle_t server); \ No newline at end of file diff --git a/Firmware/main/main.c b/Firmware/main/main.c index 2f8682c..1a854b3 100644 --- a/Firmware/main/main.c +++ b/Firmware/main/main.c @@ -40,7 +40,6 @@ void configuration_mode(bool isConfigured) ESP_LOGI("MODE", "Starting webserver"); httpd_handle_t webserver = start_webserver(); - httpd_handle_t https_webserver = start_https_webserver(); plantfi_configureStaFromPlantstore(); bool wasBootButtonPressed = false; @@ -64,7 +63,6 @@ void configuration_mode(bool isConfigured) vTaskDelay(10 / portTICK_PERIOD_MS); // Reset watchdog } stop_webserver(webserver); - stop_https_webserver(https_webserver); sensors_detach_boot_button_interrupt(); sensors_playShutdownSound(); start_deep_sleep(); diff --git a/Firmware/main/plantstore.c b/Firmware/main/plantstore.c index 679787b..c9c3ea1 100644 --- a/Firmware/main/plantstore.c +++ b/Firmware/main/plantstore.c @@ -84,6 +84,16 @@ void plantstore_setCloudConfigurationHttp(char *sensorId, char *url, char *auth) nvs_close(nvs_handle); } +void plantstore_resetCloudConfigurationHttp() +{ + nvs_handle_t nvs_handle = plantstore_openNvsReadWrite(); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, HTTP_SENSORID_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, HTTP_URL_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, HTTP_AUTH_KEY)); + ESP_ERROR_CHECK(nvs_commit(nvs_handle)); + nvs_close(nvs_handle); +} + bool plantstore_getCloudConfigurationMqtt(char *sensorId, char *server, int16_t *port, char *username, char *password, char *topic, char *clientId, size_t sensorId_size, size_t server_size, size_t username_size, size_t password_size, size_t topic_size, size_t clientId_size) { nvs_handle_t nvs_handle = plantstore_openNvsReadOnly(); @@ -115,6 +125,20 @@ void plantstore_setCloudConfigurationMqtt(char *sensorId, char *server, int16_t nvs_close(nvs_handle); } +void plantstore_resetCloudConfigurationMqtt() +{ + nvs_handle_t nvs_handle = plantstore_openNvsReadWrite(); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_SENSORID_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_SERVER_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_PORT_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_USERNAME_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_PASSWORD_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_TOPIC_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, MQTT_CLIENTID_KEY)); + ESP_ERROR_CHECK(nvs_commit(nvs_handle)); + nvs_close(nvs_handle); +} + bool plantstore_getCloudConfigurationBlumy(char *token, char *url, size_t token_size, size_t url_size) { nvs_handle_t nvs_handle = plantstore_openNvsReadOnly(); @@ -136,6 +160,15 @@ void plantstore_setCloudConfigurationBlumy(char *token, char *url) nvs_close(nvs_handle); } +void plantstore_resetCloudConfigurationBlumy() +{ + nvs_handle_t nvs_handle = plantstore_openNvsReadWrite(); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, BLUMY_TOKEN_KEY)); + ESP_ERROR_CHECK_WITHOUT_ABORT(nvs_erase_key(nvs_handle, BLUMY_URL_KEY)); + ESP_ERROR_CHECK(nvs_commit(nvs_handle)); + nvs_close(nvs_handle); +} + bool plantstore_getSensorTimeoutSleepMs(uint64_t *timeoutMs) { nvs_handle_t nvs_handle = plantstore_openNvsReadOnly(); diff --git a/Firmware/main/plantstore.h b/Firmware/main/plantstore.h index 5dd90d8..9c0fd96 100644 --- a/Firmware/main/plantstore.h +++ b/Firmware/main/plantstore.h @@ -28,10 +28,13 @@ bool plantstore_getWifiCredentials(char *ssid, char *password, size_t ssid_size, void plantstore_setWifiCredentials(char *ssid, char *password); bool plantstore_getCloudConfigurationHttp(char *sensorId, char *url, char *auth, size_t sensorId_size, size_t url_size, size_t auth_size); void plantstore_setCloudConfigurationHttp(char *sensorId, char *url, char *auth); +void plantstore_resetCloudConfigurationHttp(); bool plantstore_getCloudConfigurationMqtt(char *sensorId, char *server, int16_t *port, char *username, char *password, char *topic, char *clientId, size_t sensorId_size, size_t server_size, size_t username_size, size_t password_size, size_t topic_size, size_t clientId_size); void plantstore_setCloudConfigurationMqtt(char *sensorId, char *server, int16_t port, char *username, char *password, char *topic, char *clientId); +void plantstore_resetCloudConfigurationMqtt(); bool plantstore_getCloudConfigurationBlumy(char *token, char *url, size_t token_size, size_t url_size); void plantstore_setCloudConfigurationBlumy(char *token, char *url); +void plantstore_resetCloudConfigurationBlumy(); bool plantstore_getSensorTimeoutSleepMs(uint64_t *timeoutMs); void plantstore_setSensorTimeoutSleepMs(uint64_t timeoutMs); bool plantstore_getConfigurationModeTimeoutMs(int32_t *timeoutMs); diff --git a/Firmware/sdkconfig b/Firmware/sdkconfig index cc6af04..06376d1 100644 --- a/Firmware/sdkconfig +++ b/Firmware/sdkconfig @@ -840,7 +840,7 @@ CONFIG_ESP_GDBSTUB_MAX_TASKS=32 # # ESP HTTP client # -CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=y +# CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS is not set # CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH is not set # CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH is not set # CONFIG_ESP_HTTP_CLIENT_ENABLE_CUSTOM_TRANSPORT is not set @@ -868,7 +868,7 @@ CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP=y # # ESP HTTPS server # -CONFIG_ESP_HTTPS_SERVER_ENABLE=y +# CONFIG_ESP_HTTPS_SERVER_ENABLE is not set # end of ESP HTTPS server # diff --git a/Server/src/lib/api.ts b/Server/src/lib/api.ts index 5fadaaf..bf0853d 100644 --- a/Server/src/lib/api.ts +++ b/Server/src/lib/api.ts @@ -79,24 +79,12 @@ export async function submitUnsubscription( .then((text) => SuperJSON.parse(text)); } -export async function setupSensorOnLocalEsp( - writeToken: string, - redirectUrl: string, - apiUrl: string -) { +export function setupSensorOnLocalEsp(writeToken: string, redirectUrl: string) { const originHttp = window.location.origin.replace('https', 'http'); - try { - const res = await fetch(apiUrl, { - method: 'POST', - body: `token=${writeToken}\nurl=${originHttp}/api/v2/data\n` - }); - if (res.ok) { - location.href = redirectUrl; - } else { - return 'Unbekannter Fehler beim Einrichten des Sensors. Starte den Blumy Sensor neu und versuche es erneut.'; - } - } catch (err) { - console.log(err); - return 'Der Sensor konnte nicht synchronisiert werden. Bitte überprüfe die Verbindung zum Blumy Sensor.'; - } + const url = new URL(redirectUrl); + const query = new URLSearchParams(url.search); + query.set('token', writeToken); + query.set('blumyUrl', `${originHttp}/api/v2/data`); + url.search = query.toString(); + location.href = url.toString(); } diff --git a/Server/src/routes/selector/+page.svelte b/Server/src/routes/selector/+page.svelte index a8efdd6..85670d8 100644 --- a/Server/src/routes/selector/+page.svelte +++ b/Server/src/routes/selector/+page.svelte @@ -13,13 +13,12 @@ async function sensorClick(sensor: SensorDTO) { sensorClicked = true; const redirectUrl = $page.url.searchParams.get('redirect'); - const apiUrl = $page.url.searchParams.get('apiUrl'); - if (!redirectUrl || !apiUrl) { + if (!redirectUrl) { error = 'Ein Fehler ist aufgetreten. Bitte verbinde dich mit dem Sensor und versuche es erneut.'; return; } - error = await setupSensorOnLocalEsp(sensor.writeToken, redirectUrl, apiUrl); + setupSensorOnLocalEsp(sensor.writeToken, redirectUrl); } async function createNewSensor() { diff --git a/Server/src/routes/selector/sensor/new/+page.svelte b/Server/src/routes/selector/sensor/new/+page.svelte index 6eafadf..a3d933e 100644 --- a/Server/src/routes/selector/sensor/new/+page.svelte +++ b/Server/src/routes/selector/sensor/new/+page.svelte @@ -9,13 +9,12 @@ async function onSensorCreate() { const redirectUrl = $page.url.searchParams.get('redirect'); - const apiUrl = $page.url.searchParams.get('apiUrl'); - if (!redirectUrl || !apiUrl) { + if (!redirectUrl) { error = 'Ein Fehler ist aufgetreten. Bitte verbinde dich mit dem Sensor und versuche es erneut.'; return; } - error = await setupSensorOnLocalEsp(createdSensor.tokens.write, redirectUrl, apiUrl); + setupSensorOnLocalEsp(createdSensor.tokens.write, redirectUrl); } $: if (createdSensor) {