From be3de91ffcef7ce945c4f82e4e78d731dbcda347 Mon Sep 17 00:00:00 2001 From: doudar Date: Tue, 6 Dec 2022 18:58:58 -0600 Subject: [PATCH] added reboot when BLE device selection changed --- include/SmartSpin_parameters.h | 4 ++-- src/BLE_Client.cpp | 16 ++++++++-------- src/BLE_Setup.cpp | 4 ++-- src/HTTP_Server_Basic.cpp | 18 ++++++++++++++---- src/Main.cpp | 4 ++-- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/include/SmartSpin_parameters.h b/include/SmartSpin_parameters.h index c5cb6924..941e265d 100644 --- a/include/SmartSpin_parameters.h +++ b/include/SmartSpin_parameters.h @@ -126,8 +126,8 @@ class userParameters { bool getAutoUpdate() { return autoUpdate; } const char* getSsid() { return ssid.c_str(); } const char* getPassword() { return password.c_str(); } - const char* getconnectedPowerMeter() { return connectedPowerMeter.c_str(); } - const char* getconnectedHeartMonitor() { return connectedHeartMonitor.c_str(); } + const char* getConnectedPowerMeter() { return connectedPowerMeter.c_str(); } + const char* getConnectedHeartMonitor() { return connectedHeartMonitor.c_str(); } int getStepperPower() { return stepperPower; } int getMaxWatts() { return maxWatts; } int getMinWatts() { return minWatts; } diff --git a/src/BLE_Client.cpp b/src/BLE_Client.cpp index 93ccdcb0..f8b543af 100644 --- a/src/BLE_Client.cpp +++ b/src/BLE_Client.cpp @@ -347,24 +347,24 @@ void MyAdvertisedDeviceCallback::onResult(BLEAdvertisedDevice *advertisedDevice) // not specified. SS2K_LOG(BLE_CLIENT_LOG_TAG, "Matching Device Name: %s", aDevName.c_str()); if (advertisedDevice->getServiceUUID() == HEARTSERVICE_UUID) { - if (String(userConfig.getconnectedHeartMonitor()) == "any") { + if (String(userConfig.getConnectedHeartMonitor()) == "any") { SS2K_LOG(BLE_CLIENT_LOG_TAG, "HR String Matched Any"); // continue - } else if (aDevName != String(userConfig.getconnectedHeartMonitor()) || (String(userConfig.getconnectedHeartMonitor()) == "none")) { - SS2K_LOG(BLE_CLIENT_LOG_TAG, "Skipping non-selected HRM |%s|%s", aDevName.c_str(), userConfig.getconnectedHeartMonitor()); + } else if (aDevName != String(userConfig.getConnectedHeartMonitor()) || (String(userConfig.getConnectedHeartMonitor()) == "none")) { + SS2K_LOG(BLE_CLIENT_LOG_TAG, "Skipping non-selected HRM |%s|%s", aDevName.c_str(), userConfig.getConnectedHeartMonitor()); return; - } else if (aDevName == String(userConfig.getconnectedHeartMonitor())) { + } else if (aDevName == String(userConfig.getConnectedHeartMonitor())) { SS2K_LOG(BLE_CLIENT_LOG_TAG, "HR String Matched %s", aDevName.c_str()); } } else { // Already tested -->((advertisedDevice->getServiceUUID()(CYCLINGPOWERSERVICE_UUID) || advertisedDevice->getServiceUUID()(FLYWHEEL_UART_SERVICE_UUID) || // advertisedDevice->getServiceUUID()(FITNESSMACHINESERVICE_UUID))) - if (String(userConfig.getconnectedPowerMeter()) == "any") { + if (String(userConfig.getConnectedPowerMeter()) == "any") { SS2K_LOG(BLE_CLIENT_LOG_TAG, "PM String Matched Any"); // continue - } else if (aDevName != String(userConfig.getconnectedPowerMeter()) || (String(userConfig.getconnectedPowerMeter()) == "none")) { - SS2K_LOG(BLE_CLIENT_LOG_TAG, "Skipping non-selected PM |%s|%s", aDevName.c_str(), userConfig.getconnectedPowerMeter()); + } else if (aDevName != String(userConfig.getConnectedPowerMeter()) || (String(userConfig.getConnectedPowerMeter()) == "none")) { + SS2K_LOG(BLE_CLIENT_LOG_TAG, "Skipping non-selected PM |%s|%s", aDevName.c_str(), userConfig.getConnectedPowerMeter()); return; - } else if (aDevName == String(userConfig.getconnectedPowerMeter())) { + } else if (aDevName == String(userConfig.getConnectedPowerMeter())) { SS2K_LOG(BLE_CLIENT_LOG_TAG, "PM String Matched %s", aDevName.c_str()); } } diff --git a/src/BLE_Setup.cpp b/src/BLE_Setup.cpp index 178afb2e..a2c645ff 100644 --- a/src/BLE_Setup.cpp +++ b/src/BLE_Setup.cpp @@ -28,10 +28,10 @@ void setupBLE() { // Common BLE setup for both client and server SS2K_LOG(BLE_SETUP_LOG_TAG, "BLE Notify Task Started"); vTaskDelay(100 / portTICK_PERIOD_MS); - if (strcmp(userConfig.getconnectedPowerMeter(), "none") != 0 || strcmp(userConfig.getconnectedHeartMonitor(), "none") != 0) { + if (strcmp(userConfig.getConnectedPowerMeter(), "none") != 0 || strcmp(userConfig.getConnectedHeartMonitor(), "none") != 0) { spinBLEClient.serverScan(true); SS2K_LOG(BLE_SETUP_LOG_TAG, "Scanning"); } - SS2K_LOG(BLE_SETUP_LOG_TAG, "%s %s", userConfig.getconnectedPowerMeter(), userConfig.getconnectedHeartMonitor()); + SS2K_LOG(BLE_SETUP_LOG_TAG, "%s %s", userConfig.getConnectedPowerMeter(), userConfig.getConnectedHeartMonitor()); SS2K_LOG(BLE_SETUP_LOG_TAG, "End BLE Setup"); } diff --git a/src/HTTP_Server_Basic.cpp b/src/HTTP_Server_Basic.cpp index 8718b107..81108aae 100644 --- a/src/HTTP_Server_Basic.cpp +++ b/src/HTTP_Server_Basic.cpp @@ -436,6 +436,7 @@ void HTTP_Server::settingsProcessor() { String tString; bool wasBTUpdate = false; bool wasSettingsUpdate = false; + bool reboot = false; if (!server.arg("ssid").isEmpty()) { tString = server.arg("ssid"); tString.trim(); @@ -528,7 +529,9 @@ void HTTP_Server::settingsProcessor() { wasBTUpdate = true; if (server.arg("blePMDropdown")) { tString = server.arg("blePMDropdown"); - userConfig.setConnectedPowerMeter(server.arg("blePMDropdown")); + if (tString != userConfig.getConnectedPowerMeter()) { + reboot = true; + } } else { userConfig.setConnectedPowerMeter("any"); } @@ -536,13 +539,16 @@ void HTTP_Server::settingsProcessor() { if (!server.arg("bleHRDropdown").isEmpty()) { wasBTUpdate = true; if (server.arg("bleHRDropdown")) { - tString = server.arg("bleHRDropdown"); + bool reset = false; + tString = server.arg("bleHRDropdown"); + if (tString != userConfig.getConnectedHeartMonitor()) { + reboot = true; + } userConfig.setConnectedHeartMonitor(server.arg("bleHRDropdown")); } else { userConfig.setConnectedHeartMonitor("any"); } } - if (!server.arg("session1HR").isEmpty()) { // Needs checking for unrealistic numbers. userPWC.session1HR = server.arg("session1HR").toInt(); } @@ -579,7 +585,7 @@ void HTTP_Server::settingsProcessor() { } else { // Normal response response += "Network settings will be applied at next reboot.
Everything " - "else is availiable immediately."; } @@ -589,6 +595,10 @@ void HTTP_Server::settingsProcessor() { userConfig.printFile(); userPWC.saveToLittleFS(); userPWC.printFile(); + if (reboot) { + vTaskDelay(100 / portTICK_PERIOD_MS); + ESP.restart(); + } } void HTTP_Server::stop() { diff --git a/src/Main.cpp b/src/Main.cpp index ea7e6d54..6c38c0d8 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -502,9 +502,9 @@ void SS2K::checkSerial() { void SS2K::checkBLEReconnect() { static int bleCheck = 0; - if (((userConfig.getconnectedHeartMonitor() != "any" && !spinBLEClient.connectedHR) || (userConfig.getconnectedPowerMeter() != "any" && !spinBLEClient.connectedPM)) && (bleCheck >= BLE_RECONNECT_INTERVAL)) { + if (((userConfig.getConnectedHeartMonitor() != "any" && !spinBLEClient.connectedHR) || (userConfig.getConnectedPowerMeter() != "any" && !spinBLEClient.connectedPM)) && (bleCheck >= BLE_RECONNECT_INTERVAL)) { bleCheck = 0; - if (((userConfig.getconnectedPowerMeter() == "none") && (userConfig.getconnectedHeartMonitor() == "none"))){ + if (((userConfig.getConnectedPowerMeter() == "none") && (userConfig.getConnectedHeartMonitor() == "none"))){ return; } if (!NimBLEDevice::getScan()->isScanning()) {