Skip to content

Commit

Permalink
v1.2.26
Browse files Browse the repository at this point in the history
- Added support for `ESP32-S2`
- Wi-Fi WPS now enabled for both ESP32 and ESP8266 targets by default
- Fixed bug in time-client
- Now using FreeRTOS task by default for automation program engine if PSRAM is detected
  • Loading branch information
genemars committed Jun 25, 2024
1 parent a9ad4b2 commit 3d64223
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 115 deletions.
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ based on *ESP32* or *ESP8266* chip.

https://homegenie.it/mini


## Features

- Easy Wi-Fi configuration using Bluetooth (ESP32) or WPS (ESP8266)
- Easy device configuration using Wi-Fi protected setup button (WPS) or Bluetooth
- Does not require an Internet connection to be configured or to work properly
- Time synchronization using internal RTC (ESP32), mobile app time or NTP
- Integrated actions scheduler supporting *extended cron expressions*
- Device discovery through SNMP/UPnP advertising with customizable name
- Multi-channel I/O: HTTP, WebSocket, SSE, MQTT
- Device discovery via SNMP/UPnP with customizable advertising name
- Multi-channel I/O: HTTP, WebSocket, SSE, MQTT, Serial
- Status LED
- Configuration/Pairing Button
- Builtin GPIO control API
- Switch level restore on power-on / restart
- Event router
- Simple task manager
- Extensible API
- Multi-threading support, event router, extensible API
- Can connect directly to *HomeGenie Panel* either via Wi-Fi access point or hotspot/tethering
- Can be easily connected to *HomeGenie Server* via MQTT
- Can be easily connected to *HomeGenie Server* and other services via MQTT


## Building and flashing the firmware

Expand Down Expand Up @@ -67,23 +66,29 @@ of the firmware to support different hardware and functionality.
Once the firmware is installed you can configure and control the device using
the [HomeGenie Panel](https://play.google.com/store/apps/details?id=com.glabs.homegenieplus) app available on Google Play.

The device status LED will blink continuously indicating that the device is not
connected to Wi-Fi, and is in pairing mode accepting connections via Bluetooth.
The status LED of the device will blink continuously indicating that it is not
connected to Wi-Fi.
The device can be configured and connected to Wi-Fi very easily by enabling
WPS on your router and by pressing the WPS button on the device for at least 5
seconds. The status LED will stop blinking and stay on while the WPS mode is
active on the device.

Enable Bluetooth on your phone, open *HomeGenie Panel* and select the *"Discovery"* option.
After pairing, the device will start blinking quickly again for about 5 seconds, and then
it will blink slowly indicating that is connected correctly to Wi-Fi. It will then appear
in the list of detected devices in the connections discovery page of *HomeGenie Panel*.

![HomeGenie Panel - Discovery](data/images/phone/hg_panel_discovery.png)
![HomeGenie Panel - Discovery: select device](data/images/phone/hg_panel_discovery_select.png)

The new HG-Mini device will be detected via Bluetooth and the app will display a dialog to
configure the device name and data to connect it to Wi-Fi.
After confirming the settings, the HG-Mini will exit pairing mode, reboot and connect
to Wi-Fi.
At this point the device will blink slowly (every 2 seconds) indicating that is connected
correctly, and it will appear in the list of detected devices in the *HomeGenie Panel* app.
Select it from the list and click the *"Done"* button.

Select it from the list and click the *"Done"* button.
If WPS is not available on your router, you can alternatively set up your device
via Bluetooth if it is enabled on your phone when you start the connection discovery
process on the *HomeGenie Panel*.

![HomeGenie Panel - Discovery: select device](data/images/phone/hg_panel_discovery_select.png)
The new HG-Mini device will be detected via Bluetooth and the app will display a
dialog to configure the device name and data to connect it to Wi-Fi.
After confirming the settings, the HG-Mini device will exit pairing mode, reset
and connect to Wi-Fi.

Depending on the installed firmware version you will be able to select different kind of modules
to show in the panel dashboard. The following picture refers to the `smart-sensor-d1-mini-esp32`
Expand Down
4 changes: 2 additions & 2 deletions lib/NTPClient-master/NTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ bool NTPClient::isUpdated() const {
bool NTPClient::update() {
if (!isUpdated()) {
if (!this->_udpSetup) this->begin(); // set up the UDP client if needed
return this->forceUpdate();
this->forceUpdate();
}
return true;
return this->_currentEpoc > 1712031624;
}

unsigned long NTPClient::getEpochTime() const {
Expand Down
51 changes: 44 additions & 7 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,28 @@ lib_deps_8266 =
[env:default]
platform = [email protected]
build_flags = ${env.build_flags}
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"-1","io-typ01":"Switch","io-pin01":"5","io-typ02":"Switch","io-pin02":"13","io-typ03":"Dimmer","io-pin03":"14","io-typ04":"Dimmer","io-pin04":"15"}'

[env:default-c3]
platform = [email protected]
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
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"-1","io-typ01":"Switch","io-pin01":"7","io-typ02":"Switch","io-pin02":"8","io-typ03":"Dimmer","io-pin03":"9","io-typ04":"Dimmer","io-pin04":"10"}'

[env:default-s2-mini]
platform = [email protected]
board = lolin_s2_mini
build_flags = ${env.build_flags} -I examples -I src -D ESP32_S2 -D BOARD_HAS_PSRAM
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"15","io-typ01":"Switch","io-pin01":"7","io-typ02":"Switch","io-pin02":"8","io-typ03":"Dimmer","io-pin03":"9","io-typ04":"Dimmer","io-pin04":"10"}'
lib_ignore =
ESP32_BleSerial

