Skip to content

Commit

Permalink
added reboot when BLE device selection changed
Browse files Browse the repository at this point in the history
  • Loading branch information
doudar committed Dec 7, 2022
1 parent 7e6383a commit be3de91
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/SmartSpin_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
16 changes: 8 additions & 8 deletions src/BLE_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/BLE_Setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
18 changes: 14 additions & 4 deletions src/HTTP_Server_Basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -528,21 +529,26 @@ 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");
}
}
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();
}
Expand Down Expand Up @@ -579,7 +585,7 @@ void HTTP_Server::settingsProcessor() {
} else { // Normal response
response +=
"Network settings will be applied at next reboot. <br> Everything "
"else is availiable immediately.</h2></body><script> "
"else is available immediately.</h2></body><script> "
"setTimeout(\"location.href = 'http://" +
myIP.toString() + "/index.html';\",1000);</script></html>";
}
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit be3de91

Please sign in to comment.