From 3d3d634070cc7b76c424d8faae462d6ada0cbb12 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Tue, 19 Oct 2021 22:38:54 +0200 Subject: [PATCH] Berry support for tele rules --- lib/libesp32/Berry/default/be_tasmotalib.c | 271 +++++++++++++----- .../Berry/default/embedded/Tasmota.be | 23 ++ lib/libesp32/Berry/generate/be_const_strtab.h | 1 + .../Berry/generate/be_const_strtab_def.h | 5 +- .../generate/be_fixed_be_class_tasmota.h | 143 ++++----- tasmota/xdrv_10_rules.ino | 2 +- tasmota/xdrv_52_9_berry.ino | 9 +- 7 files changed, 299 insertions(+), 155 deletions(-) diff --git a/lib/libesp32/Berry/default/be_tasmotalib.c b/lib/libesp32/Berry/default/be_tasmotalib.c index b048c73a9..0951e1d21 100644 --- a/lib/libesp32/Berry/default/be_tasmotalib.c +++ b/lib/libesp32/Berry/default/be_tasmotalib.c @@ -1144,6 +1144,111 @@ be_local_closure(exec_rules, /* name */ /*******************************************************************/ +/******************************************************************** +** Solidified function: exec_tele +********************************************************************/ +be_local_closure(exec_tele, /* name */ + be_nested_proto( + 10, /* nstack */ + 2, /* argc */ + 0, /* varg */ + 0, /* has upvals */ + NULL, /* no upvals */ + 1, /* has sup protos */ + ( &(const struct bproto*[ 1]) { + be_nested_proto( + 8, /* nstack */ + 3, /* argc */ + 0, /* varg */ + 1, /* has upvals */ + ( &(const bupvaldesc[ 2]) { /* upvals */ + be_local_const_upval(1, 0), + be_local_const_upval(1, 3), + }), + 0, /* has sup protos */ + NULL, /* no sub protos */ + 1, /* has constants */ + ( &(const bvalue[ 1]) { /* constants */ + /* K0 */ be_nested_string("try_rule", 1986449405, 8), + }), + (be_nested_const_str("", 607256038, 8)), + (be_nested_const_str("tasmota.be", 1128870755, 10)), + ( &(const binstruction[11]) { /* code */ + 0x680C0000, // 0000 GETUPV R3 U0 + 0x8C0C0700, // 0001 GETMET R3 R3 K0 + 0x68140001, // 0002 GETUPV R5 U1 + 0x5C180000, // 0003 MOVE R6 R0 + 0x5C1C0200, // 0004 MOVE R7 R1 + 0x7C0C0800, // 0005 CALL R3 4 + 0x740E0001, // 0006 JMPT R3 #0009 + 0x740A0000, // 0007 JMPT R2 #0009 + 0x50080001, // 0008 LDBOOL R2 0 1 + 0x50080200, // 0009 LDBOOL R2 1 0 + 0x80040400, // 000A RET 1 R2 + }) + ), + }), + 1, /* has constants */ + ( &(const bvalue[ 9]) { /* constants */ + /* K0 */ be_nested_string("_rules", -28750191, 6), + /* K1 */ be_nested_string("json", 916562499, 4), + /* K2 */ be_nested_string("load", -435725847, 4), + /* K3 */ be_nested_string("log", 1062293841, 3), + /* K4 */ be_nested_string("BRY: ERROR, bad json: ", -1579831487, 22), + /* K5 */ be_const_int(3), + /* K6 */ be_nested_string("Tele", 1329980653, 4), + /* K7 */ be_nested_string("reduce", 2002030311, 6), + /* K8 */ be_nested_string("stop_iteration", -121173395, 14), + }), + (be_nested_const_str("exec_tele", 1020751601, 9)), + (be_nested_const_str("tasmota.be", 1128870755, 10)), + ( &(const binstruction[40]) { /* code */ + 0x88080100, // 0000 GETMBR R2 R0 K0 + 0x780A0022, // 0001 JMPF R2 #0025 + 0xA40A0200, // 0002 IMPORT R2 K1 + 0x8C0C0502, // 0003 GETMET R3 R2 K2 + 0x5C140200, // 0004 MOVE R5 R1 + 0x7C0C0400, // 0005 CALL R3 2 + 0x50100000, // 0006 LDBOOL R4 0 0 + 0x4C140000, // 0007 LDNIL R5 + 0x1C140605, // 0008 EQ R5 R3 R5 + 0x78160004, // 0009 JMPF R5 #000F + 0x8C140103, // 000A GETMET R5 R0 K3 + 0x001E0801, // 000B ADD R7 K4 R1 + 0x58200005, // 000C LDCONST R8 K5 + 0x7C140600, // 000D CALL R5 3 + 0x5C0C0200, // 000E MOVE R3 R1 + 0x60140013, // 000F GETGBL R5 G19 + 0x7C140000, // 0010 CALL R5 0 + 0x98160C03, // 0011 SETIDX R5 K6 R3 + 0x5C0C0A00, // 0012 MOVE R3 R5 + 0xA8020008, // 0013 EXBLK 0 #001D + 0x88140100, // 0014 GETMBR R5 R0 K0 + 0x8C140B07, // 0015 GETMET R5 R5 K7 + 0x841C0000, // 0016 CLOSURE R7 P0 + 0x4C200000, // 0017 LDNIL R8 + 0x50240000, // 0018 LDBOOL R9 0 0 + 0x7C140800, // 0019 CALL R5 4 + 0x5C100A00, // 001A MOVE R4 R5 + 0xA8040001, // 001B EXBLK 1 1 + 0x70020004, // 001C JMP #0022 + 0x58140008, // 001D LDCONST R5 K8 + 0xAC140200, // 001E CATCH R5 1 0 + 0x70020000, // 001F JMP #0021 + 0x70020000, // 0020 JMP #0022 + 0xB0080000, // 0021 RAISE 2 R0 R0 + 0xA0000000, // 0022 CLOSE R0 + 0x80040800, // 0023 RET 1 R4 + 0xA0080000, // 0024 CLOSE R2 + 0x50080000, // 0025 LDBOOL R2 0 0 + 0xA0000000, // 0026 CLOSE R0 + 0x80040400, // 0027 RET 1 R2 + }) + ) +); +/*******************************************************************/ + + /******************************************************************** ** Solidified function: remove_driver ********************************************************************/ @@ -1459,7 +1564,7 @@ be_local_closure(event, /* name */ 0, /* has sup protos */ NULL, /* no sub protos */ 1, /* has constants */ - ( &(const bvalue[21]) { /* constants */ + ( &(const bvalue[23]) { /* constants */ /* K0 */ be_nested_string("introspect", 164638290, 10), /* K1 */ be_nested_string("debug", 1483009432, 5), /* K2 */ be_nested_string("string", 398550328, 6), @@ -1467,24 +1572,26 @@ be_local_closure(event, /* name */ /* K4 */ be_nested_string("run_deferred", 371594696, 12), /* K5 */ be_nested_string("cmd", -158181397, 3), /* K6 */ be_nested_string("exec_cmd", 493567399, 8), - /* K7 */ be_nested_string("rule", -64077613, 4), - /* K8 */ be_nested_string("exec_rules", 1445221092, 10), - /* K9 */ be_nested_string("gc", 1042313471, 2), - /* K10 */ be_nested_string("_drivers", -1034638311, 8), - /* K11 */ be_const_int(0), - /* K12 */ be_nested_string("get", 1410115415, 3), - /* K13 */ be_nested_string("function", -1630125495, 8), - /* K14 */ be_nested_string("format", -1180859054, 6), - /* K15 */ be_nested_string("BRY: Exception> '%s' - %s", -2047976332, 25), - /* K16 */ be_nested_string("traceback", -909779187, 9), - /* K17 */ be_const_int(1), - /* K18 */ be_nested_string("save_before_restart", 1253239338, 19), - /* K19 */ be_nested_string("persist", -377883517, 7), - /* K20 */ be_nested_string("save", -855671224, 4), + /* K7 */ be_nested_string("tele", -820509235, 4), + /* K8 */ be_nested_string("exec_tele", 1020751601, 9), + /* K9 */ be_nested_string("rule", -64077613, 4), + /* K10 */ be_nested_string("exec_rules", 1445221092, 10), + /* K11 */ be_nested_string("gc", 1042313471, 2), + /* K12 */ be_nested_string("_drivers", -1034638311, 8), + /* K13 */ be_const_int(0), + /* K14 */ be_nested_string("get", 1410115415, 3), + /* K15 */ be_nested_string("function", -1630125495, 8), + /* K16 */ be_nested_string("format", -1180859054, 6), + /* K17 */ be_nested_string("BRY: Exception> '%s' - %s", -2047976332, 25), + /* K18 */ be_nested_string("traceback", -909779187, 9), + /* K19 */ be_const_int(1), + /* K20 */ be_nested_string("save_before_restart", 1253239338, 19), + /* K21 */ be_nested_string("persist", -377883517, 7), + /* K22 */ be_nested_string("save", -855671224, 4), }), (be_nested_const_str("event", -30355297, 5)), - (be_nested_const_str("input", -103256197, 5)), - ( &(const binstruction[84]) { /* code */ + (be_nested_const_str("tasmota.be", 1128870755, 10)), + ( &(const binstruction[91]) { /* code */ 0xA41A0000, // 0000 IMPORT R6 K0 0xA41E0200, // 0001 IMPORT R7 K1 0xA4220400, // 0002 IMPORT R8 K2 @@ -1501,74 +1608,81 @@ be_local_closure(event, /* name */ 0x5C380800, // 000D MOVE R14 R4 0x7C280800, // 000E CALL R10 4 0x80041400, // 000F RET 1 R10 - 0x7002003C, // 0010 JMP #004E + 0x70020043, // 0010 JMP #0055 0x1C280307, // 0011 EQ R10 R1 K7 0x782A0004, // 0012 JMPF R10 #0018 0x8C280108, // 0013 GETMET R10 R0 K8 0x5C300800, // 0014 MOVE R12 R4 0x7C280400, // 0015 CALL R10 2 0x80041400, // 0016 RET 1 R10 - 0x70020035, // 0017 JMP #004E + 0x7002003C, // 0017 JMP #0055 0x1C280309, // 0018 EQ R10 R1 K9 - 0x782A0003, // 0019 JMPF R10 #001E - 0x8C280109, // 001A GETMET R10 R0 K9 - 0x7C280200, // 001B CALL R10 1 - 0x80041400, // 001C RET 1 R10 - 0x7002002F, // 001D JMP #004E - 0x8828010A, // 001E GETMBR R10 R0 K10 - 0x782A002D, // 001F JMPF R10 #004E - 0x5828000B, // 0020 LDCONST R10 K11 - 0x602C000C, // 0021 GETGBL R11 G12 - 0x8830010A, // 0022 GETMBR R12 R0 K10 - 0x7C2C0200, // 0023 CALL R11 1 - 0x142C140B, // 0024 LT R11 R10 R11 - 0x782E0027, // 0025 JMPF R11 #004E - 0x882C010A, // 0026 GETMBR R11 R0 K10 - 0x942C160A, // 0027 GETIDX R11 R11 R10 - 0x8C300D0C, // 0028 GETMET R12 R6 K12 - 0x5C381600, // 0029 MOVE R14 R11 - 0x5C3C0200, // 002A MOVE R15 R1 - 0x7C300600, // 002B CALL R12 3 - 0x60340004, // 002C GETGBL R13 G4 - 0x5C381800, // 002D MOVE R14 R12 - 0x7C340200, // 002E CALL R13 1 - 0x1C341B0D, // 002F EQ R13 R13 K13 - 0x7836001A, // 0030 JMPF R13 #004C - 0xA802000C, // 0031 EXBLK 0 #003F - 0x5C341800, // 0032 MOVE R13 R12 - 0x5C381600, // 0033 MOVE R14 R11 - 0x5C3C0400, // 0034 MOVE R15 R2 - 0x5C400600, // 0035 MOVE R16 R3 - 0x5C440800, // 0036 MOVE R17 R4 - 0x5C480A00, // 0037 MOVE R18 R5 - 0x7C340A00, // 0038 CALL R13 5 - 0x5C241A00, // 0039 MOVE R9 R13 - 0x78260001, // 003A JMPF R9 #003D - 0xA8040001, // 003B EXBLK 1 1 - 0x70020010, // 003C JMP #004E - 0xA8040001, // 003D EXBLK 1 1 - 0x7002000C, // 003E JMP #004C - 0xAC340002, // 003F CATCH R13 0 2 - 0x70020009, // 0040 JMP #004B - 0x603C0001, // 0041 GETGBL R15 G1 - 0x8C40110E, // 0042 GETMET R16 R8 K14 - 0x5848000F, // 0043 LDCONST R18 K15 - 0x5C4C1A00, // 0044 MOVE R19 R13 - 0x5C501C00, // 0045 MOVE R20 R14 - 0x7C400800, // 0046 CALL R16 4 - 0x7C3C0200, // 0047 CALL R15 1 - 0x8C3C0F10, // 0048 GETMET R15 R7 K16 - 0x7C3C0200, // 0049 CALL R15 1 - 0x70020000, // 004A JMP #004C - 0xB0080000, // 004B RAISE 2 R0 R0 - 0x00281511, // 004C ADD R10 R10 K17 - 0x7001FFD2, // 004D JMP #0021 - 0x1C280312, // 004E EQ R10 R1 K18 - 0x782A0002, // 004F JMPF R10 #0053 - 0xA42A2600, // 0050 IMPORT R10 K19 - 0x8C2C1514, // 0051 GETMET R11 R10 K20 - 0x7C2C0200, // 0052 CALL R11 1 - 0x80041200, // 0053 RET 1 R9 + 0x782A0004, // 0019 JMPF R10 #001F + 0x8C28010A, // 001A GETMET R10 R0 K10 + 0x5C300800, // 001B MOVE R12 R4 + 0x7C280400, // 001C CALL R10 2 + 0x80041400, // 001D RET 1 R10 + 0x70020035, // 001E JMP #0055 + 0x1C28030B, // 001F EQ R10 R1 K11 + 0x782A0003, // 0020 JMPF R10 #0025 + 0x8C28010B, // 0021 GETMET R10 R0 K11 + 0x7C280200, // 0022 CALL R10 1 + 0x80041400, // 0023 RET 1 R10 + 0x7002002F, // 0024 JMP #0055 + 0x8828010C, // 0025 GETMBR R10 R0 K12 + 0x782A002D, // 0026 JMPF R10 #0055 + 0x5828000D, // 0027 LDCONST R10 K13 + 0x602C000C, // 0028 GETGBL R11 G12 + 0x8830010C, // 0029 GETMBR R12 R0 K12 + 0x7C2C0200, // 002A CALL R11 1 + 0x142C140B, // 002B LT R11 R10 R11 + 0x782E0027, // 002C JMPF R11 #0055 + 0x882C010C, // 002D GETMBR R11 R0 K12 + 0x942C160A, // 002E GETIDX R11 R11 R10 + 0x8C300D0E, // 002F GETMET R12 R6 K14 + 0x5C381600, // 0030 MOVE R14 R11 + 0x5C3C0200, // 0031 MOVE R15 R1 + 0x7C300600, // 0032 CALL R12 3 + 0x60340004, // 0033 GETGBL R13 G4 + 0x5C381800, // 0034 MOVE R14 R12 + 0x7C340200, // 0035 CALL R13 1 + 0x1C341B0F, // 0036 EQ R13 R13 K15 + 0x7836001A, // 0037 JMPF R13 #0053 + 0xA802000C, // 0038 EXBLK 0 #0046 + 0x5C341800, // 0039 MOVE R13 R12 + 0x5C381600, // 003A MOVE R14 R11 + 0x5C3C0400, // 003B MOVE R15 R2 + 0x5C400600, // 003C MOVE R16 R3 + 0x5C440800, // 003D MOVE R17 R4 + 0x5C480A00, // 003E MOVE R18 R5 + 0x7C340A00, // 003F CALL R13 5 + 0x5C241A00, // 0040 MOVE R9 R13 + 0x78260001, // 0041 JMPF R9 #0044 + 0xA8040001, // 0042 EXBLK 1 1 + 0x70020010, // 0043 JMP #0055 + 0xA8040001, // 0044 EXBLK 1 1 + 0x7002000C, // 0045 JMP #0053 + 0xAC340002, // 0046 CATCH R13 0 2 + 0x70020009, // 0047 JMP #0052 + 0x603C0001, // 0048 GETGBL R15 G1 + 0x8C401110, // 0049 GETMET R16 R8 K16 + 0x58480011, // 004A LDCONST R18 K17 + 0x5C4C1A00, // 004B MOVE R19 R13 + 0x5C501C00, // 004C MOVE R20 R14 + 0x7C400800, // 004D CALL R16 4 + 0x7C3C0200, // 004E CALL R15 1 + 0x8C3C0F12, // 004F GETMET R15 R7 K18 + 0x7C3C0200, // 0050 CALL R15 1 + 0x70020000, // 0051 JMP #0053 + 0xB0080000, // 0052 RAISE 2 R0 R0 + 0x00281513, // 0053 ADD R10 R10 K19 + 0x7001FFD2, // 0054 JMP #0028 + 0x1C280314, // 0055 EQ R10 R1 K20 + 0x782A0002, // 0056 JMPF R10 #005A + 0xA42A2A00, // 0057 IMPORT R10 K21 + 0x8C2C1516, // 0058 GETMET R11 R10 K22 + 0x7C2C0200, // 0059 CALL R11 1 + 0x80041200, // 005A RET 1 R9 }) ) ); @@ -1740,6 +1854,7 @@ class be_class_tasmota (scope: global, name: Tasmota) { remove_rule, closure(remove_rule_closure) try_rule, closure(try_rule_closure) exec_rules, closure(exec_rules_closure) + exec_tele, closure(exec_tele_closure) set_timer, closure(set_timer_closure) run_deferred, closure(run_deferred_closure) remove_timer, closure(remove_timer_closure) diff --git a/lib/libesp32/Berry/default/embedded/Tasmota.be b/lib/libesp32/Berry/default/embedded/Tasmota.be index da16cb212..d0ca48821 100644 --- a/lib/libesp32/Berry/default/embedded/Tasmota.be +++ b/lib/libesp32/Berry/default/embedded/Tasmota.be @@ -181,6 +181,28 @@ class Tasmota return false end + # Run tele rules + def exec_tele(ev_json) + if self._rules + import json + var ev = json.load(ev_json) # returns nil if invalid JSON + var ret = false + if ev == nil + self.log('BRY: ERROR, bad json: '+ev_json, 3) + ev = ev_json # revert to string + end + # insert tele prefix + ev = { "Tele": ev } + try + ret = self._rules.reduce( /k,v,r-> self.try_rule(ev,k,v) || r, nil, false) + except "stop_iteration" + # silence stop_iteration which means that the map was resized during iteration + end + return ret + end + return false + end + def set_timer(delay,f,id) if !self._timers self._timers=[] end self._timers.push(Timer(self.millis(delay),f,id)) @@ -329,6 +351,7 @@ class Tasmota var done = false if event_type=='cmd' return self.exec_cmd(cmd, idx, payload) + elif event_type=='tele' return self.exec_tele(payload) elif event_type=='rule' return self.exec_rules(payload) elif event_type=='gc' return self.gc() elif self._drivers diff --git a/lib/libesp32/Berry/generate/be_const_strtab.h b/lib/libesp32/Berry/generate/be_const_strtab.h index 6c7b7bf44..09f64285c 100644 --- a/lib/libesp32/Berry/generate/be_const_strtab.h +++ b/lib/libesp32/Berry/generate/be_const_strtab.h @@ -284,6 +284,7 @@ extern const bcstring be_const_str_save; extern const bcstring be_const_str_yield; extern const bcstring be_const_str_NONE; extern const bcstring be_const_str_TASMOTACLIENT_RST; +extern const bcstring be_const_str_exec_tele; extern const bcstring be_const_str_read24; extern const bcstring be_const_str_search; extern const bcstring be_const_str_web_send_decimal; diff --git a/lib/libesp32/Berry/generate/be_const_strtab_def.h b/lib/libesp32/Berry/generate/be_const_strtab_def.h index cbbc5a8bb..c0271b5d7 100644 --- a/lib/libesp32/Berry/generate/be_const_strtab_def.h +++ b/lib/libesp32/Berry/generate/be_const_strtab_def.h @@ -284,6 +284,7 @@ be_define_const_str(save, "save", 3439296072u, 0, 4, &be_const_str_yield); be_define_const_str(yield, "yield", 1821831854u, 0, 5, NULL); be_define_const_str(NONE, "NONE", 1932136219u, 0, 4, NULL); be_define_const_str(TASMOTACLIENT_RST, "TASMOTACLIENT_RST", 3326196213u, 0, 17, NULL); +be_define_const_str(exec_tele, "exec_tele", 1020751601u, 0, 9, &be_const_str_read24); be_define_const_str(read24, "read24", 1808533811u, 0, 6, &be_const_str_search); be_define_const_str(search, "search", 2150836393u, 0, 6, &be_const_str_web_send_decimal); be_define_const_str(web_send_decimal, "web_send_decimal", 1407210204u, 0, 16, NULL); @@ -733,7 +734,7 @@ static const bstring* const m_string_table[] = { (const bstring *)&be_const_str_add_driver, (const bstring *)&be_const_str_NONE, (const bstring *)&be_const_str_TASMOTACLIENT_RST, - (const bstring *)&be_const_str_read24, + (const bstring *)&be_const_str_exec_tele, (const bstring *)&be_const_str_IEM3000_RX, (const bstring *)&be_const_str_Tasmota, (const bstring *)&be_const_str_has_arg, @@ -893,6 +894,6 @@ static const bstring* const m_string_table[] = { static const struct bconststrtab m_const_string_table = { .size = 289, - .count = 578, + .count = 579, .table = m_string_table }; diff --git a/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h b/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h index 6d4bfdf08..bdd9ea780 100644 --- a/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h +++ b/lib/libesp32/Berry/generate/be_fixed_be_class_tasmota.h @@ -1,83 +1,84 @@ #include "be_constobj.h" static be_define_const_map_slots(be_class_tasmota_map) { - { be_const_key(save, -1), be_const_func(l_save) }, - { be_const_key(_drivers, -1), be_const_var(0) }, - { be_const_key(millis, -1), be_const_func(l_millis) }, - { be_const_key(resp_cmnd_done, 57), be_const_func(l_respCmndDone) }, - { be_const_key(settings, 42), be_const_var(1) }, - { be_const_key(time_reached, 6), be_const_func(l_timereached) }, - { be_const_key(try_rule, 46), be_const_closure(try_rule_closure) }, - { be_const_key(resp_cmnd_error, 69), be_const_func(l_respCmndError) }, - { be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) }, - { be_const_key(get_power, 19), be_const_func(l_getpower) }, - { be_const_key(eth, -1), be_const_func(l_eth) }, - { be_const_key(time_dump, 28), be_const_func(l_time_dump) }, - { be_const_key(web_send_decimal, 61), be_const_func(l_webSendDecimal) }, - { be_const_key(set_timer, -1), be_const_closure(set_timer_closure) }, - { be_const_key(global, 67), be_const_var(2) }, - { be_const_key(event, -1), be_const_closure(event_closure) }, - { be_const_key(remove_driver, 4), be_const_closure(remove_driver_closure) }, - { be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) }, - { be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) }, - { be_const_key(log, -1), be_const_func(l_logInfo) }, - { be_const_key(time_str, -1), be_const_closure(time_str_closure) }, - { be_const_key(resolvecmnd, 65), be_const_func(l_resolveCmnd) }, - { be_const_key(wire2, -1), be_const_var(3) }, - { be_const_key(wifi, -1), be_const_func(l_wifi) }, - { be_const_key(response_append, 36), be_const_func(l_respAppend) }, - { be_const_key(_rules, -1), be_const_var(4) }, - { be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) }, - { be_const_key(web_send, -1), be_const_func(l_webSend) }, - { be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) }, - { be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) }, - { be_const_key(resp_cmnd_str, 44), be_const_func(l_respCmndStr) }, - { be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) }, - { be_const_key(publish, 17), be_const_func(l_publish) }, - { be_const_key(_global_def, 41), be_const_comptr(&be_tasmota_global_struct) }, - { be_const_key(_get_cb, -1), be_const_func(l_get_cb) }, - { be_const_key(add_driver, -1), be_const_closure(add_driver_closure) }, - { be_const_key(init, -1), be_const_closure(init_closure) }, - { be_const_key(get_light, -1), be_const_closure(get_light_closure) }, - { be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) }, - { be_const_key(_cb, 2), be_const_var(5) }, - { be_const_key(find_op, 27), be_const_closure(find_op_closure) }, - { be_const_key(get_option, -1), be_const_func(l_getoption) }, - { be_const_key(rtc, -1), be_const_func(l_rtc) }, - { be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) }, - { be_const_key(memory, -1), be_const_func(l_memory) }, - { be_const_key(_ccmd, -1), be_const_var(6) }, - { be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) }, - { be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) }, - { be_const_key(delay, 23), be_const_func(l_delay) }, - { be_const_key(_global_addr, 53), be_const_comptr(&TasmotaGlobal) }, - { be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) }, - { be_const_key(cmd, 24), be_const_closure(cmd_closure) }, - { be_const_key(_timers, 10), be_const_var(7) }, - { be_const_key(load, -1), be_const_closure(load_closure) }, - { be_const_key(_cmd, -1), be_const_func(l_cmd) }, - { be_const_key(exec_cmd, 50), be_const_closure(exec_cmd_closure) }, - { be_const_key(set_light, -1), be_const_closure(set_light_closure) }, - { be_const_key(strftime, -1), be_const_func(l_strftime) }, - { be_const_key(cmd_res, -1), be_const_var(8) }, - { be_const_key(wire1, 11), be_const_var(9) }, - { be_const_key(publish_result, 47), be_const_func(l_publish_result) }, - { be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) }, - { be_const_key(scale_uint, -1), be_const_func(l_scaleuint) }, - { be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) }, - { be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) }, + { be_const_key(add_rule, 52), be_const_closure(add_rule_closure) }, + { be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) }, + { be_const_key(web_send, 14), be_const_func(l_webSend) }, + { be_const_key(settings, -1), be_const_var(0) }, { be_const_key(set_power, -1), be_const_func(l_setpower) }, - { be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) }, - { be_const_key(yield, -1), be_const_func(l_yield) }, - { be_const_key(get_switch, 37), be_const_func(l_getswitch) }, - { be_const_key(add_rule, -1), be_const_closure(add_rule_closure) }, - { be_const_key(remove_cmd, 26), be_const_closure(remove_cmd_closure) }, + { be_const_key(add_cmd, -1), be_const_closure(add_cmd_closure) }, + { be_const_key(publish, 13), be_const_func(l_publish) }, + { be_const_key(remove_timer, -1), be_const_closure(remove_timer_closure) }, + { be_const_key(resp_cmnd, 55), be_const_func(l_respCmnd) }, + { be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) }, + { be_const_key(time_reached, 38), be_const_func(l_timereached) }, + { be_const_key(resp_cmnd_error, 3), be_const_func(l_respCmndError) }, + { be_const_key(init, -1), be_const_closure(init_closure) }, + { be_const_key(eth, 35), be_const_func(l_eth) }, + { be_const_key(time_dump, -1), be_const_func(l_time_dump) }, + { be_const_key(_rules, 29), be_const_var(1) }, + { be_const_key(millis, 41), be_const_func(l_millis) }, + { be_const_key(get_option, -1), be_const_func(l_getoption) }, + { be_const_key(exec_cmd, 49), be_const_closure(exec_cmd_closure) }, + { be_const_key(_cb, -1), be_const_var(2) }, + { be_const_key(wire_scan, -1), be_const_closure(wire_scan_closure) }, + { be_const_key(response_append, 58), be_const_func(l_respAppend) }, + { be_const_key(add_driver, 44), be_const_closure(add_driver_closure) }, + { be_const_key(find_key_i, 28), be_const_closure(find_key_i_closure) }, + { be_const_key(remove_driver, 34), be_const_closure(remove_driver_closure) }, + { be_const_key(get_power, -1), be_const_func(l_getpower) }, + { be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) }, + { be_const_key(find_op, 21), be_const_closure(find_op_closure) }, + { be_const_key(resolvecmnd, -1), be_const_func(l_resolveCmnd) }, + { be_const_key(cb_dispatch, 40), be_const_closure(cb_dispatch_closure) }, + { be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) }, + { be_const_key(log, -1), be_const_func(l_logInfo) }, + { be_const_key(cmd_res, 45), be_const_var(3) }, + { be_const_key(wire1, 43), be_const_var(4) }, + { be_const_key(get_light, -1), be_const_closure(get_light_closure) }, + { be_const_key(strftime, -1), be_const_func(l_strftime) }, + { be_const_key(set_light, -1), be_const_closure(set_light_closure) }, + { be_const_key(global, -1), be_const_var(5) }, + { be_const_key(publish_result, -1), be_const_func(l_publish_result) }, + { be_const_key(cmd, -1), be_const_closure(cmd_closure) }, + { be_const_key(_settings_def, 46), be_const_comptr(&be_tasmota_settings_struct) }, + { be_const_key(load, -1), be_const_closure(load_closure) }, + { be_const_key(resp_cmnd_done, 23), be_const_func(l_respCmndDone) }, + { be_const_key(event, 25), be_const_closure(event_closure) }, + { be_const_key(run_deferred, 57), be_const_closure(run_deferred_closure) }, + { be_const_key(_ccmd, -1), be_const_var(6) }, + { be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) }, + { be_const_key(exec_tele, -1), be_const_closure(exec_tele_closure) }, + { be_const_key(remove_rule, 63), be_const_closure(remove_rule_closure) }, + { be_const_key(_get_cb, -1), be_const_func(l_get_cb) }, + { be_const_key(try_rule, -1), be_const_closure(try_rule_closure) }, + { be_const_key(time_str, -1), be_const_closure(time_str_closure) }, + { be_const_key(scale_uint, -1), be_const_func(l_scaleuint) }, { be_const_key(gc, -1), be_const_closure(gc_closure) }, + { be_const_key(yield, -1), be_const_func(l_yield) }, + { be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) }, + { be_const_key(_timers, 32), be_const_var(7) }, + { be_const_key(get_switch, -1), be_const_func(l_getswitch) }, + { be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) }, + { be_const_key(memory, -1), be_const_func(l_memory) }, + { be_const_key(save, 9), be_const_func(l_save) }, + { be_const_key(_settings_ptr, 26), be_const_comptr(&Settings) }, + { be_const_key(wire2, -1), be_const_var(8) }, + { be_const_key(_cmd, -1), be_const_func(l_cmd) }, + { be_const_key(set_timer, -1), be_const_closure(set_timer_closure) }, + { be_const_key(_drivers, 1), be_const_var(9) }, + { be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) }, + { be_const_key(rtc, -1), be_const_func(l_rtc) }, + { be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) }, + { be_const_key(wifi, -1), be_const_func(l_wifi) }, + { be_const_key(delay, -1), be_const_func(l_delay) }, + { be_const_key(_global_def, 37), be_const_comptr(&be_tasmota_global_struct) }, + { be_const_key(resp_cmnd_failed, 39), be_const_func(l_respCmndFailed) }, }; static be_define_const_map( be_class_tasmota_map, - 72 + 73 ); BE_EXPORT_VARIABLE be_define_const_class( diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index b6dd01d4c..16ab3db18 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -806,7 +806,7 @@ bool RulesProcessEvent(const char *json_event) { #ifdef USE_BERRY // events are passed to Berry before Rules engine - callBerryRule(json_event); + callBerryRule(json_event, Rules.teleperiod); #endif if (Rules.busy) { return false; } diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 2eaf1be0b..b210ac446 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -95,12 +95,12 @@ extern "C" { // // call a function (if exists) of type void -> void // If event == nullptr, then take XdrvMailbox.data -bool callBerryRule(const char *event) { +bool callBerryRule(const char *event, bool teleperiod) { if (berry.rules_busy) { return false; } berry.rules_busy = true; char * json_event = XdrvMailbox.data; bool serviced = false; - serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, event ? event : XdrvMailbox.data); + serviced = callBerryEventDispatcher(teleperiod ? "tele" : "rule", nullptr, 0, event ? event : XdrvMailbox.data); berry.rules_busy = false; return serviced; // TODO event not handled } @@ -760,7 +760,10 @@ bool Xdrv52(uint8_t function) // Berry wide commands and events case FUNC_RULES_PROCESS: - result = callBerryRule(nullptr); + result = callBerryRule(nullptr, false); + break; + case FUNC_TELEPERIOD_RULES_PROCESS: + result = callBerryRule(nullptr, true); break; case FUNC_MQTT_DATA: result = callBerryEventDispatcher(PSTR("mqtt_data"), XdrvMailbox.topic, 0, XdrvMailbox.data, XdrvMailbox.data_len);