[env:default-d1-mini]
platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI -D DISABLE_AUTOMATION
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"16","io-typ01":"Switch","io-pin01":"14","io-typ02":"Switch","io-pin02":"27","io-typ03":"Switch","io-pin03":"27","io-typ04":"Switch","io-pin04":"27"}'
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
lib_ignore =
Expand All @@ -63,7 +74,7 @@ lib_ignore =
[env:sonoff-dualr3]
platform = [email protected]
build_flags = ${env.build_flags} -D DISABLE_UI -D CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK
-D DEFAULT_CONFIG='{"sys_bt_pin":"0","sys_sl_pin":"13","io-typ01":"Switch","io-pin01":"14","io-typ02":"Switch","io-pin02":"27"}'
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"13","io-typ01":"Switch","io-pin01":"14","io-typ02":"Switch","io-pin02":"27","io-typ03":"Switch","io-pin03":"27","io-typ04":"Switch","io-pin04":"27"}'


#------------------[ Examples ]------------------
Expand All @@ -72,7 +83,7 @@ build_flags = ${env.build_flags} -D DISABLE_UI -D CONFIG_AUTOMATION_SPAWN_FREERT
[env:smart-sensor]
platform = [email protected]
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"}'
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"-1","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 = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps}
RobTillaart/[email protected]
Expand All @@ -85,19 +96,32 @@ platform = [email protected]
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"}'
-D DEFAULT_CONFIG='{"sys-rb-n":"9","sys-sl-n":"-1","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 = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps}
RobTillaart/[email protected]
[email protected]
lib_ignore =
LovyanGFX

[env:smart-sensor-s2-mini]
platform = [email protected]
board = lolin_s2_mini
build_flags = ${env.build_flags} -I examples -I src -D ESP32_S2 -D DISABLE_UI -D BOARD_HAS_PSRAM
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"15","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 = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps}
RobTillaart/[email protected]
[email protected]
lib_ignore =
ESP32_BleSerial
LovyanGFX

[env:smart-sensor-d1-mini]
platform = [email protected]
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"}'
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"16","sys_bt_pin":"2","sys_sl_pin":"16","soth-typ":"ds18b20","soth-pin":"0","ligh-typ":"ldr","ligh-pin":"17"}'
build_src_filter = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps_8266}
${env:smart-sensor.lib_deps}
Expand All @@ -109,16 +133,16 @@ lib_ignore =
[env:smart-sensor-display]
platform = [email protected]
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"}'
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"-1","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 = +<src> -<src/main.cpp> +<examples/smart-sensor> -<examples/smart-sensor/smart-sensor.cpp> +<examples/smart-sensor-display>
board_build.partitions = ./src/partitions.csv
lib_deps = ${env:smart-sensor.lib_deps}

