Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MI32 legacy: add config operations for Berry #22458

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/libesp32_div/esp-nimble-cpp/src/NimBLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,13 @@ int NimBLEDevice::getPower() {
*/
/* STATIC*/
NimBLEAddress NimBLEDevice::getAddress() {
ble_addr_t addr = {BLE_ADDR_PUBLIC, 0};
ble_addr_t addr = {m_own_addr_type, 0};

if(BLE_HS_ENOADDR == ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, addr.val, NULL)) {
NIMBLE_LOGD(LOG_TAG, "Public address not found, checking random");
addr.type = BLE_ADDR_RANDOM;
ble_hs_id_copy_addr(BLE_ADDR_RANDOM, addr.val, NULL);
if(BLE_HS_ENOADDR == ble_hs_id_copy_addr(m_own_addr_type, addr.val, NULL)) {
// NIMBLE_LOGD(LOG_TAG, "Public address not found, checking random");
// addr.type = BLE_ADDR_RANDOM;
// ble_hs_id_copy_addr(BLE_ADDR_RANDOM, addr.val, NULL);
return NimBLEAddress(); // return blank to report error
}

return NimBLEAddress(addr);
Expand Down
44 changes: 44 additions & 0 deletions tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <t_bearssl.h>

#include "include/xsns_62_esp32_mi.h"
#include "services/gap/ble_svc_gap.h"

void MI32notifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
void MI32AddKey(mi_bindKey_t keyMAC);
Expand Down Expand Up @@ -732,7 +733,50 @@ extern "C" {
MI32BLELoop();
}

bool MI32runBerryConfig(uint16_t operation){
bool success = false;
#ifdef CONFIG_BT_NIMBLE_EXT_ADV
NimBLEExtAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
#else
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
#endif
if(pAdvertising == nullptr){
return success;
}
switch(operation){
case 231: // set address
pAdvertising->stop();
if(MI32.conCtx->addrType > 0){
ble_hs_id_set_rnd(MI32.conCtx->MAC);
AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: set MAC to random"));
}
NimBLEDevice::setOwnAddrType(MI32.conCtx->addrType);
success = true;
break;
case 232: // set adv params via bytes() descriptor of size 5,
if(MI32.conCtx->buffer[0] == 5){
uint16_t itvl_min = MI32.conCtx->buffer[2] + (MI32.conCtx->buffer[3] << 8);
uint16_t itvl_max = MI32.conCtx->buffer[4] + (MI32.conCtx->buffer[5] << 8);
pAdvertising->setAdvertisementType(MI32.conCtx->buffer[1]);
pAdvertising->setMinInterval(itvl_min);
pAdvertising->setMaxInterval(itvl_max);
AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: adv params: type: %u, min: %u, max: %u"),MI32.conCtx->buffer[1], (uint16_t)(itvl_min * 0.625), (uint16_t)(itvl_max * 0.625)) ;
success = true;
}
break;
case 233:
int ret = ble_svc_gap_device_name_set((const char*)MI32.conCtx->buffer + 1);
AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: new gap device name - %s"),(const char*) MI32.conCtx->buffer + 1);
success = (ret == 0);
break;
}
return success;
}

bool MI32runBerryServer(uint16_t operation){
if(operation > 230){
return MI32runBerryConfig(operation);
}
MI32.conCtx->operation = operation;
AddLog(LOG_LEVEL_DEBUG,PSTR("BLE: Berry server op: %d, response: %u"),MI32.conCtx->operation, MI32.conCtx->response);
if(MI32.mode.readyForNextServerJob == 0){
Expand Down