Skip to content

Commit

Permalink
v1.2.2
Browse files Browse the repository at this point in the history
- fixed bug in API request options parsing
- new BluetoothManager class supporting device configuration via LE
- added `DISABLE_MQTT`, `DISABLE_BLUETOOTH`, `DISABLE_BLUETOOTH_LE`, `CONFIG_ENABLE_POWER_MANAGER` flags
- implemented *HomeGenie API* method `Config/Modules.ParameterSet`
- added smart sensor with touch display example for generic *ESP32* and *ESP32-S3*
- added configuration to target *ESP32-C3* for playground example
- updated Shutter control example
- added minimal UI system with touch and gestures support
- added PowerManager class with deep-sleep support
  • Loading branch information
genemars committed Feb 22, 2024
1 parent f2cca1f commit 99f90b1
Show file tree
Hide file tree
Showing 42 changed files with 1,924 additions and 192 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,20 @@ pio run -e smart-sensor-d1-mini-esp32 -t upload
```


### Smart sensor with touch display
### Smart sensor with display

A humidity and temperature sensor with touch display. Supports
GC9A01 240x240 round display and CST816S capacitive touch.

- `smart-sensor-display`
Humidity and temperature sensor with touch display. For generic *ESP32*,
GC9A01 240x240 round display, and CST816S capacitive touch
- `smart-sensor-display-s3`
Like above but with 1.28" round display and integrated ESP32-S3 on board.

**Generic ESP32**
```bash
pio run -e smart-sensor-display -t upload
```

**Round display with integrated ESP32-S3**
```bash
pio run -e smart-sensor-display-s3 -t upload
```


### Shutter control
Expand Down Expand Up @@ -236,13 +240,10 @@ Just a generic playground project to mess with the library =)
pio run -e playground -t upload
```



-`playground-c3`
Same as above but compiling for *ESP32-C3*



**Generic ESP32 C3**
```bash
pio run -e playground-c3 -t upload
```



