Merge pull request #12744 from s-hadinger/berry_wifi_eth

Berry add ``tasmota.wifi()`` and ``tasmota.eth()``
This commit is contained in:
Theo Arends 2021-07-25 14:51:06 +02:00 committed by GitHub
commit 547e95b2f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1723 additions and 1662 deletions

View File

@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- Support for CAN bus and Freedom Won Battery Management System by Marius Bezuidenhout (#12651)
- Berry ESP32 support for I2S audio mp3 playback
- Berry add module ``introspect``
- Berry add ``tasmota.wifi()`` and ``tasmota.eth()``
### Changed
- ESP32 core library from v1.0.7.1 to v1.0.7.3

View File

@ -16,6 +16,8 @@ extern int l_timereached(bvm *vm);
extern int l_rtc(bvm *vm);
extern int l_time_dump(bvm *vm);
extern int l_memory(bvm *vm);
extern int l_wifi(bvm *vm);
extern int l_eth(bvm *vm);
extern int l_yield(bvm *vm);
extern int l_delay(bvm *vm);
extern int l_scaleuint(bvm *vm);
@ -2304,6 +2306,8 @@ void be_load_tasmota_ntvlib(bvm *vm)
{ "rtc", l_rtc },
{ "time_dump", l_time_dump },
{ "memory", l_memory },
{ "wifi", l_wifi },
{ "eth", l_eth },
{ "yield", l_yield },
{ "delay", l_delay },
{ "scale_uint", l_scaleuint },
@ -2386,6 +2390,8 @@ class be_class_tasmota (scope: global, name: Tasmota) {
rtc, func(l_rtc)
time_dump, func(l_time_dump)
memory, func(l_memory)
wifi, func(l_wifi)
eth, func(l_eth)
yield, func(l_yield)
delay, func(l_delay)
scale_uint, func(l_scaleuint)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -184,7 +184,7 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}
// Berry: tasmota.memory(timer:int) -> bool
// Berry: tasmota.memory() -> map
//
int32_t l_memory(struct bvm *vm);
int32_t l_memory(struct bvm *vm) {
@ -207,6 +207,53 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}
// Berry: tasmota.wifi() -> map
//
int32_t l_wifi(struct bvm *vm);
int32_t l_wifi(struct bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top == 1) { // no argument (instance only)
be_newobject(vm, "map");
if (Settings->flag4.network_wifi) {
int32_t rssi = WiFi.RSSI();
map_insert_int(vm, "rssi", rssi);
map_insert_int(vm, "quality", WifiGetRssiAsQuality(rssi));
#if LWIP_IPV6
String ipv6_addr = WifiGetIPv6();
if (ipv6_addr != "") {
map_insert_str(vm, "ip6", ipv6_addr.c_str());
}
#endif
if (static_cast<uint32_t>(WiFi.localIP()) != 0) {
map_insert_str(vm, "mac", WiFi.macAddress().c_str());
map_insert_str(vm, "ip", WiFi.localIP().toString().c_str());
}
}
be_pop(vm, 1);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}
// Berry: tasmota.eth() -> map
//
int32_t l_eth(struct bvm *vm);
int32_t l_eth(struct bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top == 1) { // no argument (instance only)
be_newobject(vm, "map");
#ifdef USE_ETHERNET
if (static_cast<uint32_t>(EthernetLocalIP()) != 0) {
map_insert_str(vm, "mac", EthernetMacAddress().c_str());
map_insert_str(vm, "ip", EthernetLocalIP().toString().c_str());
}
#endif
be_pop(vm, 1);
be_return(vm);
}
be_raise(vm, kTypeError, nullptr);
}
int32_t l_time_dump(bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top == 2 && be_isint(vm, 2)) {