Merge pull request #12711 from s-hadinger/berry_publish_result

Berry add tasmota.publish_result
This commit is contained in:
s-hadinger 2021-07-21 09:00:04 +02:00 committed by GitHub
commit 4fb8f679d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1673 additions and 1650 deletions

View File

@ -7,6 +7,7 @@
extern int l_getFreeHeap(bvm *vm); extern int l_getFreeHeap(bvm *vm);
extern int l_publish(bvm *vm); extern int l_publish(bvm *vm);
extern int l_publish_result(bvm *vm);
extern int l_cmd(bvm *vm); extern int l_cmd(bvm *vm);
extern int l_get_cb(bvm *vm); extern int l_get_cb(bvm *vm);
extern int l_getoption(bvm *vm); extern int l_getoption(bvm *vm);
@ -2304,6 +2305,7 @@ void be_load_tasmota_ntvlib(bvm *vm)
{ "wire2", NULL }, { "wire2", NULL },
{ "get_free_heap", l_getFreeHeap }, { "get_free_heap", l_getFreeHeap },
{ "publish", l_publish }, { "publish", l_publish },
{ "publish_result", l_publish_result },
{ "_cmd", l_cmd }, { "_cmd", l_cmd },
{ "_get_cb", l_get_cb }, { "_get_cb", l_get_cb },
{ "get_option", l_getoption }, { "get_option", l_getoption },
@ -2385,6 +2387,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
get_free_heap, func(l_getFreeHeap) get_free_heap, func(l_getFreeHeap)
publish, func(l_publish) publish, func(l_publish)
publish_result, func(l_publish_result)
_cmd, func(l_cmd) _cmd, func(l_cmd)
_get_cb, func(l_get_cb) _get_cb, func(l_get_cb)
get_option, func(l_getoption) get_option, func(l_getoption)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,68 +1,69 @@
#include "be_constobj.h" #include "be_constobj.h"
static be_define_const_map_slots(be_class_tasmota_map) { static be_define_const_map_slots(be_class_tasmota_map) {
{ be_const_key(millis, 52), be_const_func(l_millis) }, { be_const_key(publish, -1), be_const_func(l_publish) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) }, { be_const_key(wire2, -1), be_const_index(0) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) }, { be_const_key(yield, 14), be_const_func(l_yield) },
{ be_const_key(log, -1), be_const_func(l_logInfo) }, { be_const_key(log, 34), be_const_func(l_logInfo) },
{ be_const_key(add_rule, -1), be_const_closure(add_rule_closure) }, { be_const_key(find_op, -1), be_const_closure(find_op_closure) },
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) }, { be_const_key(i2c_enabled, 24), be_const_func(l_i2cenabled) },
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) },
{ be_const_key(_cmd, -1), be_const_func(l_cmd) }, { be_const_key(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(web_send, 16), be_const_func(l_webSend) }, { be_const_key(save, 30), be_const_func(l_save) },
{ be_const_key(set_timer, -1), be_const_closure(set_timer_closure) }, { be_const_key(resolvecmnd, 51), be_const_func(l_resolveCmnd) },
{ be_const_key(_cb, -1), be_const_index(0) }, { be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) }, { be_const_key(_ccmd, -1), be_const_index(1) },
{ be_const_key(i2c_enabled, 42), be_const_func(l_i2cenabled) },
{ be_const_key(cmd, -1), be_const_closure(cmd_closure) },
{ be_const_key(resp_cmnd_done, 28), be_const_func(l_respCmndDone) },
{ be_const_key(set_light, 1), be_const_closure(set_light_closure) },
{ be_const_key(get_light, -1), be_const_closure(get_light_closure) }, { be_const_key(get_light, -1), be_const_closure(get_light_closure) },
{ be_const_key(_rules, 50), be_const_index(1) }, { be_const_key(add_rule, 56), be_const_closure(add_rule_closure) },
{ be_const_key(time_reached, -1), be_const_func(l_timereached) }, { be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) }, { be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(load, 22), be_const_closure(load_closure) }, { be_const_key(_get_cb, -1), be_const_func(l_get_cb) },
{ be_const_key(yield, -1), be_const_func(l_yield) }, { be_const_key(_cb, -1), be_const_index(2) },
{ be_const_key(event, -1), be_const_closure(event_closure) }, { be_const_key(time_str, -1), be_const_closure(time_str_closure) },
{ be_const_key(add_cmd, 40), be_const_closure(add_cmd_closure) }, { be_const_key(add_driver, 21), be_const_closure(add_driver_closure) },
{ be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) }, { be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
{ be_const_key(delay, 43), be_const_func(l_delay) }, { be_const_key(_rules, -1), be_const_index(3) },
{ be_const_key(remove_cmd, -1), be_const_closure(remove_cmd_closure) }, { be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(remove_rule, 56), be_const_closure(remove_rule_closure) }, { be_const_key(set_light, -1), be_const_closure(set_light_closure) },
{ be_const_key(resolvecmnd, 29), be_const_func(l_resolveCmnd) }, { be_const_key(add_cmd, 25), be_const_closure(add_cmd_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) }, { be_const_key(event, 49), be_const_closure(event_closure) },
{ be_const_key(scale_uint, -1), be_const_func(l_scaleuint) },
{ be_const_key(millis, -1), be_const_func(l_millis) },
{ be_const_key(remove_rule, -1), be_const_closure(remove_rule_closure) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(_timers, -1), be_const_index(4) },
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) }, { be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
{ be_const_key(response_append, -1), be_const_func(l_respAppend) }, { be_const_key(response_append, -1), be_const_func(l_respAppend) },
{ be_const_key(_timers, -1), be_const_index(2) }, { be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(try_rule, -1), be_const_closure(try_rule_closure) }, { be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(set_power, 45), be_const_func(l_setpower) }, { be_const_key(wire1, 32), be_const_index(5) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) }, { be_const_key(web_send, 29), be_const_func(l_webSend) },
{ be_const_key(publish, -1), be_const_func(l_publish) }, { be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
{ be_const_key(_ccmd, 13), be_const_index(3) }, { be_const_key(remove_cmd, 23), be_const_closure(remove_cmd_closure) },
{ be_const_key(_get_cb, -1), be_const_func(l_get_cb) }, { be_const_key(try_rule, 46), be_const_closure(try_rule_closure) },
{ be_const_key(wire1, 15), be_const_index(4) }, { be_const_key(wire_scan, 31), be_const_closure(wire_scan_closure) },
{ be_const_key(gen_cb, 6), be_const_closure(gen_cb_closure) }, { be_const_key(_drivers, 15), be_const_index(6) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) }, { be_const_key(resp_cmnd_failed, 7), be_const_func(l_respCmndFailed) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) }, { be_const_key(exec_cmd, -1), be_const_closure(exec_cmd_closure) },
{ be_const_key(run_deferred, -1), be_const_closure(run_deferred_closure) }, { be_const_key(find_key_i, -1), be_const_closure(find_key_i_closure) },
{ be_const_key(memory, 47), be_const_func(l_memory) }, { be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
{ be_const_key(time_str, 53), be_const_closure(time_str_closure) }, { be_const_key(load, -1), be_const_closure(load_closure) },
{ be_const_key(save, -1), be_const_func(l_save) }, { be_const_key(cmd, -1), be_const_closure(cmd_closure) },
{ be_const_key(find_op, 25), be_const_closure(find_op_closure) }, { be_const_key(resp_cmnd, 20), be_const_func(l_respCmnd) },
{ be_const_key(chars_in_string, -1), be_const_closure(chars_in_string_closure) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(wire2, 8), be_const_index(5) },
{ be_const_key(wire_scan, 55), be_const_closure(wire_scan_closure) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(exec_rules, -1), be_const_closure(exec_rules_closure) },
{ be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) }, { be_const_key(cb_dispatch, -1), be_const_closure(cb_dispatch_closure) },
{ be_const_key(resp_cmnd, -1), be_const_func(l_respCmnd) }, { be_const_key(set_timer, -1), be_const_closure(set_timer_closure) },
{ be_const_key(_drivers, -1), be_const_index(6) }, { be_const_key(gen_cb, -1), be_const_closure(gen_cb_closure) },
{ be_const_key(add_driver, -1), be_const_closure(add_driver_closure) }, { be_const_key(web_send_decimal, 1), be_const_func(l_webSendDecimal) },
{ be_const_key(gc, -1), be_const_closure(gc_closure) },
{ be_const_key(delay, -1), be_const_func(l_delay) },
{ be_const_key(time_dump, 50), be_const_func(l_time_dump) },
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
{ be_const_key(resp_cmnd_error, -1), be_const_func(l_respCmndError) },
}; };
static be_define_const_map( static be_define_const_map(
be_class_tasmota_map, be_class_tasmota_map,
57 58
); );
BE_EXPORT_VARIABLE be_define_const_class( BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -87,6 +87,22 @@ extern "C" {
} }
be_raise(vm, kTypeError, nullptr); be_raise(vm, kTypeError, nullptr);
} }
// Berry: `tasmota.publish_result(payload:string, subtopic:string) -> nil``
//
int32_t l_publish_result(struct bvm *vm);
int32_t l_publish_result(struct bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 3 && be_isstring(vm, 2) && be_isstring(vm, 3)) { // 2 mandatory string arguments
const char * payload = be_tostring(vm, 2);
const char * subtopic = be_tostring(vm, 3);
Response_P(PSTR("%s"), payload);
be_pop(vm, top);
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, subtopic);
be_return_nil(vm); // Return
}
be_raise(vm, kTypeError, nullptr);
}
// Berry: `tasmota.cmd(command:string) -> string` // Berry: `tasmota.cmd(command:string) -> string`
// //