diff --git a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino index 4752702b2..f6e90ca2b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_03_energy.ino @@ -1036,6 +1036,9 @@ void CmndMaxEnergyStart(void) { void EnergyDrvInit(void) { memset(&Energy, 0, sizeof(Energy)); // Reset all to 0 and false; +// Energy.voltage_common = false; +// Energy.frequency_common = false; +// Energy.use_overtemp = false; for (uint32_t phase = 0; phase < ENERGY_MAX_PHASES; phase++) { Energy.apparent_power[phase] = NAN; Energy.reactive_power[phase] = NAN; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro.ino b/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro.ino index d7ffd8caa..1c695804d 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_88_esp32_shelly_pro.ino @@ -23,18 +23,18 @@ /*********************************************************************************************\ * Shelly Pro support * - * {"NAME":"Shelly Pro 1","GPIO":[0,0,0,0,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,0,0,160,0],"FLAG":0,"BASE":1} - * {"NAME":"Shelly Pro 2","GPIO":[0,0,0,0,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,0,0,160,161],"FLAG":0,"BASE":1} + * {"NAME":"Shelly Pro 1","GPIO":[0,1,0,1,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,4736,0,160,0],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350"} + * {"NAME":"Shelly Pro 1PM","GPIO":[9568,1,9472,1,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,3459,0,0,32,4736,0,160,0],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350"} + * {"NAME":"Shelly Pro 2","GPIO":[0,1,0,1,768,0,0,0,672,704,736,0,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,0,0,0,32,4736,4737,160,161],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350;AdcParam2 2,10000,10000,3350"} + * {"NAME":"Shelly Pro 2PM","GPIO":[9568,1,9472,1,768,0,0,0,672,704,736,9569,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,3460,0,0,32,4736,4737,160,161],"FLAG":0,"BASE":1,"CMND":"AdcParam1 2,10000,10000,3350;AdcParam2 2,10000,10000,3350"} * * Shelly Pro uses SPI to control one 74HC595 for relays/leds and one ADE7953 (1PM) or two ADE7953 (2PM) for energy monitoring - * - * Testset - * {"NAME":"Shelly Pro 2PM (POC)","GPIO":[1,0,1,0,768,1,0,0,672,704,736,1,0,0,5600,6214,0,0,0,5568,0,0,0,0,0,0,0,0,1,1,1,32,1,1,160,161],"FLAG":0,"BASE":1} \*********************************************************************************************/ #define XDRV_88 88 struct SPro { + uint32_t last_update; uint8_t pin_shift595_rclk; uint8_t ledlink; uint8_t power; @@ -53,9 +53,9 @@ void ShellyProUpdate(void) { SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0)); SPI.transfer(val); // Write 74HC595 shift register SPI.endTransaction(); - - digitalWrite(SPro.pin_shift595_rclk, 1); - delayMicroseconds(200); // Shelly 10mS + delayMicroseconds(2); // Wait for SPI clock to stop + digitalWrite(SPro.pin_shift595_rclk, 1); // Latch data + delayMicroseconds(2); // Shelly 10mS digitalWrite(SPro.pin_shift595_rclk, 0); } @@ -71,13 +71,13 @@ void ShellyProPreInit(void) { } SPro.pin_shift595_rclk = Pin(GPIO_SPI_CS); - pinMode(SPro.pin_shift595_rclk, OUTPUT); digitalWrite(SPro.pin_shift595_rclk, 0); + pinMode(SPro.pin_shift595_rclk, OUTPUT); // Does nothing if SPI is already initiated (by ADE7953) so no harm done SPI.begin(Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), -1); SPro.power = TasmotaGlobal.power &3; // Restore power - SPro.ledlink = 0x1C; // All leds off + SPro.ledlink = 0x18; // Blue led on ShellyProUpdate(); SPro.detected = true; @@ -90,10 +90,40 @@ void ShellyProPower(void) { ShellyProUpdate(); } +void ShellyProUpdateLedLink(uint32_t ledlink) { + if (ledlink != SPro.ledlink) { + SPro.ledlink = ledlink; + ShellyProUpdate(); + } +} + void ShellyProLedLink(void) { - // bit 2 = blue, 3 = green, 4 = red - SPro.ledlink = (XdrvMailbox.index) ? 0x18 : 0x1C; // Blue on (wifi link) or all off - ShellyProUpdate(); + /* + bit 2 = blue, 3 = green, 4 = red + Shelly Pro documentation + - Blue light indicator will be on if in AP mode. + - Red light indicator will be on if in STA mode and not connected to a Wi-Fi network. + - Yellow light indicator will be on if in STA mode and connected to a Wi-Fi network. + - Green light indicator will be on if in STA mode and connected to a Wi-Fi network and to the Shelly Cloud. + - The light indicator will be flashing Red/Blue if OTA update is in progress. + Tasmota default behaviour + - Blue light indicator will blink if no wifi or mqtt. + */ + SPro.last_update = TasmotaGlobal.uptime; + uint32_t ledlink = 0x1C; + if (XdrvMailbox.index) { ledlink &= 0xFB; } // Blue blinks if wifi/mqtt lost + if (!TasmotaGlobal.global_state.wifi_down) { ledlink &= 0xF7; } // Green On + ShellyProUpdateLedLink(ledlink); +} + +void ShellyProLedLinkWifiOff(void) { + /* + bit 2 = blue, 3 = green, 4 = red + - Green light indicator will be on if in STA mode and connected to a Wi-Fi network. + */ + if (SPro.last_update +1 < TasmotaGlobal.uptime) { + ShellyProUpdateLedLink((TasmotaGlobal.global_state.wifi_down) ? 0x1C : 0x14); // Green off if wifi OFF + } } /*********************************************************************************************\ @@ -107,6 +137,9 @@ bool Xdrv88(uint8_t function) { ShellyProPreInit(); } else if (SPro.detected) { switch (function) { + case FUNC_EVERY_SECOND: + ShellyProLedLinkWifiOff(); + break; case FUNC_SET_POWER: ShellyProPower(); break;