Make Telegram command ``TmState`` persistent

Make Telegram command ``TmState`` persistent (#11965)
This commit is contained in:
Theo Arends 2021-04-30 15:42:57 +02:00
parent 9f9625ac5c
commit 86ec4af6c5
6 changed files with 76 additions and 25 deletions

View File

@ -3,7 +3,11 @@ All notable changes to this project will be documented in this file.
## [Unreleased] - Development ## [Unreleased] - Development
## [9.4.0.2] ## [9.4.0.3]
### Added
- Make Telegram command ``TmState`` persistent (#11965)
## [9.4.0.2] 20210430
### Added ### Added
- Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>|<any template related command>|..."`` (#11788) - Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>|<any template related command>|..."`` (#11788)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` (#10814) - ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` (#10814)

View File

@ -81,6 +81,7 @@ The binaries can be downloaded from either https://github.com/arendst/Tasmota/tr
- Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>|<any template related command>|..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788) - Initial support for optional ``Template`` JSON fieldpair ``"CMND":"<any template related command>|<any template related command>|..."`` [#11788](https://github.com/arendst/Tasmota/issues/11788)
- ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` [#10814](https://github.com/arendst/Tasmota/issues/10814) - ESP32 pulldown buttons ``Button_d`` and ``Button_id`` and switches ``Switch_d`` [#10814](https://github.com/arendst/Tasmota/issues/10814)
- Support for MQTT using Azure IoT Hub by Kevin Saye [#11906](https://github.com/arendst/Tasmota/issues/11906) - Support for MQTT using Azure IoT Hub by Kevin Saye [#11906](https://github.com/arendst/Tasmota/issues/11906)
- Make Telegram command ``TmState`` persistent [#11965](https://github.com/arendst/Tasmota/issues/11965)
### Breaking Changed ### Breaking Changed

View File

@ -22,6 +22,7 @@
const uint8_t PARAM8_SIZE = 18; // Number of param bytes (SetOption) const uint8_t PARAM8_SIZE = 18; // Number of param bytes (SetOption)
// Bitfield to be used for any SetOption0 .. SetOption31 persistent single bit
typedef union { // Restricted by MISRA-C Rule 18.4 but so useful... typedef union { // Restricted by MISRA-C Rule 18.4 but so useful...
uint32_t data; // Allow bit manipulation using SetOption uint32_t data; // Allow bit manipulation using SetOption
struct { // SetOption0 .. SetOption31 struct { // SetOption0 .. SetOption31
@ -58,8 +59,9 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t hass_light : 1; // bit 30 (v6.0.0b) - SetOption30 - (HAss) enforce autodiscovery as light (1) uint32_t hass_light : 1; // bit 30 (v6.0.0b) - SetOption30 - (HAss) enforce autodiscovery as light (1)
uint32_t global_state : 1; // bit 31 (v6.1.0) - SetOption31 - (Wifi, MQTT) Control link led blinking (1) uint32_t global_state : 1; // bit 31 (v6.1.0) - SetOption31 - (Wifi, MQTT) Control link led blinking (1)
}; };
} SysBitfield; } SOBitfield;
// Bitfield to be used for any SetOption50 .. SetOption81 persistent single bit
typedef union { // Restricted by MISRA-C Rule 18.4 but so useful... typedef union { // Restricted by MISRA-C Rule 18.4 but so useful...
uint32_t data; // Allow bit manipulation using SetOption uint32_t data; // Allow bit manipulation using SetOption
struct { // SetOption50 .. SetOption81 struct { // SetOption50 .. SetOption81
@ -96,8 +98,9 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t shutter_mode : 1; // bit 30 (v6.6.0.14) - SetOption80 - (Shutter) Enable shutter support (1) uint32_t shutter_mode : 1; // bit 30 (v6.6.0.14) - SetOption80 - (Shutter) Enable shutter support (1)
uint32_t pcf8574_ports_inverted : 1; // bit 31 (v6.6.0.14) - SetOption81 - (PCF8574) Invert all ports on PCF8574 devices (1) uint32_t pcf8574_ports_inverted : 1; // bit 31 (v6.6.0.14) - SetOption81 - (PCF8574) Invert all ports on PCF8574 devices (1)
}; };
} SysBitfield3; } SOBitfield3;
// Bitfield to be used for any SetOption82 .. SetOption113 persistent single bit
typedef union { // Restricted by MISRA-C Rule 18.4 but so useful... typedef union { // Restricted by MISRA-C Rule 18.4 but so useful...
uint32_t data; // Allow bit manipulation using SetOption uint32_t data; // Allow bit manipulation using SetOption
struct { // SetOption82 .. SetOption113 struct { // SetOption82 .. SetOption113
@ -134,8 +137,9 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t zb_topic_fname : 1; // bit 30 (v8.5.0.1) - SetOption112 - (Zigbee) Use friendly name in zigbee topic (1) (use with SetOption89) uint32_t zb_topic_fname : 1; // bit 30 (v8.5.0.1) - SetOption112 - (Zigbee) Use friendly name in zigbee topic (1) (use with SetOption89)
uint32_t rotary_poweron_dimlow : 1; // bit 31 (v9.0.0.2) - SetOption113 - (Rotary) Set dimmer low on rotary dial after power off (1) uint32_t rotary_poweron_dimlow : 1; // bit 31 (v9.0.0.2) - SetOption113 - (Rotary) Set dimmer low on rotary dial after power off (1)
}; };
} SysBitfield4; } SOBitfield4;
// Bitfield to be used for any SetOption114 .. SetOption145 persistent single bit
typedef union { // Restricted by MISRA-C Rule 18.4 but so useful... typedef union { // Restricted by MISRA-C Rule 18.4 but so useful...
uint32_t data; // Allow bit manipulation using SetOption uint32_t data; // Allow bit manipulation using SetOption
struct { // SetOption114 .. SetOption145 struct { // SetOption114 .. SetOption145
@ -172,8 +176,9 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t spare30 : 1; // bit 30 uint32_t spare30 : 1; // bit 30
uint32_t spare31 : 1; // bit 31 uint32_t spare31 : 1; // bit 31
}; };
} SysBitfield5; } SOBitfield5;
// Bitfield to be used for persistent multi bit
typedef union { typedef union {
uint32_t data; // Allow bit manipulation uint32_t data; // Allow bit manipulation
struct { struct {
@ -195,6 +200,7 @@ typedef union {
}; };
} SysMBitfield1; } SysMBitfield1;
// Bitfield to be used for persistent multi bit
typedef union { typedef union {
uint32_t data; // Allow bit manipulation uint32_t data; // Allow bit manipulation
struct { struct {
@ -232,6 +238,45 @@ typedef union {
}; };
} SysMBitfield2; } SysMBitfield2;
// Bitfield to be used for non-SetOption persistent single bit
typedef union {
uint32_t data; // Allow bit manipulation
struct {
uint32_t telegram_send_enable : 1; // bit 0 (v9.4.0.3) - CMND_TMSTATE 0/1 - Enable Telegram send
uint32_t telegram_recv_enable : 1; // bit 1 (v9.4.0.3) - CMND_TMSTATE 2/3 - Enable Telegram receive
uint32_t telegram_echo_enable : 1; // bit 2 (v9.4.0.3) - CMND_TMSTATE 4/5 - Enable Telegram echo
uint32_t spare03 : 1; // bit 3
uint32_t spare04 : 1; // bit 4
uint32_t spare05 : 1; // bit 5
uint32_t spare06 : 1; // bit 6
uint32_t spare07 : 1; // bit 7
uint32_t spare08 : 1; // bit 8
uint32_t spare09 : 1; // bit 9
uint32_t spare10 : 1; // bit 10
uint32_t spare11 : 1; // bit 11
uint32_t spare12 : 1; // bit 12
uint32_t spare13 : 1; // bit 13
uint32_t spare14 : 1; // bit 14
uint32_t spare15 : 1; // bit 15
uint32_t spare16 : 1; // bit 16
uint32_t spare17 : 1; // bit 17
uint32_t spare18 : 1; // bit 18
uint32_t spare19 : 1; // bit 19
uint32_t spare20 : 1; // bit 20
uint32_t spare21 : 1; // bit 21
uint32_t spare22 : 1; // bit 22
uint32_t spare23 : 1; // bit 23
uint32_t spare24 : 1; // bit 24
uint32_t spare25 : 1; // bit 25
uint32_t spare26 : 1; // bit 26
uint32_t spare27 : 1; // bit 27
uint32_t spare28 : 1; // bit 28
uint32_t spare29 : 1; // bit 29
uint32_t spare30 : 1; // bit 30
uint32_t spare31 : 1; // bit 31
};
} SBitfield1;
typedef union { typedef union {
uint16_t data; uint16_t data;
struct { struct {
@ -400,7 +445,7 @@ struct {
unsigned long version; // 008 unsigned long version; // 008
uint16_t bootcount; // 00C uint16_t bootcount; // 00C
uint16_t cfg_crc; // 00E uint16_t cfg_crc; // 00E
SysBitfield flag; // 010 SOBitfield flag; // 010
int16_t save_data; // 014 int16_t save_data; // 014
int8_t timezone; // 016 int8_t timezone; // 016
@ -472,7 +517,7 @@ struct {
uint16_t blinktime; // 39A uint16_t blinktime; // 39A
uint16_t blinkcount; // 39C uint16_t blinkcount; // 39C
uint16_t light_rotation; // 39E uint16_t light_rotation; // 39E
SysBitfield3 flag3; // 3A0 SOBitfield3 flag3; // 3A0
uint8_t ex_switchmode[8]; // 3A4 - Free since 9.2.0.6 uint8_t ex_switchmode[8]; // 3A4 - Free since 9.2.0.6
@ -651,7 +696,7 @@ struct {
uint8_t ex_adc_param_type; // EF7 Free since 9.0.0.1 uint8_t ex_adc_param_type; // EF7 Free since 9.0.0.1
SysBitfield4 flag4; // EF8 SOBitfield4 flag4; // EF8
uint16_t mqtt_port; // EFC uint16_t mqtt_port; // EFC
uint8_t serial_config; // EFE uint8_t serial_config; // EFE
uint8_t wifi_output_power; // EFF uint8_t wifi_output_power; // EFF
@ -694,14 +739,15 @@ struct {
uint16_t shd_warmup_brightness; // F5C uint16_t shd_warmup_brightness; // F5C
uint8_t shd_warmup_time; // F5E uint8_t shd_warmup_time; // F5E
uint8_t free_f5f[69]; // F5F - Decrement if adding new Setting variables just above and below uint8_t free_f5f[65]; // F5F - Decrement if adding new Setting variables just above and below
// Only 32 bit boundary variables below // Only 32 bit boundary variables below
SBitfield1 sbflag1; // FA0
TeleinfoCfg teleinfo; // FA4 TeleinfoCfg teleinfo; // FA4
uint64_t rf_protocol_mask; // FA8 uint64_t rf_protocol_mask; // FA8
uint8_t device_group_tie[4]; // FB0 uint8_t device_group_tie[4]; // FB0
SysBitfield5 flag5; // FB4 SOBitfield5 flag5; // FB4
uint16_t pulse_counter_debounce_low; // FB8 uint16_t pulse_counter_debounce_low; // FB8
uint16_t pulse_counter_debounce_high; // FBA uint16_t pulse_counter_debounce_high; // FBA
uint32_t keeloq_master_msb; // FBC uint32_t keeloq_master_msb; // FBC

View File

@ -706,10 +706,10 @@ void SettingsDefaultSet2(void) {
memset((char*)&Settings +16, 0x00, sizeof(Settings) -16); memset((char*)&Settings +16, 0x00, sizeof(Settings) -16);
// this little trick allows GCC to optimize the assignment by grouping values and doing only ORs // this little trick allows GCC to optimize the assignment by grouping values and doing only ORs
SysBitfield flag = { 0 }; SOBitfield flag = { 0 };
SysBitfield3 flag3 = { 0 }; SOBitfield3 flag3 = { 0 };
SysBitfield4 flag4 = { 0 }; SOBitfield4 flag4 = { 0 };
SysBitfield5 flag5 = { 0 }; SOBitfield5 flag5 = { 0 };
SysMBitfield1 flag2 = { 0 }; SysMBitfield1 flag2 = { 0 };
SysMBitfield2 mbflag2 = { 0 }; SysMBitfield2 mbflag2 = { 0 };
@ -1259,6 +1259,9 @@ void SettingsDelta(void) {
if (Settings.version < 0x09030104) { if (Settings.version < 0x09030104) {
Settings.mbflag2.data = 0; Settings.mbflag2.data = 0;
} }
if (Settings.version < 0x09040002) {
Settings.sbflag1.data = 0;
}
Settings.version = VERSION; Settings.version = VERSION;
SettingsSave(1); SettingsSave(1);

View File

@ -20,6 +20,6 @@
#ifndef _TASMOTA_VERSION_H_ #ifndef _TASMOTA_VERSION_H_
#define _TASMOTA_VERSION_H_ #define _TASMOTA_VERSION_H_
const uint32_t VERSION = 0x09040002; const uint32_t VERSION = 0x09040003;
#endif // _TASMOTA_VERSION_H_ #endif // _TASMOTA_VERSION_H_

View File

@ -78,9 +78,6 @@ struct {
uint8_t retry = 0; uint8_t retry = 0;
uint8_t poll = TELEGRAM_LOOP_WAIT; uint8_t poll = TELEGRAM_LOOP_WAIT;
uint8_t wait = 0; uint8_t wait = 0;
bool send_enable = false;
bool recv_enable = false;
bool echo_enable = false;
bool recv_busy = false; bool recv_busy = false;
bool skip = true; // Skip first telegram if restarted bool skip = true; // Skip first telegram if restarted
} Telegram; } Telegram;
@ -317,7 +314,7 @@ String TelegramExecuteCommand(const char *svalue) {
} }
void TelegramLoop(void) { void TelegramLoop(void) {
if (!TasmotaGlobal.global_state.network_down && (Telegram.recv_enable || Telegram.echo_enable)) { if (!TasmotaGlobal.global_state.network_down && (Settings.sbflag1.telegram_recv_enable || Settings.sbflag1.telegram_echo_enable)) {
switch (Telegram.state) { switch (Telegram.state) {
case 0: case 0:
TelegramInit(); TelegramInit();
@ -330,7 +327,7 @@ void TelegramLoop(void) {
Telegram.state++; Telegram.state++;
break; break;
case 2: case 2:
if (Telegram.echo_enable) { if (Settings.sbflag1.telegram_echo_enable) {
if (Telegram.retry && (Telegram.index < Telegram.message_count)) { if (Telegram.retry && (Telegram.index < Telegram.message_count)) {
if (TelegramSendMessage(Telegram.message[Telegram.index].chat_id, Telegram.message[Telegram.index].text)) { if (TelegramSendMessage(Telegram.message[Telegram.index].chat_id, Telegram.message[Telegram.index].text)) {
Telegram.index++; Telegram.index++;
@ -391,21 +388,21 @@ void CmndTmState(void) {
switch (XdrvMailbox.payload) { switch (XdrvMailbox.payload) {
case 0: // Off case 0: // Off
case 1: // On case 1: // On
Telegram.send_enable = XdrvMailbox.payload &1; Settings.sbflag1.telegram_send_enable = XdrvMailbox.payload &1;
break; break;
case 2: // Off case 2: // Off
case 3: // On case 3: // On
Telegram.recv_enable = XdrvMailbox.payload &1; Settings.sbflag1.telegram_recv_enable = XdrvMailbox.payload &1;
break; break;
case 4: // Off case 4: // Off
case 5: // On case 5: // On
Telegram.echo_enable = XdrvMailbox.payload &1; Settings.sbflag1.telegram_echo_enable = XdrvMailbox.payload &1;
break; break;
} }
} }
} }
snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":{\"Send\":\"%s\",\"Receive\":\"%s\",\"Echo\":\"%s\"}}"), snprintf_P (TasmotaGlobal.mqtt_data, sizeof(TasmotaGlobal.mqtt_data), PSTR("{\"%s\":{\"Send\":\"%s\",\"Receive\":\"%s\",\"Echo\":\"%s\"}}"),
XdrvMailbox.command, GetStateText(Telegram.send_enable), GetStateText(Telegram.recv_enable), GetStateText(Telegram.echo_enable)); XdrvMailbox.command, GetStateText(Settings.sbflag1.telegram_send_enable), GetStateText(Settings.sbflag1.telegram_recv_enable), GetStateText(Settings.sbflag1.telegram_echo_enable));
} }
void CmndTmPoll(void) { void CmndTmPoll(void) {
@ -433,7 +430,7 @@ void CmndTmChatId(void) {
} }
void CmndTmSend(void) { void CmndTmSend(void) {
if (!Telegram.send_enable || !strlen(SettingsText(SET_TELEGRAM_CHATID))) { if (!Settings.sbflag1.telegram_send_enable || !strlen(SettingsText(SET_TELEGRAM_CHATID))) {
ResponseCmndFailed(); ResponseCmndFailed();
return; return;
} }