diff --git a/lib/libesp32/berry_tasmota/src/be_MI32_lib.c b/lib/libesp32/berry_tasmota/src/be_MI32_lib.c index 3cddb77dc..5078de941 100644 --- a/lib/libesp32/berry_tasmota/src/be_MI32_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_MI32_lib.c @@ -46,6 +46,8 @@ module MI32 (scope: global) { extern int be_BLE_init(bvm *vm); +extern int be_BLE_info(bvm *vm); + extern void be_BLE_loop(void); BE_FUNC_CTYPE_DECLARE(be_BLE_loop, "", ""); @@ -83,6 +85,7 @@ BE_FUNC_CTYPE_DECLARE(be_BLE_adv_block, "", "@(bytes)~[i]"); module BLE (scope: global) { init, func(be_BLE_init) loop, ctype_func(be_BLE_loop) + info, func(be_BLE_info) conn_cb, ctype_func(be_BLE_reg_conn_cb) set_svc, ctype_func(be_BLE_set_service) run, ctype_func(be_BLE_run) diff --git a/tasmota/include/xsns_62_esp32_mi.h b/tasmota/include/xsns_62_esp32_mi.h index 2b9ec9e99..2d010270d 100644 --- a/tasmota/include/xsns_62_esp32_mi.h +++ b/tasmota/include/xsns_62_esp32_mi.h @@ -18,6 +18,11 @@ */ #ifdef USE_MI_ESP32 + +#pragma once + +#include + /*********************************************************************************************\ * structs and types \*********************************************************************************************/ diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino index eab484c2b..b836b7c3b 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino @@ -24,6 +24,8 @@ #if defined(USE_MI_ESP32) && !defined(USE_BLE_ESP32) +#include "include/xsns_62_esp32_mi.h" + /*********************************************************************************************\ * Native functions mapped to Berry functions * @@ -206,6 +208,48 @@ extern "C" { be_raisef(vm, "ble_error", "BLE: could not add MAC to watch list"); } + // BLE.info(void) -> map + int32_t be_BLE_info(struct bvm *vm); + int32_t be_BLE_info(struct bvm *vm) { + be_newobject(vm, "map"); + char _Role[16]; + GetTextIndexed(_Role, sizeof(_Role), MI32.role, HTTP_MI32_PARENT_BLE_ROLE); + char _role[16]; + LowerCase(_role,_Role); + be_map_insert_str(vm, "role", _role); + be_map_insert_str(vm, "local_addr", NimBLEDevice::toString().c_str()); + be_map_insert_int(vm, "power", NimBLEDevice::getPower()); + be_map_insert_int(vm, "MTU", NimBLEDevice::getMTU()); +#ifdef CONFIG_BT_NIMBLE_EXT_ADV // TODO - BLE 5 is very unsharp + be_map_insert_int(vm, "version", 5); +#else + be_map_insert_int(vm, "version", 4); +#endif +#ifdef CONFIG_BT_NIMBLE_PERSIST + be_map_insert_int(vm, "bonds", NimBLEDevice::getNumBonds()); +#else + be_map_insert_nil(vm, "bonds"); +#endif + if(MI32.mode.connected == 1){ + be_pushstring(vm, "connection"); + be_newobject(vm, "map"); + auto _info = NimBLEDevice::getClientList()->front()->getConnInfo(); + be_map_insert_str(vm, "peer_addr", _info.getAddress().toString().c_str()); + be_map_insert_int(vm, "RSSI", NimBLEDevice::getClientList()->front()->getRssi()); + be_map_insert_int(vm, "MTU", _info.getMTU()); + be_map_insert_bool(vm, "bonded", _info.isBonded()); + be_map_insert_bool(vm, "master", _info.isMaster()); + be_map_insert_bool(vm, "encrypted", _info.isEncrypted()); + be_map_insert_bool(vm, "authenticated", _info.isAuthenticated()); + + be_pop(vm, 1); + be_data_insert(vm, -3); + be_pop(vm, 2); + } + + be_pop(vm, 1); + be_return(vm); + } } //extern "C" diff --git a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino index 1dfa9d217..40878f001 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino @@ -60,7 +60,6 @@ #define XSNS_62 62 -#include // undefine "trash" from the NimBLE stack, that collides with Tasmotas enum #undef LOG_LEVEL_DEBUG #undef LOG_LEVEL_NONE