[env:smart-sensor-display-s3]
platform = [email protected]
board = esp32-s3-devkitc-1
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_flags = ${env.build_flags} -I examples -I src -D ESP32_S3 -D CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK -D ESP32S3_DEV -D BOARD_HAS_PSRAM
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"-1","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 = +<src> -<src/main.cpp> +<examples/smart-sensor> -<examples/smart-sensor/smart-sensor.cpp> +<examples/smart-sensor-display>
board_build.mcu = esp32s3
board_build.f_cpu = 240000000L
Expand Down Expand Up @@ -235,6 +259,7 @@ platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -I examples -I src -D DISABLE_UI -D DISABLE_AUTOMATION
build_src_filter = +<src> -<src/main.cpp> +<examples/color-light>
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"16","leds-typ":"6","leds-cnt":"64","leds-spd":"0","leds-pin":"8"}'
lib_deps = ${env.lib_deps_8266}
${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0
Expand All @@ -248,9 +273,21 @@ platform = [email protected]
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
build_src_filter = +<src> -<src/main.cpp> +<examples/color-light>
-D DEFAULT_CONFIG='{"sys-rb-n":"9","sys-sl-n":"-1","leds-typ":"6","leds-cnt":"64","leds-spd":"0","leds-pin":"8"}'
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0

[env:color-light-s2-mini]
platform = [email protected]
board = lolin_s2_mini
build_flags = ${env.build_flags} -I examples -I src -D ESP32_S2 -D BOARD_HAS_PSRAM
-D DEFAULT_CONFIG='{"sys-rb-n":"0","sys-sl-n":"15","leds-typ":"6","leds-cnt":"64","leds-spd":"0","leds-pin":"8"}'
build_src_filter = +<src> -<src/main.cpp> +<examples/color-light>
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0
lib_ignore =
ESP32_BleSerial


[env:shutter]
Expand Down
37 changes: 16 additions & 21 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,30 @@
#ifndef HOMEGENIE_MINI_CONFIG_H
#define HOMEGENIE_MINI_CONFIG_H

#include "defs.h"

#include <Arduino.h>
#include <ArduinoJson.h>

#include "defs.h"

#ifdef CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK
#include <FreeRTOSConfig.h>
#endif

#ifdef ESP32
#include <ESP32Time.h>
#else
#ifdef CONFIGURE_WITH_WPS
#include "esp_wifi.h"
#endif
#endif

#ifdef CONFIGURE_WITH_WPS
#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h>
#endif
#endif

#include <Preferences.h>

const static char CONFIG_KEY_wifi_ssid[] = {"wifi:ssid"};
Expand Down Expand Up @@ -81,16 +90,13 @@ class SystemConfig {
public:
String friendlyName;
String systemMode;
#ifndef CONFIGURE_WITH_WPS
String ssid, pass;
#endif

SystemConfig() {
friendlyName = CONFIG_BUILTIN_MODULE_NAME;
systemMode = "";
#ifndef CONFIGURE_WITH_WPS
ssid = "";
pass = "";
#endif
}
};

Expand All @@ -117,18 +123,11 @@ class Config {
}

static bool isDeviceConfigured() {
#ifdef CONFIGURE_WITH_WPS
return !WiFi.SSID().isEmpty() && !WiFi.psk().isEmpty();
#else
return !system.systemMode.equals("config") && !system.ssid.isEmpty() && !system.pass.isEmpty();
#endif
return isWiFiConfigured();
}

static bool isWiFiConfigured() {
#ifdef CONFIGURE_WITH_WPS
return !WiFi.SSID().isEmpty() && !WiFi.psk().isEmpty();
#else
return !system.ssid.isEmpty() && !system.pass.isEmpty();
#endif
return !system.systemMode.equals("config") && !system.ssid.isEmpty();
}

static bool saveSetting(const char* key, String& value) {
Expand Down Expand Up @@ -188,10 +187,8 @@ class Config {
// System and WiFi settings
system.friendlyName = preferences.getString(CONFIG_KEY_device_name, system.friendlyName);
system.systemMode = preferences.getString(CONFIG_KEY_system_mode, system.systemMode);
#ifndef CONFIGURE_WITH_WPS
system.ssid = preferences.getString(CONFIG_KEY_wifi_ssid, system.ssid);
system.pass = preferences.getString(CONFIG_KEY_wifi_password, system.pass);
#endif
// Time Zone
zone.id = preferences.getString(CONFIG_KEY_system_zone_id, zone.id);
zone.description = preferences.getString(CONFIG_KEY_system_zone_description, zone.description);
Expand All @@ -204,10 +201,8 @@ class Config {
preferences.begin(CONFIG_SYSTEM_NAME, false);
preferences.putString(CONFIG_KEY_device_name, system.friendlyName);
preferences.putString(CONFIG_KEY_system_mode, system.systemMode);
#ifndef CONFIGURE_WITH_WPS
preferences.putString(CONFIG_KEY_wifi_ssid, system.ssid);
preferences.putString(CONFIG_KEY_wifi_password, system.pass);
#endif
// Time Zone
preferences.putString(CONFIG_KEY_system_zone_id, zone.id);
preferences.putString(CONFIG_KEY_system_zone_description, zone.description);
Expand Down
Loading

0 comments on commit 3d64223

Please sign in to comment.