diff --git a/src/Sensors.h b/src/Sensors.h index 7b0cc61..d481816 100644 --- a/src/Sensors.h +++ b/src/Sensors.h @@ -334,7 +334,7 @@ public: uint8_t valueId = (uint8_t) valueType; if (!isValidValueId(valueId)) { - return false; + return 0; } float value = 0.0f; diff --git a/src/SensorsTask.h b/src/SensorsTask.h index cba050e..135d20f 100644 --- a/src/SensorsTask.h +++ b/src/SensorsTask.h @@ -385,7 +385,7 @@ protected: continue; } - const float sensorResistance = value > 0.001f + const float sensorResistance = value > 1 ? DEFAULT_NTC_REF_RESISTANCE / (DEFAULT_NTC_VREF / (float) value - 1.0f) : 0.0f; const float rawTemp = 1.0f / ( @@ -577,7 +577,7 @@ protected: bool subscribeToBleDevice(const uint8_t sensorId, NimBLEClient* pClient) { auto& sSensor = Sensors::settings[sensorId]; - auto pAddress = pClient->getPeerAddress().toString().c_str(); + auto pAddress = pClient->getPeerAddress().toString(); NimBLERemoteService* pService = nullptr; NimBLERemoteCharacteristic* pChar = nullptr; @@ -588,13 +588,13 @@ protected: if (!pService) { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to find env service (%s) on device %s"), - sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress + sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str() ); } else { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found env service (%s) on device %s"), - sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress + sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str() ); // 0x2A6E - Notify temperature x0.01C (pvvx) @@ -606,7 +606,7 @@ protected: if (pChar && (pChar->canNotify() || pChar->canIndicate())) { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found temp char (%s) in env service on device %s"), - sensorId, sSensor.name, charUuid.toString().c_str(), pAddress + sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str() ); pChar->unsubscribe(); @@ -661,14 +661,14 @@ protected: Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to temp char (%s) in env service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } else { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to temp char (%s) in env service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } } @@ -683,7 +683,7 @@ protected: if (pChar && (pChar->canNotify() || pChar->canIndicate())) { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found temp char (%s) in env service on device %s"), - sensorId, sSensor.name, charUuid.toString().c_str(), pAddress + sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str() ); pChar->unsubscribe(); @@ -738,14 +738,14 @@ protected: Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to temp char (%s) in env service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } else { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to temp char (%s) in env service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } } @@ -754,7 +754,7 @@ protected: if (!tempNotifyCreated) { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found supported temp chars in env service on device %s"), - sensorId, sSensor.name, pAddress + sensorId, sSensor.name, pAddress.c_str() ); pClient->disconnect(); @@ -772,7 +772,7 @@ protected: if (pChar && (pChar->canNotify() || pChar->canIndicate())) { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found humidity char (%s) in env service on device %s"), - sensorId, sSensor.name, charUuid.toString().c_str(), pAddress + sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str() ); pChar->unsubscribe(); @@ -827,14 +827,14 @@ protected: Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to humidity char (%s) in env service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } else { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to humidity char (%s) in env service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } } @@ -843,7 +843,7 @@ protected: if (!humidityNotifyCreated) { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found supported humidity chars in env service on device %s"), - sensorId, sSensor.name, pAddress + sensorId, sSensor.name, pAddress.c_str() ); } } @@ -857,13 +857,13 @@ protected: if (!pService) { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to find battery service (%s) on device %s"), - sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress + sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str() ); } else { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found battery service (%s) on device %s"), - sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress + sensorId, sSensor.name, serviceUuid.toString().c_str(), pAddress.c_str() ); // 0x2A19 - Notify the battery charge level 0..99% (pvvx) @@ -875,7 +875,7 @@ protected: if (pChar && (pChar->canNotify() || pChar->canIndicate())) { Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': found battery char (%s) in battery service on device %s"), - sensorId, sSensor.name, charUuid.toString().c_str(), pAddress + sensorId, sSensor.name, charUuid.toString().c_str(), pAddress.c_str() ); pChar->unsubscribe(); @@ -930,14 +930,14 @@ protected: Log.straceln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': subscribed to battery char (%s) in battery service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } else { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': failed to subscribe to battery char (%s) in battery service on device %s"), sensorId, sSensor.name, - charUuid.toString().c_str(), pAddress + charUuid.toString().c_str(), pAddress.c_str() ); } } @@ -946,7 +946,7 @@ protected: if (!batteryNotifyCreated) { Log.swarningln( FPSTR(L_SENSORS_BLE), F("Sensor #%hhu '%s': not found supported battery chars in battery service on device %s"), - sensorId, sSensor.name, pAddress + sensorId, sSensor.name, pAddress.c_str() ); } } diff --git a/src/Settings.h b/src/Settings.h index af71a46..17cdad1 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -170,15 +170,15 @@ struct Settings { struct { struct { bool enabled = false; - byte gpio = GPIO_IS_NOT_CONFIGURED; - byte invertState = false; + uint8_t gpio = GPIO_IS_NOT_CONFIGURED; + bool invertState = false; unsigned short thresholdTime = 60; } input; struct { bool enabled = false; - byte gpio = GPIO_IS_NOT_CONFIGURED; - byte invertState = false; + uint8_t gpio = GPIO_IS_NOT_CONFIGURED; + bool invertState = false; unsigned short thresholdTime = 60; bool onFault = true; bool onLossConnection = true; diff --git a/src/utils.h b/src/utils.h index 4913357..ac4ffa2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -72,7 +72,7 @@ time_t mkgmtime(const struct tm *ptm) { inline bool isDigit(const char* ptr) { char* endPtr; - strtol(ptr, &endPtr, 10); + auto tmp = strtol(ptr, &endPtr, 10); return *endPtr == 0; } @@ -1324,7 +1324,7 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false if (!src[FPSTR(S_HEATING)][FPSTR(S_MIN_TEMP)].isNull()) { unsigned char value = src[FPSTR(S_HEATING)][FPSTR(S_MIN_TEMP)].as(); - if (value != dst.heating.minTemp && value >= vars.slave.heating.minTemp && value < vars.slave.heating.maxTemp && value != dst.heating.minTemp) { + if (value != dst.heating.minTemp && value >= vars.slave.heating.minTemp && value < vars.slave.heating.maxTemp && value != dst.heating.maxTemp) { dst.heating.minTemp = value; changed = true; } @@ -1333,7 +1333,7 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false if (!src[FPSTR(S_HEATING)][FPSTR(S_MAX_TEMP)].isNull()) { unsigned char value = src[FPSTR(S_HEATING)][FPSTR(S_MAX_TEMP)].as(); - if (value != dst.heating.maxTemp && value > vars.slave.heating.minTemp && value <= vars.slave.heating.maxTemp && value != dst.heating.maxTemp) { + if (value != dst.heating.maxTemp && value > vars.slave.heating.minTemp && value <= vars.slave.heating.maxTemp && value != dst.heating.minTemp) { dst.heating.maxTemp = value; changed = true; } @@ -1894,7 +1894,7 @@ bool jsonToSensorSettings(const uint8_t sensorId, const JsonVariantConst src, Se // gpio if (!src[FPSTR(S_GPIO)].isNull()) { - if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type == Sensors::Type::BLUETOOTH && dst.type == Sensors::Type::NTC_10K_TEMP) { + if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP) { if (dst.gpio != GPIO_IS_NOT_CONFIGURED) { dst.gpio = GPIO_IS_NOT_CONFIGURED; changed = true;