Skip to content

Commit

Permalink
v1.2.23
Browse files Browse the repository at this point in the history
- added configuration parameters for most system settings (see README.md)
- default configuration can now be passed as JSON key/value pair with the build flag `-D DEFAULT_CONFIG='{..}'`
  • Loading branch information
genemars committed Jun 20, 2024
1 parent 96dd7b8 commit bd33135
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 113 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,72 @@ pio device monitor -b 115200
```


### Firmware configuration commands

HomeGenie Mini device support also commands via serial terminal. You can enter any API
command using the `/api/` prefix, or enter system commands prefixed by `#` character.

#### System core commands

```
#CONFIG:device-name <name>
#CONFIG:wifi-ssid <ssid>
#CONFIG:wifi-password <passwd>
#CONFIG:system-time <hh>:<mm>:<ss>.<ms>
#CONFIG:system-zone-id <zone_id>
#CONFIG:system-zone-offset <tz_offset>
#VERSION
#RESET
```

#### Getting/Setting parameters

```
#GET:<key>
#SET:<key> <value>
```

##### System configuration parameters list

| Key | Description | Default |
|------------|----------------------------|------------------|
| `sys-rb-n` | Factory reset button GPIO# | -1 (-1=not used) |
| `sys-sl-n` | System status LED GPIO# | -1 (-1=not used) |
| `io-typ01` | I/O Ch.1 type | |
| `io-pin01` | I/O Ch.1 GPIO# | -1 (-1=not used) |
| `io-typ02` | I/O Ch.2 type | |
| `io-pin02` | I/O Ch.2 GPIO# | -1 (-1=not used) |
| `io-typ03` | I/O Ch.3 type | |
| `io-pin03` | I/O Ch.3 GPIO# | -1 (-1=not used) |
| `io-typ04` | I/O Ch.4 type | |
| `io-pin04` | I/O Ch.4 GPIO# | -1 (-1=not used) |
| `io-typ05` | I/O Ch.5 type | |
| `io-pin05` | I/O Ch.5 GPIO# | -1 (-1=not used) |
| `io-typ06` | I/O Ch.6 type | |
| `io-pin06` | I/O Ch.6 GPIO# | -1 (-1=not used) |
| `io-typ07` | I/O Ch.7 type | |
| `io-pin07` | I/O Ch.7 GPIO# | -1 (-1=not used) |
| `io-typ08` | I/O Ch.8 type | |
| `io-pin08` | I/O Ch.8 GPIO# | -1 (-1=not used) |

*Example **setting** configuration from a terminal connected to the serial port of the device:*

```
#SET:sys-sl-n=10
#SET:sys-rb-n=0
#RESET
```

*Example **getting** configuration value:*

```
#GET:sys-sl-n
```
response:
```
#GET:sys-sl-n=10
```


## Firmwares examples with source code

