diff --git a/include/WebThingConfig.h b/include/WebThingConfig.h index 909d1a6..90a0e8c 100755 --- a/include/WebThingConfig.h +++ b/include/WebThingConfig.h @@ -1,9 +1,8 @@ #ifndef AIRLY_INCLUDE_WEB_THINGS_CONFIG_H_ #define AIRLY_INCLUDE_WEB_THINGS_CONFIG_H_ -#if !defined(LARGE_JSON_BUFFERS) #define LARGE_JSON_BUFFERS 1 -#endif + #if !defined(ARDUINOJSON_USE_LONG_LONG) #define ARDUINOJSON_USE_LONG_LONG 1 #endif diff --git a/include/airly/Config.h b/include/airly/Config.h index 52f958e..e4b8c49 100755 --- a/include/airly/Config.h +++ b/include/airly/Config.h @@ -10,9 +10,16 @@ #if defined(THING_MODEL_B) #define THING_HAS_BME280 +#define THING_HAS_TEMPERATURE_PROPERTY +#define THING_HAS_HUMIDITY_PROPERTY +#define THING_HAS_BAROMETRIC_PRESSURE_PROPERTY +#define THING_HAS_DEW_POINT_PROPERTY #elif defined(THING_MODEL_M) #define THING_HAS_BME280 #define THING_HAS_MHZ19 +#define THING_HAS_TEMPERATURE_PROPERTY +#define THING_HAS_HUMIDITY_PROPERTY +#define THING_HAS_CARBON_DIOXIDE_PROPERTY #endif #if !defined(SCHEDULER_INTERVAL_UPDATE_PROPERTIES) diff --git a/include/airly/I18n.h b/include/airly/I18n.h index 62844cb..d0a3d20 100755 --- a/include/airly/I18n.h +++ b/include/airly/I18n.h @@ -16,21 +16,28 @@ namespace i18n { extern const char* DeviceTitle; -extern const char* UptimePropertyDescription; -extern const char* UptimePropertyTitle; -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_TEMPERATURE_PROPERTY) +extern const char* TemperaturePropertyDescription; +extern const char* TemperaturePropertyTitle; +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) +extern const char* HumidityPropertyDescription; +extern const char* HumidityPropertyTitle; +#endif + +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) extern const char* BarometricPressurePropertyDescription; extern const char* BarometricPressurePropertyTitle; +#endif + +#if defined(THING_HAS_DEW_POINT_PROPERTY) extern const char* DewPointPropertyDescription; extern const char* DewPointPropertyTitle; -extern const char* HumidityPropertyDescription; -extern const char* HumidityPropertyTitle; -extern const char* TemperaturePropertyDescription; -extern const char* TemperaturePropertyTitle; #endif -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) extern const char* CarbonDioxidePropertyDescription; extern const char* CarbonDioxidePropertyTitle; #endif diff --git a/include/airly/properties/BarometricPressure.h b/include/airly/properties/BarometricPressure.h index a4ffb25..6129802 100755 --- a/include/airly/properties/BarometricPressure.h +++ b/include/airly/properties/BarometricPressure.h @@ -7,7 +7,9 @@ /* WebThings framework */ #include +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) void describeBarometricPressureProperty(ThingDevice* device); void setBarometricPressureProperty(const float barometricPressure); +#endif #endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_BAROMETRIC_PRESSURE_H_ diff --git a/include/airly/properties/CarbonDioxide.h b/include/airly/properties/CarbonDioxide.h index c32258f..1ed1f07 100755 --- a/include/airly/properties/CarbonDioxide.h +++ b/include/airly/properties/CarbonDioxide.h @@ -7,7 +7,9 @@ /* WebThings framework */ #include +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) void describeCarbonDioxideProperty(ThingDevice* device); void setCarbonDioxideProperty(const unsigned short carbonDioxide); +#endif #endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_CARBON_DIOXIDE_H_ diff --git a/include/airly/properties/DewPoint.h b/include/airly/properties/DewPoint.h index 86871e8..3a4b173 100755 --- a/include/airly/properties/DewPoint.h +++ b/include/airly/properties/DewPoint.h @@ -7,8 +7,10 @@ /* WebThings framework */ #include +#if defined(THING_HAS_DEW_POINT_PROPERTY) void describeDewPointProperty(ThingDevice* device); void setDewPointProperty(const float DewPoint); float calculateDewPoint(const float temperature, const float humidity); +#endif #endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_DEW_POINT_H_ diff --git a/include/airly/properties/Humidity.h b/include/airly/properties/Humidity.h index b712939..7ad9744 100755 --- a/include/airly/properties/Humidity.h +++ b/include/airly/properties/Humidity.h @@ -7,7 +7,9 @@ /* WebThings framework */ #include +#if defined(THING_HAS_HUMIDITY_PROPERTY) void describeHumidityProperty(ThingDevice* device); void setHumidityProperty(const float humidity); +#endif #endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_HUMIDITY_H_ diff --git a/include/airly/properties/Temperature.h b/include/airly/properties/Temperature.h index 6bc390a..b3aa377 100755 --- a/include/airly/properties/Temperature.h +++ b/include/airly/properties/Temperature.h @@ -7,7 +7,9 @@ /* WebThings framework */ #include +#if defined(THING_HAS_TEMPERATURE_PROPERTY) void describeTemperatureProperty(ThingDevice* device); void setTemperatureProperty(const float temperature); +#endif #endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_TEMPERATURE_H_ diff --git a/include/airly/properties/Uptime.h b/include/airly/properties/Uptime.h deleted file mode 100755 index c322544..0000000 --- a/include/airly/properties/Uptime.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef AIRLY_INCLUDE_AIRLY_PROPERTIES_UPTIME_H_ -#define AIRLY_INCLUDE_AIRLY_PROPERTIES_UPTIME_H_ - -/* Config for WebThings framework */ -#include - -/* WebThings framework */ -#include - -void describeUptimeProperty(ThingDevice* device); -void updateUptimeProperty(); - -#endif // AIRLY_INCLUDE_AIRLY_PROPERTIES_UPTIME_H_ diff --git a/src/airly/Device.cc b/src/airly/Device.cc index 7b93d13..2081336 100755 --- a/src/airly/Device.cc +++ b/src/airly/Device.cc @@ -3,48 +3,63 @@ /* Preprocessor-based localization */ #include -/* Common properties */ -#include - -#if defined(THING_HAS_BME280) -/* Properties for Bosch Sensortec BME280 */ +/* Properties */ #include +#include #include #include #include -#define BME280_CAPABILITIES \ - "TemperatureSensor", "HumiditySensor", "BarometricPressureSensor", +#if defined(THING_HAS_TEMPERATURE_PROPERTY) +#define TEMPERATURE_SENSOR_CAPABILITY "TemperatureSensor", #else -#define BME280_CAPABILITIES +#define TEMPERATURE_SENSOR_CAPABILITY #endif -#if defined(THING_HAS_MHZ19) -/* Properties for Winsen MH-Z19 */ -#include +#if defined(THING_HAS_HUMIDITY_PROPERTY) +#define HUMIDITY_SENSOR_CAPABILITY "HumiditySensor", +#else +#define HUMIDITY_SENSOR_CAPABILITY +#endif + +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) +#define BAROMETRIC_PRESSURE_SENSOR_CAPABILITY "BarometricPressureSensor", +#else +#define BAROMETRIC_PRESSURE_SENSOR_CAPABILITY +#endif -#define MHZ19_CAPABILITIES "AirQualitySensor", +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) +#define AIR_QUALITY_SENSOR_CAPABILITY "AirQualitySensor", #else -#define MHZ19_CAPABILITIES +#define AIR_QUALITY_SENSOR_CAPABILITY #endif static const char* deviceCapabilities[] = { - BME280_CAPABILITIES MHZ19_CAPABILITIES nullptr}; + TEMPERATURE_SENSOR_CAPABILITY HUMIDITY_SENSOR_CAPABILITY + BAROMETRIC_PRESSURE_SENSOR_CAPABILITY + AIR_QUALITY_SENSOR_CAPABILITY nullptr}; static ThingDevice device("0", i18n::DeviceTitle, deviceCapabilities); void describeDevice(WebThingAdapter* adapter) { -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_TEMPERATURE_PROPERTY) describeTemperatureProperty(&device); +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) describeHumidityProperty(&device); +#endif + +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) describeBarometricPressureProperty(&device); +#endif + +#if defined(THING_HAS_DEW_POINT_PROPERTY) describeDewPointProperty(&device); #endif -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) describeCarbonDioxideProperty(&device); #endif - describeUptimeProperty(&device); - adapter->addDevice(&device); } diff --git a/src/airly/I18n.cc b/src/airly/I18n.cc index 9c7bd4a..fb52451 100755 --- a/src/airly/I18n.cc +++ b/src/airly/I18n.cc @@ -8,21 +8,28 @@ namespace i18n { const char* DeviceTitle = ""; -const char* UptimePropertyDescription = ""; -const char* UptimePropertyTitle = ""; -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_TEMPERATURE_PROPERTY) +const char* TemperaturePropertyDescription = ""; +const char* TemperaturePropertyTitle = ""; +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) +const char* HumidityPropertyDescription = ""; +const char* HumidityPropertyTitle = ""; +#endif + +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) const char* BarometricPressurePropertyDescription = ""; const char* BarometricPressurePropertyTitle = ""; +#endif + +#if defined(THING_HAS_DEW_POINT_PROPERTY) const char* DewPointPropertyDescription = ""; const char* DewPointPropertyTitle = ""; -const char* HumidityPropertyDescription = ""; -const char* HumidityPropertyTitle = ""; -const char* TemperaturePropertyDescription = ""; -const char* TemperaturePropertyTitle = ""; #endif -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) const char* CarbonDioxidePropertyDescription = ""; const char* CarbonDioxidePropertyTitle = ""; #endif diff --git a/src/airly/OtaUpdates.cc b/src/airly/OtaUpdate.cc similarity index 100% rename from src/airly/OtaUpdates.cc rename to src/airly/OtaUpdate.cc diff --git a/src/airly/Thing.cc b/src/airly/Thing.cc index 9912ad5..48898d9 100755 --- a/src/airly/Thing.cc +++ b/src/airly/Thing.cc @@ -54,26 +54,62 @@ static void offBuiltinLed() { digitalWrite(LED_BUILTIN, HIGH); } static Bme280TwoWire bme280; +static void beginTwoWire() { Wire.begin(I2C_SDA, I2C_SCL); } + static void beginBme280() { bme280.begin(BME280_ADDRESS); - bme280.setSettings(Bme280Settings::indoor()); + + auto settings = Bme280Settings::indoor(); + +#if !defined(THING_HAS_TEMPERATURE_PROPERTY) && \ + !defined(THING_HAS_DEW_POINT_PROPERTY) + settings.temperatureOversampling = Bme280Oversampling::Off; +#endif + +#if !defined(THING_HAS_HUMIDITY_PROPERTY) && \ + !defined(THING_HAS_DEW_POINT_PROPERTY) + settings.humidityOversampling = Bme280Oversampling::Off; +#endif + +#if !defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) + settings.pressureOversampling = Bme280Oversampling::Off; +#endif + + bme280.setSettings(settings); delay(1000); // 1 second } static bool pollBme280(void *) { +#if defined(THING_HAS_TEMPERATURE_PROPERTY) || \ + defined(THING_HAS_DEW_POINT_PROPERTY) auto temperature = bme280.getTemperature(); +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) || \ + defined(THING_HAS_DEW_POINT_PROPERTY) auto humidity = bme280.getHumidity(); - auto barometricPressure = bme280.getPressure(); - auto dewPoint = calculateDewPoint(temperature, humidity); +#endif +#if defined(THING_HAS_TEMPERATURE_PROPERTY) setTemperatureProperty(temperature); +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) setHumidityProperty(humidity); +#endif + +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) + auto barometricPressure = bme280.getPressure(); setBarometricPressureProperty(barometricPressure); +#endif +#if defined(THING_HAS_DEW_POINT_PROPERTY) + auto dewPoint = calculateDewPoint(temperature, humidity); if (!isnan(dewPoint)) { setDewPointProperty(dewPoint); } +#endif return true; } @@ -89,7 +125,9 @@ static bool pollBme280(void *) { #include /* Properties */ +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) #include +#endif #define MHZ19_UART_BAUDRATE 9600 // kbps @@ -113,12 +151,16 @@ static void beginMhz19() { } static bool pollMhz19(void *) { +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) if (isMhz19PreheatingDone) { auto carbonDioxide = mhz19.getCarbonDioxide(); - if (carbonDioxide < 0) carbonDioxide = 0; + if (carbonDioxide < 0) { + carbonDioxide = 0; + } setCarbonDioxideProperty(carbonDioxide); } +#endif return true; } @@ -129,14 +171,9 @@ static bool pollMhz19(void *) { // -------------------------------------------------------------------------- // // Adapter, common properties // -------------------------------------------------------------------------- // -/* Properties */ -#include - static WebThingAdapter *adapter = nullptr; static bool updateProperties(void *) { - updateUptimeProperty(); - #if defined(THING_HAS_MHZ19) if (!isMhz19PreheatingDone) { if (mhz19.isReady()) { @@ -148,7 +185,9 @@ static bool updateProperties(void *) { if (WiFi.status() == WL_CONNECTED) { adapter->update(); - } else { + } + + if (WiFi.status() == WL_DISCONNECTED) { WiFi.reconnect(); } @@ -196,8 +235,6 @@ static String getThingIdentity() { return getMacAddressWithoutColon(); } static void beginBuiltinLed() { pinMode(LED_BUILTIN, OUTPUT); } -static void beginTwoWire() { Wire.begin(I2C_SDA, I2C_SCL); } - void beginThing() { beginBuiltinLed(); onBuiltinLed(); diff --git a/src/airly/locales/en-US.cc b/src/airly/locales/en-US.cc index 0e2cccc..d852c2b 100755 --- a/src/airly/locales/en-US.cc +++ b/src/airly/locales/en-US.cc @@ -28,26 +28,31 @@ const char* DeviceTitle PROGMEM = "Airly Model M"; namespace i18n { -const char* UptimePropertyDescription PROGMEM = - "The time during which the thing is in operation"; -const char* UptimePropertyTitle PROGMEM = "Uptime"; +#if defined(THING_HAS_TEMPERATURE_PROPERTY) +const char* TemperaturePropertyDescription PROGMEM = + "A physical quantity that expresses hot and cold"; +const char* TemperaturePropertyTitle PROGMEM = "Temperature"; +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) +const char* HumidityPropertyDescription PROGMEM = + "The concentration of water vapor present in the air"; +const char* HumidityPropertyTitle PROGMEM = "Humidity"; +#endif -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) const char* BarometricPressurePropertyDescription PROGMEM = "The pressure within the atmosphere of Earth"; const char* BarometricPressurePropertyTitle PROGMEM = "Barometric pressure"; +#endif + +#if defined(THING_HAS_DEW_POINT_PROPERTY) const char* DewPointPropertyDescription PROGMEM = "The temperature at which water vapor begins to condense into water"; const char* DewPointPropertyTitle PROGMEM = "Dew point"; -const char* HumidityPropertyDescription PROGMEM = - "The concentration of water vapor present in the air"; -const char* HumidityPropertyTitle PROGMEM = "Humidity"; -const char* TemperaturePropertyDescription PROGMEM = - "A physical quantity that expresses hot and cold"; -const char* TemperaturePropertyTitle PROGMEM = "Temperature"; #endif -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) const char* CarbonDioxidePropertyDescription PROGMEM = "The concentration of carbon dioxide"; const char* CarbonDioxidePropertyTitle PROGMEM = "Carbon dioxide"; diff --git a/src/airly/locales/ru-RU.cc b/src/airly/locales/ru-RU.cc index 38ec84b..90c91b6 100755 --- a/src/airly/locales/ru-RU.cc +++ b/src/airly/locales/ru-RU.cc @@ -10,26 +10,31 @@ namespace i18n { -const char* UptimePropertyDescription PROGMEM = - "Время, в течение которого вещь находится в эксплуатации"; -const char* UptimePropertyTitle PROGMEM = "Аптайм"; +#if defined(THING_HAS_TEMPERATURE_PROPERTY) +const char* TemperaturePropertyDescription PROGMEM = + "Физическая величина, выражающая тепло и холод"; +const char* TemperaturePropertyTitle PROGMEM = "Температура"; +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) +const char* HumidityPropertyDescription PROGMEM = + "Концентрация водяного пара в воздухе"; +const char* HumidityPropertyTitle PROGMEM = "Влажность"; +#endif -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) const char* BarometricPressurePropertyDescription PROGMEM = "Давление в атмосфере Земли"; const char* BarometricPressurePropertyTitle PROGMEM = "Атмосферное давление"; +#endif + +#if defined(THING_HAS_DEW_POINT_PROPERTY) const char* DewPointPropertyDescription PROGMEM = "Температура, при которой водяной пар начинает конденсироваться в воду"; const char* DewPointPropertyTitle PROGMEM = "Точка росы"; -const char* HumidityPropertyDescription PROGMEM = - "Концентрация водяного пара в воздухе"; -const char* HumidityPropertyTitle PROGMEM = "Влажность"; -const char* TemperaturePropertyDescription PROGMEM = - "Физическая величина, выражающая тепло и холод"; -const char* TemperaturePropertyTitle PROGMEM = "Температура"; #endif -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) const char* CarbonDioxidePropertyDescription PROGMEM = "Концентрация углекислого газа"; const char* CarbonDioxidePropertyTitle PROGMEM = "Углекислый газ"; diff --git a/src/airly/locales/uk-UA.cc b/src/airly/locales/uk-UA.cc index 36c6977..c248252 100755 --- a/src/airly/locales/uk-UA.cc +++ b/src/airly/locales/uk-UA.cc @@ -10,26 +10,31 @@ namespace i18n { -const char* UptimePropertyDescription PROGMEM = - "Час, протягом якого річ перебуває в експлуатації"; -const char* UptimePropertyTitle PROGMEM = "Аптайм"; +#if defined(THING_HAS_TEMPERATURE_PROPERTY) +const char* TemperaturePropertyDescription PROGMEM = + "Фізична величина, що виражає тепло та холод"; +const char* TemperaturePropertyTitle PROGMEM = "Температура"; +#endif + +#if defined(THING_HAS_HUMIDITY_PROPERTY) +const char* HumidityPropertyDescription PROGMEM = + "Концентрація водяної пари у повітрі"; +const char* HumidityPropertyTitle PROGMEM = "Вологість"; +#endif -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) const char* BarometricPressurePropertyDescription PROGMEM = "Тиск у атмосфері Землі"; const char* BarometricPressurePropertyTitle PROGMEM = "Атмосферний тиск"; +#endif + +#if defined(THING_HAS_DEW_POINT_PROPERTY) const char* DewPointPropertyDescription PROGMEM = "Температура, при якій водяна пара починає конденсуватися у воду"; const char* DewPointPropertyTitle PROGMEM = "Точка роси"; -const char* HumidityPropertyDescription PROGMEM = - "Концентрація водяної пари у повітрі"; -const char* HumidityPropertyTitle PROGMEM = "Вологість"; -const char* TemperaturePropertyDescription PROGMEM = - "Фізична величина, що виражає тепло та холод"; -const char* TemperaturePropertyTitle PROGMEM = "Температура"; #endif -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) const char* CarbonDioxidePropertyDescription PROGMEM = "Концентрація вуглекислого газу"; const char* CarbonDioxidePropertyTitle PROGMEM = "Вуглекислий газ"; diff --git a/src/airly/properties/BarometricPressure.cc b/src/airly/properties/BarometricPressure.cc index 152e1b0..f6ccbeb 100755 --- a/src/airly/properties/BarometricPressure.cc +++ b/src/airly/properties/BarometricPressure.cc @@ -9,7 +9,7 @@ // -------------------------------------------------------------------------- // // Property: Barometric pressure (hPa) // -------------------------------------------------------------------------- // -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_BAROMETRIC_PRESSURE_PROPERTY) static const char* propertyId PROGMEM = "barometricPressure"; static ThingProperty property(propertyId, diff --git a/src/airly/properties/CarbonDioxide.cc b/src/airly/properties/CarbonDioxide.cc index 31aa916..ea562d5 100755 --- a/src/airly/properties/CarbonDioxide.cc +++ b/src/airly/properties/CarbonDioxide.cc @@ -9,7 +9,7 @@ // -------------------------------------------------------------------------- // // Property: Carbon dioxide (ppm) // -------------------------------------------------------------------------- // -#if defined(THING_HAS_MHZ19) +#if defined(THING_HAS_CARBON_DIOXIDE_PROPERTY) static const char* propertyId PROGMEM = "carbonDioxide"; static ThingProperty property(propertyId, diff --git a/src/airly/properties/DewPoint.cc b/src/airly/properties/DewPoint.cc index 9a8509b..509e4dc 100755 --- a/src/airly/properties/DewPoint.cc +++ b/src/airly/properties/DewPoint.cc @@ -9,7 +9,7 @@ // -------------------------------------------------------------------------- // // Property: Dew point (°C) // -------------------------------------------------------------------------- // -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_DEW_POINT_PROPERTY) static const char* propertyId PROGMEM = "dewPoint"; static ThingProperty property(propertyId, i18n::DewPointPropertyDescription, diff --git a/src/airly/properties/Humidity.cc b/src/airly/properties/Humidity.cc index 99509df..32de291 100755 --- a/src/airly/properties/Humidity.cc +++ b/src/airly/properties/Humidity.cc @@ -9,7 +9,7 @@ // -------------------------------------------------------------------------- // // Property: Humidity, % // -------------------------------------------------------------------------- // -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_HUMIDITY_PROPERTY) static const char* propertyId PROGMEM = "humidity"; static ThingProperty property(propertyId, i18n::HumidityPropertyDescription, diff --git a/src/airly/properties/Temperature.cc b/src/airly/properties/Temperature.cc index 972a5b3..397e6af 100755 --- a/src/airly/properties/Temperature.cc +++ b/src/airly/properties/Temperature.cc @@ -9,7 +9,7 @@ // -------------------------------------------------------------------------- // // Property: Temperature (°C) // -------------------------------------------------------------------------- // -#if defined(THING_HAS_BME280) +#if defined(THING_HAS_TEMPERATURE_PROPERTY) static const char* propertyId PROGMEM = "temperature"; static ThingProperty property(propertyId, i18n::TemperaturePropertyDescription, diff --git a/src/airly/properties/Uptime.cc b/src/airly/properties/Uptime.cc deleted file mode 100755 index 2c49d90..0000000 --- a/src/airly/properties/Uptime.cc +++ /dev/null @@ -1,70 +0,0 @@ -#include - -/* AVR low-level */ -#include - -/* Uptime */ -#include - -/* Preprocessor-based localization */ -#include - -// -------------------------------------------------------------------------- // -// Property: Uptime (seconds, minutes, hours, days) -// -------------------------------------------------------------------------- // -enum UptimeUnit { Seconds, Minutes, Hours, Days }; - -static const char* propertyId PROGMEM = "uptime"; -static String propertyValue = ""; -static ThingProperty property(propertyId, i18n::UptimePropertyDescription, - STRING, nullptr); - -static UptimeUnit currentUnit = UptimeUnit::Seconds; -static unsigned long lastDays = 0; -static unsigned long lastHours = 0; -static unsigned long lastMinutes = 0; -static unsigned long lastSeconds = 0; - -static bool hasChanges(unsigned long current, long long last) { - return current > 0 && current != last; -} - -static void setUptimeProperty(const unsigned long uptime, const String unit) { - propertyValue = String(uptime) + unit; - property.setValue({.string = &propertyValue}); -} - -void describeUptimeProperty(ThingDevice* device) { - property.title = i18n::UptimePropertyTitle; - property.readOnly = true; - - device->addProperty(&property); -} - -void updateUptimeProperty() { - ::uptime::calculateUptime(); - - auto days = ::uptime::getDays(); - auto hours = ::uptime::getHours(); - auto minutes = ::uptime::getMinutes(); - auto seconds = ::uptime::getSeconds(); - - if (days == 1) currentUnit = Days; - if (days == 0 && hours == 1) currentUnit = Hours; - if (days == 0 && hours == 0 && minutes == 1) currentUnit = Minutes; - - if (currentUnit == Days && hasChanges(days, lastDays)) { - lastDays = days; - setUptimeProperty(days, "d"); - } else if (currentUnit == Hours && hasChanges(hours, lastHours)) { - lastHours = hours; - setUptimeProperty(hours, "h"); - } else if (currentUnit == Minutes && hasChanges(minutes, lastMinutes)) { - lastMinutes = minutes; - setUptimeProperty(minutes, "m"); - } else if (currentUnit == Seconds && hasChanges(seconds, lastSeconds)) { - lastSeconds = seconds; - setUptimeProperty(seconds, "s"); - } -} -// -------------------------------------------------------------------------- //