Expand Down
3 changes: 0 additions & 3 deletions examples/rf-transceiver/rf-transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ void setup() {
homeGenie = HomeGenie::getInstance();
auto miniModule = homeGenie->getDefaultModule();


// RCSwitch RF Transmitter
auto rcsTransmitterConfig = new RCS::RFTransmitterConfig(CONFIG_RCSwitchTransmitterPin);
auto rcsTransmitter = new RCS::RFTransmitter(rcsTransmitterConfig);
homeGenie->addAPIHandler(new RCSwitchHandler(rcsTransmitter));

// TODO: homeGenie->addIOHandler(new RCS::RFReceiver());
// TODO: auto propRawData = new ModuleParameter(IOEventPaths::Receiver_RawData);
// TODO: miniModule->properties.add(propRawData);


homeGenie->begin();
Expand Down
53 changes: 53 additions & 0 deletions examples/smart-sensor-display/io/BatterySensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*
* Authors:
* - Generoso Martello <[email protected]>
*
*/

#include "BatterySensor.h"

namespace IO { namespace Env {

void BatterySensor::begin() {
pinMode(sensorPin, INPUT);
}
void BatterySensor::loop() {
float gpioMax = 4096;
float gpioV = 3.3f;
float batteryVMax = 3.7f;
const float conversionFactor = gpioV / gpioMax * 3.0f;
float adv = analogReadMilliVolts(sensorPin);
float v = adv * conversionFactor; //adv * (gpioV / gpioMax) * batteryV;
float batteryLevel = v / batteryVMax * 100;
if (lastBatteryLevel != batteryLevel) {
Logger::info("@%s [%s %.2f]", BATTERY_SENSOR_NS_PREFIX, (IOEventPaths::Status_Battery), batteryLevel);
sendEvent((const uint8_t*)(IOEventPaths::Status_Battery), (float*)&batteryLevel, IOEventDataType::Float);
lastBatteryLevel = batteryLevel;
}

if (batteryLevel > 100) {
// Charging
Service::PowerManager::setActive();
}
}

}}
57 changes: 57 additions & 0 deletions examples/smart-sensor-display/io/BatterySensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*
* Authors:
* - Generoso Martello <[email protected]>
*
*/

#ifndef HOMEGENIE_MINI_BATTERYSENSOR_H
#define HOMEGENIE_MINI_BATTERYSENSOR_H

#include <HomeGenie.h>

#include "../configuration.h"

#define BATTERY_SENSOR_NS_PREFIX "IO::Env::BatterySensor"

namespace IO { namespace Env {

class BatterySensor: Task, public IIOEventSender {
public:
BatterySensor(uint8_t analogPin) {
setLoopInterval(5000); // update every 15 seconds
sensorPin = analogPin;
}
void setModule(Module* m) override {
IIOEventSender::setModule(m);
auto statusBattery = new ModuleParameter(IOEventPaths::Status_Battery);
m->properties.add(statusBattery);
}
void begin() override;
void loop() override;
private:
uint8_t sensorPin;
float lastBatteryLevel = 0;
};

}}

#endif //HOMEGENIE_MINI_BATTERYSENSOR_H
23 changes: 14 additions & 9 deletions examples/smart-sensor-display/io/DHTxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,31 @@ namespace IO { namespace Env {
// signal value changes
if (currentData.temperature != t) {
Logger::info("@%s [%s %0.2f]", DHTXX_NS_PREFIX, (IOEventPaths::Sensor_Temperature), currentData.temperature);
sendEvent(domain.c_str(), address.c_str(), (const uint8_t*)(IOEventPaths::Sensor_Temperature), (float_t *)&currentData.temperature, SensorTemperature);
sendEvent((const uint8_t*)(IOEventPaths::Sensor_Temperature), (float_t *)&currentData.temperature, SensorTemperature);
}
if (currentData.humidity != h) {
Logger::info("@%s [%s %0.2f]", DHTXX_NS_PREFIX, (IOEventPaths::Sensor_Humidity), currentData.humidity);
sendEvent(domain.c_str(), address.c_str(), (const uint8_t*)(IOEventPaths::Sensor_Humidity), (float_t *)&currentData.humidity, SensorHumidity);
sendEvent((const uint8_t*)(IOEventPaths::Sensor_Humidity), (float_t *)&currentData.humidity, SensorHumidity);
}

Logger::verbose(" > %s::loop() << END", DHTXX_NS_PREFIX);
setLoopInterval(SENSOR_SAMPLING_RATE);
}

/// Read temperature and humidity values from one DHTxx.
void DHTxx::readSensorData() {
dht->read();
float h = dht->getHumidity();
float t = dht->getTemperature();
if (h != DHT_READ_ERROR && t != DHT_READ_ERROR) {
currentData.temperature = t;
currentData.humidity = h;
} else {
uint8_t attempts = 5;
while (attempts > 0) {
dht->read();
float h = dht->getHumidity();
float t = dht->getTemperature();
if (h != DHT_READ_ERROR && t != DHT_READ_ERROR) {
currentData.temperature = t;
currentData.humidity = h;
break;
}
// TODO: report error reading sensor data
attempts--;
}
}

Expand Down
11 changes: 8 additions & 3 deletions examples/smart-sensor-display/io/DHTxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ namespace IO { namespace Env {
class DHTxx : Task, public IIOEventSender {
public:
DHTxx(uint8_t dhtType) {
setLoopInterval(SENSOR_SAMPLING_RATE);
setLoopInterval(2000); // initial reading delay
dht = new DHTNEW(inputPin);
dht->setType(dhtType);
}
void setModule(Module* m) override {
IIOEventSender::setModule(m);
auto temperature = new ModuleParameter(IOEventPaths::Sensor_Temperature);
m->properties.add(temperature);
auto humidity = new ModuleParameter(IOEventPaths::Sensor_Humidity);
m->properties.add(humidity);
}
void begin() override;
void loop() override;
private:
String domain = IOEventDomains::HomeAutomation_HomeGenie;
String address = CONFIG_BUILTIN_MODULE_ADDRESS;
// Set DHTxx pin number
uint8_t inputPin = CONFIG_DHTxx_DataPin;
// Temperature and humidity sensor
Expand Down
2 changes: 1 addition & 1 deletion examples/smart-sensor-display/io/LightSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace IO { namespace Env {
if (lightLevel != currentLevel) {
currentLevel = lightLevel;
Logger::info("@%s [%s %d]", LIGHTSENSOR_NS_PREFIX, (IOEventPaths::Sensor_Luminance), currentLevel);
sendEvent(domain.c_str(), address.c_str(), (const uint8_t*)(IOEventPaths::Sensor_Luminance), (uint16_t *)&currentLevel, SensorLight);
sendEvent((const uint8_t*)(IOEventPaths::Sensor_Luminance), (uint16_t *)&currentLevel, SensorLight);
}
}

Expand Down
8 changes: 6 additions & 2 deletions examples/smart-sensor-display/io/LightSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ namespace IO { namespace Env {
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:
String domain = IOEventDomains::HomeAutomation_HomeGenie;
String address = CONFIG_BUILTIN_MODULE_ADDRESS;
uint8_t inputPin = CONFIG_LightSensorPin; // Analogic input pin A0 (0)
uint16_t currentLevel = 0;
};
Expand Down
30 changes: 30 additions & 0 deletions examples/smart-sensor-display/io/MotionSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Created by gene on 19/02/24.
//

#include "MotionSensor.h"

namespace IO { namespace Env {
void MotionSensor::begin() {
pinMode(sensorPin, INPUT_PULLUP);
Logger::info("| ✔ %s (PIN=%d)", MOTION_SENSOR_NS_PREFIX, sensorPin);
}
void MotionSensor::loop() {
int motionValue = digitalRead(sensorPin);
if (motionValue == HIGH && !motionDetected) {
// MOTION DETECTED
motionDetected = true;
Logger::info("@%s [%s %d]", MOTION_SENSOR_NS_PREFIX, (IOEventPaths::Sensor_MotionDetect), motionValue);
sendEvent((const uint8_t*)(IOEventPaths::Sensor_MotionDetect), (int*)&motionValue, IOEventDataType::Number);
PowerManager::setActive();
} else if (motionValue == LOW && motionDetected) {
// MOTION CLEAR
motionDetected = false;
Logger::info("@%s [%s %d]", MOTION_SENSOR_NS_PREFIX, (IOEventPaths::Sensor_MotionDetect), motionValue);
sendEvent((const uint8_t*)(IOEventPaths::Sensor_MotionDetect), (int*)&motionValue, IOEventDataType::Number);
} else if (motionDetected) {
// MOTION ACTIVE
PowerManager::setActive();
}
}
}} // Env
39 changes: 39 additions & 0 deletions examples/smart-sensor-display/io/MotionSensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Created by gene on 19/02/24.
//

#ifndef HOMEGENIE_MINI_MOTIONSENSOR_H
#define HOMEGENIE_MINI_MOTIONSENSOR_H

#include <HomeGenie.h>

#include "../configuration.h"

#define MOTION_SENSOR_NS_PREFIX "IO::Env::MotionSensor"

namespace IO { namespace Env {

using namespace Service;

class MotionSensor : Task, public IIOEventSender {
public:
MotionSensor(uint8_t pin) {
setLoopInterval(200);
sensorPin = pin;
}
void setModule(Module* m) override {
IIOEventSender::setModule(m);
auto motionDetect = new ModuleParameter(IOEventPaths::Sensor_MotionDetect);
m->properties.add(motionDetect);
}
void begin() override;
void loop() override;

private:
uint8_t sensorPin = 0;
bool motionDetected = false;
};

}} // Env

#endif //HOMEGENIE_MINI_MOTIONSENSOR_H
Loading

0 comments on commit 99f90b1

Please sign in to comment.