Expand Down
2 changes: 1 addition & 1 deletion examples/color-light/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A smart light device with addressable RGB LEDs.
- [Documentation and firmware install page](https://homegenie.it/mini/1.2/examples/smart-led-lights/)


## Firmware configuration
## Firmware configuration (in addition to default system options)

| Key | Description | Default |
|------------|----------------------------|-----------------------------------------|
Expand Down
31 changes: 15 additions & 16 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ lib_deps_8266 =
platform = [email protected]
build_flags = ${env.build_flags}

[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

[env:d1-mini]
[env:default-d1mini]
platform = [email protected]
board = d1_mini
build_flags = ${env.build_flags} -D DISABLE_UI -D DISABLE_AUTOMATION
Expand All @@ -55,19 +60,11 @@ lib_ignore =
ESP32_BleSerial
LovyanGFX

[env:d1-mini-esp32]
[env:sonoff-dualr3]
platform = [email protected]
build_flags = ${env.build_flags} -D MINI_ESP32 -D CONFIG_ServiceButtonPin=16 -D CONFIG_StatusLedPin=26 -D CONFIG_GPIO_OUT={18,19,23,5}

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"}'

[env:switch-relay-x2-esp32]
platform = [email protected]
build_flags = ${env.build_flags} -D DISABLE_UI -D CONFIG_ServiceButtonPin=0 -D CONFIG_StatusLedPin=23 -D CONFIG_GPIO_OUT="{16,17}"


[env:sonoff]
platform = [email protected]
build_flags = ${env.build_flags} -D DISABLE_UI -D CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK -D CONFIG_ServiceButtonPin=0 -D CONFIG_StatusLedPin=13 -D CONFIG_GPIO_OUT={14,27} -D CONFIG_GPIO_IN={32,33}

#------------------[ Examples ]------------------

Expand All @@ -81,7 +78,8 @@ lib_deps = ${env.lib_deps}

[env:smart-sensor-d1-mini-esp32]
platform = [email protected]
build_flags = ${env.build_flags} -I examples -I src -D MINI_ESP32 -D DISABLE_UI -D CONFIG_ServiceButtonPin=16 -D CONFIG_StatusLedPin=26 -D CONFIG_GPIO_OUT={18,19,23,5}
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"}'
build_src_filter = +<src> -<src/main.cpp> +<examples/smart-sensor>
lib_deps = ${env.lib_deps}
[email protected]
Expand Down Expand Up @@ -110,7 +108,8 @@ lib_deps = ${env.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 -D CONFIG_ENABLE_POWER_MANAGER -DESP32S3_DEV -DBOARD_HAS_PSRAM -D CONFIG_GPIO_OUT={15,17,18}
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 = +<src> -<src/main.cpp> +<examples/smart-sensor-display>
board_build.mcu = esp32s3
board_build.f_cpu = 240000000L
Expand Down Expand Up @@ -226,7 +225,7 @@ lib_deps = ${env.lib_deps}
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 CONFIG_StatusLedPin=-1 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=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> +<lib/jerryscript/amalgam/*> +<examples/color-light>
lib_deps = ${env.lib_deps}
https://github.com/adafruit/Adafruit_NeoPixel#1.12.0
Expand All @@ -244,7 +243,7 @@ lib_deps = ${env.lib_deps}
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 CONFIG_StatusLedPin=-1 -D ARDUINO_USB_MODE=1 -D ARDUINO_USB_CDC_ON_BOOT=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/shutter>
lib_deps = ${env.lib_deps}
arduino-libraries/Stepper@^1.1.3
Expand Down
9 changes: 4 additions & 5 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

ZoneConfig Config::zone;
SystemConfig Config::system;
short Config::ServiceButtonPin = -1;
short Config::StatusLedPin = -1;


bool Config::isStatusLedOn = false;
void Config::statusLedOn() {
Expand Down Expand Up @@ -104,10 +107,6 @@ void Config::handleConfigCommand(String &message) {
} else
if (message.equals("#RESET")) {
delay(50);
#ifndef ESP8266
esp_restart();
#else
// TODO: not supported by ESP8266
#endif
ESP.restart();
}
}
33 changes: 28 additions & 5 deletions src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "defs.h"

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

#ifdef CONFIG_AUTOMATION_SPAWN_FREERTOS_TASK
#include <FreeRTOSConfig.h>
#endif
Expand Down Expand Up @@ -94,9 +96,9 @@ class SystemConfig {

class Config {
public:
const static short ServiceButtonPin = CONFIG_ServiceButtonPin;
const static short StatusLedPin = CONFIG_StatusLedPin;
const static uint16_t ConfigureButtonPushInterval = 2500;
static short ServiceButtonPin;
static short StatusLedPin;
const static uint16_t ConfigureButtonPushInterval = 5000;
static ZoneConfig zone;
static SystemConfig system;
#ifdef ESP32
Expand Down Expand Up @@ -135,7 +137,7 @@ class Config {
preferences.begin(CONFIG_SYSTEM_NAME, false);
preferences.putString(k.c_str(), value);
preferences.end();
return false;
return false; // TODO: ?!?
}

static String getSetting(const char* key, const char* defaultValue = "") {
Expand All @@ -146,6 +148,24 @@ class Config {
value = preferences.getString(k.c_str(), defaultValue);
}
preferences.end();
// TODO: should use "pref.isKey(...)" for proper checking
if (value == "") {
// Lookup config factory defaults only if the value does not exists
String config = STRING_VALUE(DEFAULT_CONFIG);
if (!config.isEmpty()) {
JsonDocument doc;
DeserializationError error = deserializeJson(doc, config);
if (error.code() == 0) {
auto params = doc.as<JsonObject>();
for (auto p: params) {
if (p.key() == key) {
value = p.value().as<String>();
break;
}
}
}
}
}
return value;
}

Expand All @@ -157,7 +177,10 @@ class Config {
static void statusLedCallback(std::function<void(bool)> new_func);

static void init() {
// Setup status led
// Setup status LED and factory reset buttons
ServiceButtonPin = getSetting("sys-rb-n", "-1").toInt();
StatusLedPin = getSetting("sys-sl-n", "-1").toInt();
// Setup status LED
if (StatusLedPin >= 0) pinMode(StatusLedPin, OUTPUT);
Preferences preferences;

Expand Down
6 changes: 4 additions & 2 deletions src/HomeGenie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ namespace Service {
Config::init();

// Setup button
pinMode(Config::ServiceButtonPin, INPUT_PULLUP);
// attachInterrupt(digitalPinToInterrupt(Config::ServiceButtonPin), buttonChange, CHANGE);
if (Config::ServiceButtonPin != -1) {
pinMode(Config::ServiceButtonPin, INPUT_PULLUP);
// attachInterrupt(digitalPinToInterrupt(Config::ServiceButtonPin), buttonChange, CHANGE);
}

// Logger initialization
Logger::begin(LOG_LEVEL_TRACE);
Expand Down
3 changes: 3 additions & 0 deletions src/HomeGenie.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ namespace Service {
}
}
static void checkServiceButton() {
if (Config::ServiceButtonPin < 0) {
return;
}
buttonChange();
int64_t elapsed = 0;
if (getInstance()->buttonPressed) {
Expand Down
1 change: 0 additions & 1 deletion src/automation/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#ifndef HOMEGENIE_MINI_SCHEDULER_H
#define HOMEGENIE_MINI_SCHEDULER_H

#include <ArduinoJson.h>
#include <LinkedList.h>
#include <LittleFS.h>

Expand Down
30 changes: 0 additions & 30 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,14 @@
#define DISABLE_BLUETOOTH_CLASSIC
#define CONFIGURE_WITH_WPS
#define WebServer ESP8266WebServer
#ifndef CONFIG_GPIO_OUT
#define CONFIG_GPIO_OUT {14,12,13,15}
#endif
#endif

#ifdef ESP32_C3
#undef DISABLE_BLUETOOTH_LE
#define DISABLE_BLUETOOTH_CLASSIC
#define CONFIG_ServiceButtonPin 4
#if CONFIG_StatusLedPin != -1
#define CONFIG_StatusLedPin 0
#endif
#ifndef CONFIG_GPIO_OUT
#define CONFIG_GPIO_OUT {6}
#endif
#elif ESP32_S3
#undef DISABLE_BLUETOOTH_LE
#define DISABLE_BLUETOOTH_CLASSIC
#define CONFIG_ServiceButtonPin 21
#if CONFIG_StatusLedPin != -1
#define CONFIG_StatusLedPin 33
#endif
#ifndef CONFIG_GPIO_OUT
#define CONFIG_GPIO_OUT {15,16,17,18}
#endif
#else
#define DISABLE_BLUETOOTH_LE
// #define DISABLE_BLUETOOTH_CLASSIC
Expand All @@ -101,19 +84,6 @@
// #undef DISABLE_UI
#endif

#ifndef CONFIG_ServiceButtonPin
#define CONFIG_ServiceButtonPin 2
#endif
#ifndef CONFIG_StatusLedPin
#define CONFIG_StatusLedPin 16
#endif
#ifndef CONFIG_GPIO_OUT
#define CONFIG_GPIO_OUT {14,12,13,17}
#endif
#ifndef CONFIG_GPIO_IN
#define CONFIG_GPIO_IN { /* not implemented */ }
#endif


// --------------------------------

Expand Down
2 changes: 0 additions & 2 deletions src/net/MQTTServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#ifndef HOMEGENIE_MINI_MQTTSERVER_H
#define HOMEGENIE_MINI_MQTTSERVER_H

#include <ArduinoJson.h>

#include "Task.h"
#include "net/mqtt/MQTTBrokerMini.h"

Expand Down
Loading

0 comments on commit bd33135

Please sign in to comment.