From a2522f25aef098b827fba1e907e189fb8bdd88ca Mon Sep 17 00:00:00 2001 From: gene Date: Sat, 22 Jun 2024 11:08:11 +0200 Subject: [PATCH] v1.2.24 - added firmware `#` configuration parameters to `smart-sensor` example - refactored `smart-sensor*` code --- examples/color-light/README.md | 22 ------- examples/smart-sensor-display/README.md | 38 ++++++++++- examples/smart-sensor-display/configuration.h | 18 ----- .../smart-sensor-display/io/BatterySensor.cpp | 2 +- .../smart-sensor-display/io/BatterySensor.h | 6 +- .../smart-sensor-display/io/LightSensor.cpp | 61 ----------------- .../smart-sensor-display.cpp | 33 +++------- examples/smart-sensor/CommonSensors.h | 54 +++++++++++++++ examples/smart-sensor/README.md | 36 ++++++++++ examples/smart-sensor/configuration.h | 16 ----- examples/smart-sensor/io/LightSensor.h | 66 ------------------- .../io => smart-sensor/io/sensors}/DHTxx.cpp | 2 +- .../io => smart-sensor/io/sensors}/DHTxx.h | 12 ++-- .../smart-sensor/io/{ => sensors}/DS18B20.cpp | 2 +- .../smart-sensor/io/{ => sensors}/DS18B20.h | 14 ++-- .../io/{ => sensors}/LightSensor.cpp | 2 +- .../io/sensors}/LightSensor.h | 13 ++-- .../io/sensors}/MotionSensor.cpp | 4 +- .../io/sensors}/MotionSensor.h | 10 ++- examples/smart-sensor/smart-sensor.cpp | 14 +--- {src => lib/homegenie-io}/io/Logger.cpp | 10 ++- {src => lib/homegenie-io}/io/Logger.h | 0 platformio.ini | 46 ++++++++----- src/Task.h | 3 +- src/TaskManager.h | 3 +- src/automation/ProgramEngine.h | 3 +- src/io/gpio/GPIOPort.h | 3 +- src/io/sys/Diagnostics.h | 3 +- src/net/MQTTServer.cpp | 1 + src/net/MQTTServer.h | 7 ++ src/net/NetManager.cpp | 1 + src/net/TimeClient.h | 2 +- src/net/WiFiManager.h | 3 +- src/net/mqtt/MQTTBrokerMini.cpp | 1 - src/net/mqtt/MQTTBrokerMini.h | 4 +- src/service/api/APIRequest.h | 3 +- src/version.h | 2 +- 37 files changed, 234 insertions(+), 286 deletions(-) delete mode 100644 examples/smart-sensor-display/configuration.h delete mode 100644 examples/smart-sensor-display/io/LightSensor.cpp create mode 100644 examples/smart-sensor/CommonSensors.h delete mode 100644 examples/smart-sensor/configuration.h delete mode 100644 examples/smart-sensor/io/LightSensor.h rename examples/{smart-sensor-display/io => smart-sensor/io/sensors}/DHTxx.cpp (98%) rename examples/{smart-sensor-display/io => smart-sensor/io/sensors}/DHTxx.h (92%) rename examples/smart-sensor/io/{ => sensors}/DS18B20.cpp (98%) rename examples/smart-sensor/io/{ => sensors}/DS18B20.h (88%) rename examples/smart-sensor/io/{ => sensors}/LightSensor.cpp (98%) rename examples/{smart-sensor-display/io => smart-sensor/io/sensors}/LightSensor.h (86%) rename examples/{smart-sensor-display/io => smart-sensor/io/sensors}/MotionSensor.cpp (96%) rename examples/{smart-sensor-display/io => smart-sensor/io/sensors}/MotionSensor.h (82%) rename {src => lib/homegenie-io}/io/Logger.cpp (91%) rename {src => lib/homegenie-io}/io/Logger.h (100%) diff --git a/examples/color-light/README.md b/examples/color-light/README.md index c3b2c61..ca5189b 100644 --- a/examples/color-light/README.md +++ b/examples/color-light/README.md @@ -17,28 +17,6 @@ A smart light device with addressable RGB LEDs. | `stld-typ` | Status LED type | RGB/RGBW order mask (see code for ref.) | | `stld-spd` | Status LED speed | 0 (0=800kHz, 256=400kHz) | -*Example **setting** configuration from a terminal connected to the serial port of the device:* - -``` -#SET:leds-pin=5 -#SET:leds-cnt=25 -#SET:leds-typ=6 -#SET:leds-spd=0 -#SET:stld-pin=10 -#SET:stld-typ=82 -#SET:stld-spd=0 -#RESET -``` - -*Example **getting** configuration value:* - -``` -#GET:stl-pin -``` -response: -``` -#GET:stl-pin=10 -``` ## Manual build and install diff --git a/examples/smart-sensor-display/README.md b/examples/smart-sensor-display/README.md index 867dce4..b765612 100644 --- a/examples/smart-sensor-display/README.md +++ b/examples/smart-sensor-display/README.md @@ -1 +1,37 @@ -Smart sensor with display and HomeGenie Mini UI. + +# smart-sensor + +Smart multi-sensor device with display. HomeGenie Mini UI example use. + +- [Documentation and firmware install page](https://homegenie.it/mini/1.2/examples/smart-sensor/) + + +## Firmware configuration (in addition to default system options) + +| Key | Description | Default | +|------------|-------------------------------------|---------| +| `ligh-typ` | Light sensor type | -1 | +| `ligh-pin` | Light sensor GPIO# | -1 | +| `motn-typ` | Motion sensor type | -1 | +| `motn-pin` | Motion sensor GPIO# | -1 | +| `soth-typ` | Temperature sensor type | -1 | +| `soth-pin` | Temperature sensor GPIO# | -1 | +| `sdht-typ` | Temperature + Humidity sensor type | -1 | +| `sdht-pin` | Temperature + Humidity sensor GPIO# | -1 | + + +### Manual build and install + +You can also manually build and install the firmware from source code +as explained in the [Getting started](../../getting-started#custom-firmware) page +and using the following commands for flashing the firmware: + +```bash +pio run -e smart-sensor[] -t upload +``` + +where the optional `` suffix can be one of the following: +- ESP32 + display + `-display` +- ESP32-S3 + display + `-display-s3` \ No newline at end of file diff --git a/examples/smart-sensor-display/configuration.h b/examples/smart-sensor-display/configuration.h deleted file mode 100644 index eb46e37..0000000 --- a/examples/smart-sensor-display/configuration.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifdef ESP8266 - - #define CONFIG_DHTxx_DataPin 0 - #define CONFIG_LightSensorPin 17 - -#elif MINI_ESP32 - - #define CONFIG_DHTxx_DataPin 17 - #define CONFIG_LightSensorPin 36 - -#else - - #define CONFIG_DHTxx_DataPin 21 - #define CONFIG_LightSensorPin 34 - -#endif - -#define CONFIG_MotionSensorPin 16 diff --git a/examples/smart-sensor-display/io/BatterySensor.cpp b/examples/smart-sensor-display/io/BatterySensor.cpp index ea002bb..f5fc933 100644 --- a/examples/smart-sensor-display/io/BatterySensor.cpp +++ b/examples/smart-sensor-display/io/BatterySensor.cpp @@ -25,7 +25,7 @@ #include "BatterySensor.h" -namespace IO { namespace Env { +namespace IO { namespace Sensors { void BatterySensor::begin() { pinMode(sensorPin, INPUT); diff --git a/examples/smart-sensor-display/io/BatterySensor.h b/examples/smart-sensor-display/io/BatterySensor.h index 018c33d..227bd68 100644 --- a/examples/smart-sensor-display/io/BatterySensor.h +++ b/examples/smart-sensor-display/io/BatterySensor.h @@ -28,11 +28,9 @@ #include -#include "../configuration.h" +#define BATTERY_SENSOR_NS_PREFIX "IO::Sensors::BatterySensor" -#define BATTERY_SENSOR_NS_PREFIX "IO::Env::BatterySensor" - -namespace IO { namespace Env { +namespace IO { namespace Sensors { class BatterySensor: Task, public IIOEventSender { public: diff --git a/examples/smart-sensor-display/io/LightSensor.cpp b/examples/smart-sensor-display/io/LightSensor.cpp deleted file mode 100644 index e26fa59..0000000 --- a/examples/smart-sensor-display/io/LightSensor.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * HomeGenie-Mini (c) 2018-2024 G-Labs - * - * - * This file is part of HomeGenie-Mini (HGM). - * - * HomeGenie-Mini is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * HomeGenie-Mini is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with HomeGenie-Mini. If not, see . - * - * - * Authors: - * - Generoso Martello - * - * - * Releases: - * - 2019-01-12 Initial release - * - */ - -#include "LightSensor.h" - -namespace IO { namespace Env { - - void LightSensor::begin() { - Logger::info("| ✔ %s (PIN=%d)", LIGHTSENSOR_NS_PREFIX, inputPin); - } - - void LightSensor::loop() { - uint16_t lightLevel = getLightLevel(); - // signal value changes - if (lightLevel != currentLevel) { - currentLevel = lightLevel; - Logger::info("@%s [%s %d]", LIGHTSENSOR_NS_PREFIX, IOEventPaths::Sensor_Luminance, currentLevel); - sendEvent(IOEventPaths::Sensor_Luminance, (uint16_t *)¤tLevel, SensorLight); - } - } - - void LightSensor::setInputPin(const uint8_t number) { - inputPin = number; - } - - uint16_t LightSensor::getLightLevel() { -#ifdef ESP8266 - // It returns values between 0-1023 - return (uint16_t)analogRead(inputPin); -#else // ESP32 - // It returns values between 0-4095 - return (uint16_t)analogRead(inputPin) / 4; -#endif - } -}} diff --git a/examples/smart-sensor-display/smart-sensor-display.cpp b/examples/smart-sensor-display/smart-sensor-display.cpp index 6b202d2..c85cc42 100644 --- a/examples/smart-sensor-display/smart-sensor-display.cpp +++ b/examples/smart-sensor-display/smart-sensor-display.cpp @@ -27,8 +27,6 @@ * */ -#include "configuration.h" - #include #include @@ -39,17 +37,15 @@ #include #include +#include "smart-sensor/CommonSensors.h" + #include "display/activities/SensorValuesActivity.h" -#include "io/DHTxx.h" -//#include "../smart-sensor/io/LightSensor.h" //#include "io/BatterySensor.h" -#include "io/MotionSensor.h" // Accelerometer and Gyroscope //#include "io/QMI8658.h" -using namespace IO::Env; using namespace Service; using namespace UI::Activities::Control; //using namespace UI::Activities::Examples; @@ -68,9 +64,6 @@ Dashboard* dashboard; void setup() { //uint8_t batterySensorPin = 1; - uint8_t motionSensorPin = CONFIG_MotionSensorPin; - - PowerManager::setWakeUpGPIO((gpio_num_t)motionSensorPin); homeGenie = HomeGenie::getInstance(); miniModule = homeGenie->getDefaultModule(); @@ -98,22 +91,16 @@ void setup() { homeGenie->addIOHandler(batterySensor); //*/ - // Motion sensor - auto motionSensor = new MotionSensor(motionSensorPin); - motionSensor->setModule(miniModule); - homeGenie->addIOHandler(motionSensor); - /* - // Light sensor - auto lightSensor = new LightSensor(); - lightSensor->setModule(miniModule); - homeGenie->addIOHandler(lightSensor); - //*/ + includeCommonSensors(homeGenie, miniModule); - // Temperature and humidity sensor - auto dhtSensor = new DHTxx(22); - dhtSensor->setModule(miniModule); - homeGenie->addIOHandler(dhtSensor); +#ifdef CONFIG_ENABLE_POWER_MANAGER + // Enable power manager (deep sleep on motion timeout) + if (Config::getSetting("motn-typ").equals("switch") && Config::getSetting("motn-pms").equals("sleep")) { + uint8_t motionSensorPin = Config::getSetting("motn-pin", "16").toInt(); + PowerManager::setWakeUpGPIO((gpio_num_t) motionSensorPin); + } +#endif // add custom properties to default module controlModuleParameter = new ModuleParameter("RemoteControl.EndPoint", Config::getSetting("ctrl-mod")); diff --git a/examples/smart-sensor/CommonSensors.h b/examples/smart-sensor/CommonSensors.h new file mode 100644 index 0000000..6dcac54 --- /dev/null +++ b/examples/smart-sensor/CommonSensors.h @@ -0,0 +1,54 @@ +// +// Created by gene on 21/06/24. +// + +#ifndef HOMEGENIE_MINI_COMMONSENSORS_H +#define HOMEGENIE_MINI_COMMONSENSORS_H + +#include "HomeGenie.h" + +#include "io/sensors/DS18B20.h" +#include "io/sensors/MotionSensor.h" +#include "io/sensors/DHTxx.h" +#include "io/sensors/LightSensor.h" + +using namespace IO::Sensors; + +void includeCommonSensors(HomeGenie* homeGenie, Module* miniModule) { + + // Light sensor + if (Config::getSetting("ligh-typ").equals("ldr")) { + auto lightSensor = new LightSensor(Config::getSetting("ligh-pin").toInt()); + lightSensor->setModule(miniModule); + homeGenie->addIOHandler(lightSensor); + } + + // Motion sensor + if (Config::getSetting("motn-typ").equals("switch")) { + uint8_t motionSensorPin = Config::getSetting("motn-pin").toInt(); + auto motionSensor = new MotionSensor(motionSensorPin); + motionSensor->setModule(miniModule); + homeGenie->addIOHandler(motionSensor); + } + + // Temperature sensor + if (Config::getSetting("soth-typ").equals("ds18b20")) { + auto temperatureSensor = new DS18B20(Config::getSetting("soth-pin").toInt()); + temperatureSensor->setModule(miniModule); + homeGenie->addIOHandler(temperatureSensor); + } + + // DHT-xx Temperature and humidity sensor + uint8_t dhtSensorPint = Config::getSetting("sdht-pin").toInt(); + if (Config::getSetting("sdht-typ").equals("22")) { + auto dhtSensor = new DHTxx(22, dhtSensorPint); + dhtSensor->setModule(miniModule); + homeGenie->addIOHandler(dhtSensor); + } else if (Config::getSetting("sdht-typ").equals("11")) { + auto dhtSensor = new DHTxx(11, dhtSensorPint); + dhtSensor->setModule(miniModule); + homeGenie->addIOHandler(dhtSensor); + } +} + +#endif //HOMEGENIE_MINI_COMMONSENSORS_H diff --git a/examples/smart-sensor/README.md b/examples/smart-sensor/README.md index e69de29..2de5abc 100644 --- a/examples/smart-sensor/README.md +++ b/examples/smart-sensor/README.md @@ -0,0 +1,36 @@ +# smart-sensor + +A smart multi-sensor device. + +- [Documentation and firmware install page](https://homegenie.it/mini/1.2/examples/smart-sensor/) + + +## Firmware configuration (in addition to default system options) + +| Key | Description | Default | +|------------|-------------------------------------|---------| +| `ligh-typ` | Light sensor type | -1 | +| `ligh-pin` | Light sensor GPIO# | -1 | +| `motn-typ` | Motion sensor type | -1 | +| `motn-pin` | Motion sensor GPIO# | -1 | +| `soth-typ` | Temperature sensor type | -1 | +| `soth-pin` | Temperature sensor GPIO# | -1 | +| `sdht-typ` | Temperature + Humidity sensor type | -1 | +| `sdht-pin` | Temperature + Humidity sensor GPIO# | -1 | + + +### Manual build and install + +You can also manually build and install the firmware from source code +as explained in the [Getting started](../../getting-started#custom-firmware) page +and using the following commands for flashing the firmware: + +```bash +pio run -e smart-sensor[] -t upload +``` + +where the optional `` suffix can be one of the following: +- ESP8266 + `-d1-mini` +- ESP32 D1 Mini + `-d1-mini-esp32` diff --git a/examples/smart-sensor/configuration.h b/examples/smart-sensor/configuration.h deleted file mode 100644 index b9c4d6d..0000000 --- a/examples/smart-sensor/configuration.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef ESP8266 - - #define CONFIG_DS18B20_DataPin 0 - #define CONFIG_LightSensorPin 17 - -#elif MINI_ESP32 - - #define CONFIG_DS18B20_DataPin 17 - #define CONFIG_LightSensorPin 36 - -#else - - #define CONFIG_DS18B20_DataPin 0 - #define CONFIG_LightSensorPin 34 - -#endif diff --git a/examples/smart-sensor/io/LightSensor.h b/examples/smart-sensor/io/LightSensor.h deleted file mode 100644 index e9a7d8e..0000000 --- a/examples/smart-sensor/io/LightSensor.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * HomeGenie-Mini (c) 2018-2024 G-Labs - * - * - * This file is part of HomeGenie-Mini (HGM). - * - * HomeGenie-Mini is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * HomeGenie-Mini is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with HomeGenie-Mini. If not, see . - * - * - * Authors: - * - Generoso Martello - * - * - * Releases: - * - 2019-01-12 Initial release - * - */ - -#ifndef HOMEGENIE_MINI_LIGHTSENSOR_H -#define HOMEGENIE_MINI_LIGHTSENSOR_H - -#include - -#include "../configuration.h" - -#define LIGHTSENSOR_NS_PREFIX "IO::Env::LightSensor" -#define LIGHTSENSOR_SAMPLING_RATE 5000L - -namespace IO { namespace Env { - - using namespace Service; - - class LightSensor : Task, public IIOEventSender { - public: - LightSensor() { - setLoopInterval(LIGHTSENSOR_SAMPLING_RATE); - } - void setModule(Module* m) override { - IIOEventSender::setModule(m); - auto luminance = new ModuleParameter(IOEventPaths::Sensor_Luminance); - m->properties.add(luminance); - } - - void begin() override; - void loop() override; - void setInputPin(uint8_t number); - uint16_t getLightLevel(); - private: - uint8_t inputPin = CONFIG_LightSensorPin; // Analogic input pin A0 (0) - uint16_t currentLevel = 0; - }; - -}} - -#endif //HOMEGENIE_MINI_LIGHTSENSOR_H diff --git a/examples/smart-sensor-display/io/DHTxx.cpp b/examples/smart-sensor/io/sensors/DHTxx.cpp similarity index 98% rename from examples/smart-sensor-display/io/DHTxx.cpp rename to examples/smart-sensor/io/sensors/DHTxx.cpp index eed13e2..ed91aad 100644 --- a/examples/smart-sensor-display/io/DHTxx.cpp +++ b/examples/smart-sensor/io/sensors/DHTxx.cpp @@ -29,7 +29,7 @@ #include "DHTxx.h" -namespace IO { namespace Env { +namespace IO { namespace Sensors { void DHTxx::begin() { dht->setDisableIRQ(true); diff --git a/examples/smart-sensor-display/io/DHTxx.h b/examples/smart-sensor/io/sensors/DHTxx.h similarity index 92% rename from examples/smart-sensor-display/io/DHTxx.h rename to examples/smart-sensor/io/sensors/DHTxx.h index 8e1aa54..8e15b66 100644 --- a/examples/smart-sensor-display/io/DHTxx.h +++ b/examples/smart-sensor/io/sensors/DHTxx.h @@ -30,15 +30,14 @@ #ifndef HOMEGENIE_MINI_DHTXX_H #define HOMEGENIE_MINI_DHTXX_H -#include #include -#include "../configuration.h" +#include -#define DHTXX_NS_PREFIX "IO::Env::DHTxx" +#define DHTXX_NS_PREFIX "IO::Sensors::DHTxx" #define SENSOR_SAMPLING_RATE 30000L -namespace IO { namespace Env { +namespace IO { namespace Sensors { using namespace Service; @@ -56,8 +55,9 @@ namespace IO { namespace Env { class DHTxx : Task, public IIOEventSender { public: - DHTxx(uint8_t dhtType) { + DHTxx(uint8_t dhtType, uint8_t pin) { setLoopInterval(2000); // initial reading delay + inputPin = pin; dht = new DHTNEW(inputPin); dht->setType(dhtType); } @@ -72,7 +72,7 @@ namespace IO { namespace Env { void loop() override; private: // Set DHTxx pin number - uint8_t inputPin = CONFIG_DHTxx_DataPin; + uint8_t inputPin = 0; // Temperature and humidity sensor DHTNEW* dht; // Current temperature and humidity diff --git a/examples/smart-sensor/io/DS18B20.cpp b/examples/smart-sensor/io/sensors/DS18B20.cpp similarity index 98% rename from examples/smart-sensor/io/DS18B20.cpp rename to examples/smart-sensor/io/sensors/DS18B20.cpp index f2da79e..9d667fc 100644 --- a/examples/smart-sensor/io/DS18B20.cpp +++ b/examples/smart-sensor/io/sensors/DS18B20.cpp @@ -29,7 +29,7 @@ #include "DS18B20.h" -namespace IO { namespace Env { +namespace IO { namespace Sensors { void DS18B20::begin() { ds = new OneWire(inputPin); diff --git a/examples/smart-sensor/io/DS18B20.h b/examples/smart-sensor/io/sensors/DS18B20.h similarity index 88% rename from examples/smart-sensor/io/DS18B20.h rename to examples/smart-sensor/io/sensors/DS18B20.h index 07ad112..ab74498 100644 --- a/examples/smart-sensor/io/DS18B20.h +++ b/examples/smart-sensor/io/sensors/DS18B20.h @@ -30,25 +30,25 @@ #ifndef HOMEGENIE_MINI_DS18B20_H #define HOMEGENIE_MINI_DS18B20_H -#include -#include +#include "src/HomeGenie.h" -#include "../configuration.h" +#include ".pio/libdeps/smart-sensor/OneWire/OneWire.h" -#define DS18B20_NS_PREFIX "IO::Env::DS18B10" +#define DS18B20_NS_PREFIX "IO::Sensors::DS18B10" #define DS18B20_SAMPLING_RATE 60000L #define DS18B20_READ_ERROR -1000 // TODO: maybe put this as a configurable parameter through API #define DS18B20_MEASURE_OFFSET (float_t)-2.00 -namespace IO { namespace Env { +namespace IO { namespace Sensors { using namespace Service; class DS18B20 : Task, public IIOEventSender { public: - DS18B20() { + DS18B20(uint8_t pin) { setLoopInterval(DS18B20_SAMPLING_RATE); + inputPin = pin; } void setModule(Module* m) override { IIOEventSender::setModule(m); @@ -64,7 +64,7 @@ namespace IO { namespace Env { String domain = IOEventDomains::HomeAutomation_HomeGenie; String address = CONFIG_BUILTIN_MODULE_ADDRESS; // Default I/O pin number is D3 (0) - uint8_t inputPin = CONFIG_DS18B20_DataPin; + uint8_t inputPin = 0; // Temperature chip I/O OneWire *ds; // Current temperature diff --git a/examples/smart-sensor/io/LightSensor.cpp b/examples/smart-sensor/io/sensors/LightSensor.cpp similarity index 98% rename from examples/smart-sensor/io/LightSensor.cpp rename to examples/smart-sensor/io/sensors/LightSensor.cpp index e26fa59..b356d0f 100644 --- a/examples/smart-sensor/io/LightSensor.cpp +++ b/examples/smart-sensor/io/sensors/LightSensor.cpp @@ -29,7 +29,7 @@ #include "LightSensor.h" -namespace IO { namespace Env { +namespace IO { namespace Sensors { void LightSensor::begin() { Logger::info("| ✔ %s (PIN=%d)", LIGHTSENSOR_NS_PREFIX, inputPin); diff --git a/examples/smart-sensor-display/io/LightSensor.h b/examples/smart-sensor/io/sensors/LightSensor.h similarity index 86% rename from examples/smart-sensor-display/io/LightSensor.h rename to examples/smart-sensor/io/sensors/LightSensor.h index e9a7d8e..694359a 100644 --- a/examples/smart-sensor-display/io/LightSensor.h +++ b/examples/smart-sensor/io/sensors/LightSensor.h @@ -30,21 +30,20 @@ #ifndef HOMEGENIE_MINI_LIGHTSENSOR_H #define HOMEGENIE_MINI_LIGHTSENSOR_H -#include +#include "src/HomeGenie.h" -#include "../configuration.h" - -#define LIGHTSENSOR_NS_PREFIX "IO::Env::LightSensor" +#define LIGHTSENSOR_NS_PREFIX "IO::Sensors::LightSensor" #define LIGHTSENSOR_SAMPLING_RATE 5000L -namespace IO { namespace Env { +namespace IO { namespace Sensors { using namespace Service; class LightSensor : Task, public IIOEventSender { public: - LightSensor() { + LightSensor(uint8_t pin) { setLoopInterval(LIGHTSENSOR_SAMPLING_RATE); + inputPin = pin; } void setModule(Module* m) override { IIOEventSender::setModule(m); @@ -57,7 +56,7 @@ namespace IO { namespace Env { void setInputPin(uint8_t number); uint16_t getLightLevel(); private: - uint8_t inputPin = CONFIG_LightSensorPin; // Analogic input pin A0 (0) + uint8_t inputPin = 0; uint16_t currentLevel = 0; }; diff --git a/examples/smart-sensor-display/io/MotionSensor.cpp b/examples/smart-sensor/io/sensors/MotionSensor.cpp similarity index 96% rename from examples/smart-sensor-display/io/MotionSensor.cpp rename to examples/smart-sensor/io/sensors/MotionSensor.cpp index 34189b3..978b41b 100644 --- a/examples/smart-sensor-display/io/MotionSensor.cpp +++ b/examples/smart-sensor/io/sensors/MotionSensor.cpp @@ -4,7 +4,7 @@ #include "MotionSensor.h" -namespace IO { namespace Env { +namespace IO { namespace Sensors { void MotionSensor::begin() { pinMode(sensorPin, INPUT_PULLUP); Logger::info("| ✔ %s (PIN=%d)", MOTION_SENSOR_NS_PREFIX, sensorPin); @@ -31,4 +31,4 @@ namespace IO { namespace Env { #endif } } -}} // Env +}} // Sensors diff --git a/examples/smart-sensor-display/io/MotionSensor.h b/examples/smart-sensor/io/sensors/MotionSensor.h similarity index 82% rename from examples/smart-sensor-display/io/MotionSensor.h rename to examples/smart-sensor/io/sensors/MotionSensor.h index 23d7197..ccf6bf1 100644 --- a/examples/smart-sensor-display/io/MotionSensor.h +++ b/examples/smart-sensor/io/sensors/MotionSensor.h @@ -5,13 +5,11 @@ #ifndef HOMEGENIE_MINI_MOTIONSENSOR_H #define HOMEGENIE_MINI_MOTIONSENSOR_H -#include +#include "src/HomeGenie.h" -#include "../configuration.h" +#define MOTION_SENSOR_NS_PREFIX "IO::Sensors::MotionSensor" -#define MOTION_SENSOR_NS_PREFIX "IO::Env::MotionSensor" - -namespace IO { namespace Env { +namespace IO { namespace Sensors { using namespace Service; @@ -34,6 +32,6 @@ namespace IO { namespace Env { bool motionDetected = false; }; -}} // Env +}} // Sensors #endif //HOMEGENIE_MINI_MOTIONSENSOR_H diff --git a/examples/smart-sensor/smart-sensor.cpp b/examples/smart-sensor/smart-sensor.cpp index 60c8f58..049c56b 100644 --- a/examples/smart-sensor/smart-sensor.cpp +++ b/examples/smart-sensor/smart-sensor.cpp @@ -30,10 +30,8 @@ #include -#include "io/DS18B20.h" -#include "io/LightSensor.h" +#include "CommonSensors.h" -using namespace IO::Env; using namespace Service; HomeGenie* homeGenie; @@ -44,15 +42,7 @@ void setup() { auto miniModule = homeGenie->getDefaultModule(); - // Temperature sensor - auto temperatureSensor = new DS18B20(); - temperatureSensor->setModule(miniModule); - homeGenie->addIOHandler(temperatureSensor); - - // Light sensor - auto lightSensor = new LightSensor(); - lightSensor->setModule(miniModule); - homeGenie->addIOHandler(lightSensor); + includeCommonSensors(homeGenie, miniModule); homeGenie->begin(); diff --git a/src/io/Logger.cpp b/lib/homegenie-io/io/Logger.cpp similarity index 91% rename from src/io/Logger.cpp rename to lib/homegenie-io/io/Logger.cpp index a462d4b..588bf7e 100644 --- a/src/io/Logger.cpp +++ b/lib/homegenie-io/io/Logger.cpp @@ -29,8 +29,6 @@ #include "Logger.h" -#include "net/TimeClient.h" - namespace IO { static int logLevel; @@ -101,7 +99,13 @@ namespace IO { } void Logger::timestamp() { - Serial.printf("[%s] ", Net::TimeClient::getTimeClient().getFormattedDate().c_str()); + char buffer[80]; + auto ms = millis() % 1000; + auto tt = time(0); + auto timeInfo = localtime(&tt); + strftime (buffer, 80, "%FT%T", timeInfo); + sprintf(buffer, "%s.%03dZ", buffer, (int)ms); + Serial.printf("[%s] ", buffer); } void Logger::trace(const char *s, ...) { diff --git a/src/io/Logger.h b/lib/homegenie-io/io/Logger.h similarity index 100% rename from src/io/Logger.h rename to lib/homegenie-io/io/Logger.h diff --git a/platformio.ini b/platformio.ini index d21e21f..57f3ce6 100644 --- a/platformio.ini +++ b/platformio.ini @@ -49,7 +49,7 @@ board = esp32-c3-devkitc-02 #board = esp32-c3-devkitm-1 build_flags = ${env.build_flags} -I examples -I src -D ESP32_C3 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1 -[env:default-d1mini] +[env:default-d1-mini] platform = espressif8266@2.6.3 board = d1_mini build_flags = ${env.build_flags} -D DISABLE_UI -D DISABLE_AUTOMATION @@ -72,26 +72,42 @@ build_flags = ${env.build_flags} -D DISABLE_UI -D CONFIG_AUTOMATION_SPAWN_FREERT [env:smart-sensor] platform = espressif32@6.7.0 build_flags = ${env.build_flags} -I examples -I src -D DISABLE_UI + -D DEFAULT_CONFIG='{"io-typ01":"Dimmer","io-pin01":"15","io-typ02":"Dimmer","io-pin02":"17","sdht-typ":"22","sdht-pin":"21","motn-typ":"switch","motn-pin":"16"}' build_src_filter = + - + lib_deps = ${env.lib_deps} + RobTillaart/DHTNew@0.4.19 OneWire@2.3.8 +lib_ignore = + LovyanGFX + +[env:smart-sensor-c3] +platform = espressif32@6.7.0 +board = esp32-c3-devkitc-02 +#board = esp32-c3-devkitm-1 +build_flags = ${env.build_flags} -I examples -I src -D ESP32_C3 -D DISABLE_UI -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=1 + -D DEFAULT_CONFIG='{"io-typ01":"Dimmer","io-pin01":"4","io-typ02":"Dimmer","io-pin02":"5","sdht-typ":"22","sdht-pin":"7","motn-typ":"switch","motn-pin":"6"}' +build_src_filter = + - + +lib_deps = ${env.lib_deps} + RobTillaart/DHTNew@0.4.19 + OneWire@2.3.8 +lib_ignore = + LovyanGFX [env:smart-sensor-d1-mini-esp32] platform = espressif32@6.7.0 build_flags = ${env.build_flags} -I examples -I src -D MINI_ESP32 -D DISABLE_UI - -D DEFAULT_CONFIG='{"sys_bt_pin":"16","sys_sl_pin":"26","io-typ01":"Dimmer","io-pin01":"18","io-typ02":"Dimmer","io-pin02":"19","io-typ03":"Dimmer","io-pin03":"23","io-typ04":"Dimmer","io-pin04":"5"}' + -D DEFAULT_CONFIG='{"sys_bt_pin":"16","sys_sl_pin":"26","soth-typ":"ds18b20","soth-pin":"17","ligh-typ":"ldr","ligh-pin":"36"}' build_src_filter = + - + -lib_deps = ${env.lib_deps} - OneWire@2.3.8 +lib_deps = ${env:smart-sensor.lib_deps} [env:smart-sensor-d1-mini] platform = espressif8266@2.6.3 board = d1_mini build_flags = ${env.build_flags} -I examples -I src -D DISABLE_UI -D DISABLE_AUTOMATION + -D DEFAULT_CONFIG='{"sys_bt_pin":"2","sys_sl_pin":"16","soth-typ":"ds18b20","soth-pin":"0","ligh-typ":"ldr","ligh-pin":"17"}' build_src_filter = + - + lib_deps = ${env.lib_deps_8266} - ${env.lib_deps} - OneWire@2.3.8 + ${env:smart-sensor.lib_deps} lib_ignore = ESP32Time ESP32_BleSerial @@ -99,18 +115,18 @@ lib_ignore = [env:smart-sensor-display] platform = espressif32@6.7.0 -build_flags = ${env.build_flags} -I examples -I src -D CONFIG_ENABLE_POWER_MANAGER -D DISABLE_AUTOMATION -build_src_filter = + - + +build_flags = ${env.build_flags} -I examples -I src -D DISABLE_AUTOMATION + -D DEFAULT_CONFIG='{"io-typ01":"Dimmer","io-pin01":"15","io-typ02":"Dimmer","io-pin02":"17","sdht-typ":"22","sdht-pin":"21","motn-typ":"switch","motn-pin":"16"}' +build_src_filter = + - + - + board_build.partitions = ./src/partitions.csv -lib_deps = ${env.lib_deps} - RobTillaart/DHTNew@0.4.19 +lib_deps = ${env:smart-sensor.lib_deps} [env:smart-sensor-display-s3] platform = espressif32@6.7.0 board = esp32-s3-devkitc-1 -build_flags = ${env.build_flags} -I examples -I src -D ESP32_S3 -D CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK -D CONFIG_ENABLE_POWER_MANAGER -DESP32S3_DEV -DBOARD_HAS_PSRAM - -D DEFAULT_CONFIG='{"sys_bt_pin":"0","sys_sl_pin":"-1","io-typ01":"Dimmer","io-pin01":"15","io-typ02":"Dimmer","io-pin02":"17","io-typ03":"Dimmer","io-pin03":"18"}' -build_src_filter = + - + +build_flags = ${env.build_flags} -I examples -I src -D ESP32_S3 -D CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK -DESP32S3_DEV -DBOARD_HAS_PSRAM + -D DEFAULT_CONFIG='{"io-typ01":"Dimmer","io-pin01":"15","io-typ02":"Dimmer","io-pin02":"17","sdht-typ":"22","sdht-pin":"21","motn-typ":"switch","motn-pin":"16"}' +build_src_filter = + - + - + board_build.mcu = esp32s3 board_build.f_cpu = 240000000L board_build.arduino.memory_type = qio_qspi @@ -118,8 +134,8 @@ board_build.f_flash = 80000000L board_build.flash_mode = qio board_build.partitions = default_16MB.csv board_upload.flash_size = 16MB -lib_deps = ${env.lib_deps} - RobTillaart/DHTNew@0.4.19 +lib_deps = ${env:smart-sensor.lib_deps} + [env:x10-transceiver] platform = espressif32@6.7.0 diff --git a/src/Task.h b/src/Task.h index bf88940..a6eaf22 100644 --- a/src/Task.h +++ b/src/Task.h @@ -30,7 +30,8 @@ #ifndef HOMEGENIE_MINI_TASK_H #define HOMEGENIE_MINI_TASK_H -#include "Config.h" +//#include "Config.h" +#include // Task interface diff --git a/src/TaskManager.h b/src/TaskManager.h index 9226b8e..422db55 100644 --- a/src/TaskManager.h +++ b/src/TaskManager.h @@ -30,8 +30,9 @@ #ifndef HOMEGENIE_MINI_TASKMANAGER_H #define HOMEGENIE_MINI_TASKMANAGER_H +#include + #include "Task.h" -#include "io/Logger.h" #define TASKMANAGER_LOG_PREFIX "@ROOT::TaskManager" diff --git a/src/automation/ProgramEngine.h b/src/automation/ProgramEngine.h index faf1867..074c8aa 100644 --- a/src/automation/ProgramEngine.h +++ b/src/automation/ProgramEngine.h @@ -30,10 +30,11 @@ #ifndef HOMEGENIE_MINI_PROGRAMENGINE_H #define HOMEGENIE_MINI_PROGRAMENGINE_H +#include + #include "Task.h" #include "automation/Scheduler.h" -#include "io/Logger.h" #include "net/NetManager.h" #define PROGRAMENGINE_NS_PREFIX "Automation::ProgramEngine" diff --git a/src/io/gpio/GPIOPort.h b/src/io/gpio/GPIOPort.h index 6ce3150..d9b2706 100644 --- a/src/io/gpio/GPIOPort.h +++ b/src/io/gpio/GPIOPort.h @@ -34,12 +34,13 @@ #include #endif +#include + #include "Config.h" #include "io/IOEvent.h" #include "io/IOEventDomains.h" #include "io/IOEventPaths.h" -#include "io/Logger.h" #define GPIO_PORT_NS_PREFIX "IO::GPIO::GPIOPort" diff --git a/src/io/sys/Diagnostics.h b/src/io/sys/Diagnostics.h index f13741e..990dcbc 100644 --- a/src/io/sys/Diagnostics.h +++ b/src/io/sys/Diagnostics.h @@ -36,8 +36,9 @@ extern "C" { } #endif +#include + #include "Task.h" -#include "io/Logger.h" #include "io/IOEvent.h" #include "io/IOEventDomains.h" #include "io/IOEventPaths.h" diff --git a/src/net/MQTTServer.cpp b/src/net/MQTTServer.cpp index e6092f8..6f84520 100644 --- a/src/net/MQTTServer.cpp +++ b/src/net/MQTTServer.cpp @@ -55,6 +55,7 @@ namespace Net { mqttBroker->setCallback([this](uint8_t n, const Net::MQTT::Events_t* e, const String* topic_name, uint8_t* payload, uint16_t payload_length) { mqttCallback(n, e, topic_name, payload, payload_length); }); + Logger::info("| ✔ MQTT service"); } diff --git a/src/net/MQTTServer.h b/src/net/MQTTServer.h index 34ce875..83fe0b8 100644 --- a/src/net/MQTTServer.h +++ b/src/net/MQTTServer.h @@ -30,11 +30,18 @@ #ifndef HOMEGENIE_MINI_MQTTSERVER_H #define HOMEGENIE_MINI_MQTTSERVER_H +#include +#include +#include + +#include "defs.h" #include "Task.h" #include "net/mqtt/MQTTBrokerMini.h" + namespace Net { using namespace MQTT; + using namespace IO; typedef std::function ApiRequestEvent; diff --git a/src/net/NetManager.cpp b/src/net/NetManager.cpp index b24b4a7..4b54f2f 100644 --- a/src/net/NetManager.cpp +++ b/src/net/NetManager.cpp @@ -133,6 +133,7 @@ namespace Net { }); mqttServer->begin(); + Logger::info("| ✔ MQTT service"); #endif timeClient = new TimeClient(); timeClient->begin(); diff --git a/src/net/TimeClient.h b/src/net/TimeClient.h index 91daa51..c7f4e45 100644 --- a/src/net/TimeClient.h +++ b/src/net/TimeClient.h @@ -36,7 +36,7 @@ #endif #include -#include "io/Logger.h" +#include #include "Task.h" namespace Net { diff --git a/src/net/WiFiManager.h b/src/net/WiFiManager.h index 1745ff4..a7fb442 100644 --- a/src/net/WiFiManager.h +++ b/src/net/WiFiManager.h @@ -38,9 +38,10 @@ #endif #include +#include + #include "Config.h" #include "Task.h" -#include "io/Logger.h" namespace Net { diff --git a/src/net/mqtt/MQTTBrokerMini.cpp b/src/net/mqtt/MQTTBrokerMini.cpp index 5ab1690..a9ce571 100644 --- a/src/net/mqtt/MQTTBrokerMini.cpp +++ b/src/net/mqtt/MQTTBrokerMini.cpp @@ -60,7 +60,6 @@ namespace Net { namespace MQTT { for (auto &MQTTclient : MQTTclients) { MQTTclient.status = false; } - Logger::info("| ✔ MQTT service"); } void MQTTBrokerMini::parsing(uint8_t num, uint8_t *payload, uint16_t length) { diff --git a/src/net/mqtt/MQTTBrokerMini.h b/src/net/mqtt/MQTTBrokerMini.h index 2c07314..757dcd1 100644 --- a/src/net/mqtt/MQTTBrokerMini.h +++ b/src/net/mqtt/MQTTBrokerMini.h @@ -35,7 +35,7 @@ #include -#include "io/Logger.h" +#include #define MQTT_VERSION_3_1_1 4 @@ -104,8 +104,6 @@ namespace Net { namespace MQTT { typedef std::function callback_t; - using namespace IO; - class MQTTBrokerMini { public: MQTTBrokerMini(WebSocketsServer *webSocket); diff --git a/src/service/api/APIRequest.h b/src/service/api/APIRequest.h index 222273c..6e1bfa6 100644 --- a/src/service/api/APIRequest.h +++ b/src/service/api/APIRequest.h @@ -30,8 +30,9 @@ #ifndef HOMEGENIE_MINI_APIREQUEST_H #define HOMEGENIE_MINI_APIREQUEST_H +#include + #include "Config.h" -#include "io/Logger.h" #define APIREQUEST_LOG_PREFIX "@Service::ApiRequest" diff --git a/src/version.h b/src/version.h index a64c897..6e5eeba 100644 --- a/src/version.h +++ b/src/version.h @@ -29,7 +29,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 2 -#define VERSION_PATCH 23 +#define VERSION_PATCH 24 #define STRING_VALUE(...) STRING_VALUE__(__VA_ARGS__) #define STRING_VALUE__(...) #__VA_ARGS__