From 31ffdf1e2b8be27a8bddec540f64c87dd13b0764 Mon Sep 17 00:00:00 2001 From: Florian Date: Tue, 10 Jan 2023 07:18:59 -0600 Subject: [PATCH] Add SHELLY PLUS 1 board with support of relay, switch, BT gateway (#1349) So that you know, the overtemperature protection is not implemented in the firmware. --- .github/workflows/build.yml | 1 + docs/upload/web-install.md | 1 + main/ZactuatorONOFF.ino | 15 +++++++++------ main/ZsensorGPIOInput.ino | 19 +++++++++---------- main/config_GPIOInput.h | 4 ++++ main/config_ONOFF.h | 5 ++++- platformio.ini | 35 +++++++++++++++++++++++++++++++++++ scripts/gen_wu.py | 2 +- scripts/gen_wu_dev.py | 2 +- 9 files changed, 65 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9384d8e..098d24e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,7 @@ jobs: - "ttgo-t-beam" - "heltec-wifi-lora-32-868" - "heltec-wifi-lora-32-915" + - "shelly-plus1" - "nodemcuv2-all-test" - "nodemcuv2-fastled-test" - "nodemcuv2-2g" diff --git a/docs/upload/web-install.md b/docs/upload/web-install.md index 428f7bf..90423c3 100644 --- a/docs/upload/web-install.md +++ b/docs/upload/web-install.md @@ -47,6 +47,7 @@ The table below describes the libraries and the modules of each board configurat |esp32dev-somfy-CC1101|ESP32 dev board|Gateway using [Somfy Remote](https://github.com/Legion2/Somfy_Remote_Lib) library, need CC1101|X|-|-|-| |esp32dev-weatherstation|ESP32 dev board|Gateway to retrieve weather station data Ventus W174/W132 (tested), Auriol H13726, Hama EWS 1500, Meteoscan W155/W160 using [WeatherStationDataRx](https://github.com/Zwer2k/WeatherStationDataRx)|X|-|-|-| |esp32feather-ble|ESP32 Feather Adafruit|BLE for the Adafruit Feather board|-|-|X|-| +|shelly-plus1|Shelly Plus 1 relay board|BLE, Relay control, Switch|-|-|X|-| |heltec-wifi-lora32-868|ESP32 HELTEC LORA V2|LORA communication 868Mhz using [arduino-LoRA](https://github.com/sandeepmistry/arduino-LoRa) |-|-|-|X| |heltec-wifi-lora32-915|ESP32 HELTEC LORA V2|LORA communication 915Mhz using [arduino-LoRA](https://github.com/sandeepmistry/arduino-LoRa)|-|-|-|X| |heltec-rtl_433|ESP32 HELTEC LORA32 v2|Gateway using [RTL_433_ESP](https://github.com/NorthernMan54/rtl_433_ESP) and [RadioLib](https://github.com/jgromes/RadioLib)|X|-|-|-| diff --git a/main/ZactuatorONOFF.ino b/main/ZactuatorONOFF.ino index cf54391..841c70e 100644 --- a/main/ZactuatorONOFF.ino +++ b/main/ZactuatorONOFF.ino @@ -103,13 +103,16 @@ void MQTTtoONOFF(char* topicOri, char* datacallback) { } # endif -void ActuatorButtonTrigger() { - uint8_t level = !digitalRead(ACTUATOR_ONOFF_GPIO); - char* level_string = "ON"; - if (level != ACTUATOR_ON) { - level_string = "OFF"; +void ActuatorManualTrigger(uint8_t level) { +# ifdef ACTUATOR_BUTTON_TRIGGER_LEVEL + if (level == ACTUATOR_BUTTON_TRIGGER_LEVEL) { + // Change level value to the opposite of the current level + level = !digitalRead(ACTUATOR_ONOFF_GPIO); } - Log.trace(F("Actuator triggered %s by button" CR), level_string); +# else + level = !digitalRead(ACTUATOR_ONOFF_GPIO); +# endif + Log.trace(F("Actuator triggered %d" CR), level); digitalWrite(ACTUATOR_ONOFF_GPIO, level); // Send the state of the switch to the broker so as to update the status StaticJsonDocument jsonBuffer; diff --git a/main/ZsensorGPIOInput.ino b/main/ZsensorGPIOInput.ino index 6922e31..279defb 100644 --- a/main/ZsensorGPIOInput.ino +++ b/main/ZsensorGPIOInput.ino @@ -34,11 +34,11 @@ unsigned long resetTime = 0; # endif unsigned long lastDebounceTime = 0; int InputState = 3; // Set to 3 so that it reads on startup -int lastInputState = 3; +int previousInputState = 3; void setupGPIOInput() { Log.notice(F("Reading GPIO at pin: %d" CR), INPUT_GPIO); - pinMode(INPUT_GPIO, INPUT_PULLUP); // declare GPIOInput pin as input_pullup to prevent floating. Pin will be high when not connected to ground + pinMode(INPUT_GPIO, GPIO_INPUT_TYPE); // declare GPIOInput pin as input_pullup to prevent floating. Pin will be high when not connected to ground } void MeasureGPIOInput() { @@ -49,7 +49,7 @@ void MeasureGPIOInput() { // since the last press to ignore any noise: // If the switch changed, due to noise or pressing: - if (reading != lastInputState) { + if (reading != previousInputState) { // reset the debouncing timer lastDebounceTime = millis(); } @@ -75,7 +75,6 @@ void MeasureGPIOInput() { # endif // if the Input state has changed: if (reading != InputState) { - InputState = reading; Log.trace(F("Creating GPIOInput buffer" CR)); StaticJsonDocument jsonBuffer; JsonObject GPIOdata = jsonBuffer.to(); @@ -88,15 +87,15 @@ void MeasureGPIOInput() { if (GPIOdata.size() > 0) pub(subjectGPIOInputtoMQTT, GPIOdata); -# ifdef ZactuatorONOFF - if (InputState == ACTUATOR_BUTTON_TRIGGER_LEVEL) { - ActuatorButtonTrigger(); - } +# if defined(ZactuatorONOFF) && defined(ACTUATOR_TRIGGER) + //Trigger the actuator if we are not at startup + if (InputState != 3) ActuatorManualTrigger(InputState); # endif + InputState = reading; } } - // save the reading. Next time through the loop, it'll be the lastInputState: - lastInputState = reading; + // save the reading. Next time through the loop, it'll be the previousInputState: + previousInputState = reading; } #endif diff --git a/main/config_GPIOInput.h b/main/config_GPIOInput.h index b7dce13..5a4d9cd 100644 --- a/main/config_GPIOInput.h +++ b/main/config_GPIOInput.h @@ -42,6 +42,10 @@ extern void GPIOInputtoMQTT(); # endif #endif +#ifndef GPIO_INPUT_TYPE +# define GPIO_INPUT_TYPE INPUT_PULLUP +#endif + #define INPUT_GPIO_ON_VALUE "HIGH" #define INPUT_GPIO_OFF_VALUE "LOW" diff --git a/main/config_ONOFF.h b/main/config_ONOFF.h index 854a1e8..4641d0f 100644 --- a/main/config_ONOFF.h +++ b/main/config_ONOFF.h @@ -41,7 +41,10 @@ extern void MQTTtoONOFF(char* topicOri, JsonObject& RFdata); #endif //# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON // ACTUATOR_ON or !ACTUATOR_ON, set to the state desired on reset. #ifndef ACTUATOR_BUTTON_TRIGGER_LEVEL -# define ACTUATOR_BUTTON_TRIGGER_LEVEL LOW // 0 or 1, set to the sensing level which to detect a button press to change the actuator state. +//# define ACTUATOR_BUTTON_TRIGGER_LEVEL LOW // 0 or 1, set to the sensing level which to detect a button press to change the actuator state. +#endif +#ifndef ACTUATOR_TRIGGER +# define ACTUATOR_TRIGGER false // false or true, enable to control an actuator directly from the board switch (default behavior if true), or by button if ACTUATOR_BUTTON_TRIGGER_LEVEL is defined #endif /*-------------------PIN DEFINITIONS----------------------*/ diff --git a/platformio.ini b/platformio.ini index 44e268c..90e5ebb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -61,6 +61,7 @@ extra_configs = ;default_envs = tinypico-ble ;default_envs = ttgo-lora32-v1-868 ;default_envs = ttgo-lora32-v1-915 +;default_envs = shelly-plus1 ;default_envs = ttgo-t-beam ;default_envs = heltec-wifi-lora-32-868 ;default_envs = heltec-wifi-lora-32-915 @@ -159,6 +160,7 @@ monitor_speed = 115200 esp8266_platform = espressif8266@3.2.0 esp32_platform = espressif32@3.5.0 esp32_c3_s3_platform = espressif32@5.2.0 +esp32_solo_platform = https://github.com/tasmota/platform-espressif32/releases/download/v.2.0.5/platform-espressif32-v.2.0.5.zip atmelavr_platform = atmelavr@3.3.0 [com-esp] @@ -1020,6 +1022,37 @@ build_flags = '-DTimeLedON=0.1' '-DLED_SEND_RECEIVE_ON=1' +[env:shelly-plus1] +platform = ${com.esp32_solo_platform} +board = esp32-solo1 +board_build.partitions = min_spiffs.csv +lib_deps = + ${com-esp.lib_deps} + ${libraries.ble} + ${libraries.wifimanager32} + ${libraries.decoder} +build_flags = + ${env.build_flags} + ${com-esp.build_flags} + '-DZgatewayBT="BT"' + '-DTimeBtwRead=100' + '-DScan_duration=3000' + '-DTRIGGER_GPIO=25' + '-DZactuatorONOFF="ONOFF"' + '-DACTUATOR_ON=1' + '-DACTUATOR_OFF=0' + '-ACTUATOR_TRIGGER=true' + '-DZsensorGPIOInput="GPIOInput"' + '-DINPUT_GPIO=4' + '-DGPIO_INPUT_TYPE=INPUT' + '-DACTUATOR_ONOFF_GPIO=26' + '-DZsensorADC="ADC"' + '-DADC_GPIO=32' + '-DUSE_MAC_AS_GATEWAY_NAME' + '-DFRAMEWORK_ARDUINO_SOLO1' + '-DGATEWAY_MANUFACTURER="Shelly"' + '-DGATEWAY_MODEL="SPLUS1"' + [env:nodemcuv2-all-test] platform = ${com.esp8266_platform} board = nodemcuv2 @@ -1324,6 +1357,7 @@ build_flags = '-DACTUATOR_ON=0' '-DACTUATOR_ONOFF_DEFAULT=ACTUATOR_ON' '-DACTUATOR_BUTTON_TRIGGER_LEVEL=0' + '-ACTUATOR_TRIGGER=true' '-DGateway_Name="OpenMQTTGateway_SONOFF_RELAY"' board_build.flash_mode = dout @@ -1344,6 +1378,7 @@ build_flags = '-DACTUATOR_ON=0' '-DACTUATOR_ONOFF_DEFAULT=ACTUATOR_ON' '-DACTUATOR_BUTTON_TRIGGER_LEVEL=0' + '-ACTUATOR_TRIGGER=true' '-DRF_RECEIVER_GPIO=4' '-DZgatewayRF="RF"' '-DGateway_Name="OpenMQTTGateway_SONOFF_BASIC_RFR3"' diff --git a/scripts/gen_wu.py b/scripts/gen_wu.py index 9f27f0c..0e082b4 100644 --- a/scripts/gen_wu.py +++ b/scripts/gen_wu.py @@ -119,7 +119,7 @@ with open(manif_path + filename,'wb') as output_file: for item in range(len(assets)): name = assets[item]['name'] - if 'firmware.bin' in name and ('esp32' in name or 'ttgo' in name or 'heltec' in name or 'thingpulse' in name or 'lilygo' in name): + if 'firmware.bin' in name and ('esp32' in name or 'ttgo' in name or 'heltec' in name or 'thingpulse' in name or 'lilygo' in name or 'shelly' in name): fw = name.split('-firmware')[0] man_file = fw + '.manifest.json' fw_url = assets[item]['browser_download_url'] diff --git a/scripts/gen_wu_dev.py b/scripts/gen_wu_dev.py index 69368d2..f85fc91 100644 --- a/scripts/gen_wu_dev.py +++ b/scripts/gen_wu_dev.py @@ -107,7 +107,7 @@ with open(manif_path + filename,'wb') as output_file: output_file.write(boot_bin.content) for name in os.listdir(bin_path): - if 'firmware.bin' in name and ('esp32' in name or 'ttgo' in name or 'heltec' in name or 'thingpulse' in name or 'lilygo' in name): + if 'firmware.bin' in name and ('esp32' in name or 'ttgo' in name or 'heltec' in name or 'thingpulse' in name or 'lilygo' in name or 'shelly' in name): fw = name.split('-firmware')[0] man_file = fw + '.manifest.json' print('Bin name:' + name)