Controlling Philips Hue lamp

Thanks, would you mind trying again with monitor_filters = esp32_exception_decoder added to your environment so I can see the backtrace decode info?

I have to thank you for bearing with me.
Here’s the result

E: Failed to secure connection to aa:bb:cc:dd:ee:ff
CORRUPT HEAP: Bad head at 0x3ffe8034. Expected 0xabba1234 got 0x3f405e88
abort() was called at PC 0x40087155 on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x4008fac4:0x3ffe7b30 0x4008fd41:0x3ffe7b50 0x40087155:0x3ffe7b70 0x40087281:0x3ffe7ba0 0x4013d293:0x3ffe7bc0 0x4013693d:0x3ffe7e80 0x401368ad:0x3ffe7ed0 0x40094975:0x3ffe7f00 0x40081f26:0x3ffe7f20 0x4008704d:0x3ffe7f40 0x4000bec7:0x3ffe7f60 0x401c1329:0x3ffe7f80 0x400d2605:0x3ffe7fa0 0x400f9e85:0x3ffe7fc0 0x400fad69:0x3ffe7fe0 0x400dafdd:0x3ffe8010 0x400db471:0x3ffe8090 0x40090d52:0x3ffe8100
  #0  0x4008fac4:0x3ffe7b30 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #1  0x4008fd41:0x3ffe7b50 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #2  0x40087155:0x3ffe7b70 in lock_acquire_generic at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/locks.c:143
  #3  0x40087281:0x3ffe7ba0 in _lock_acquire_recursive at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/locks.c:171
  #4  0x4013d293:0x3ffe7bc0 in _vfiprintf_r at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/vfprintf.c:860 (discriminator 2)
  #5  0x4013693d:0x3ffe7e80 in fiprintf at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdio/../../../.././newlib/libc/stdio/fiprintf.c:50
  #6  0x401368ad:0x3ffe7ed0 in __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/stdlib/../../../.././newlib/libc/stdlib/assert.c:59 (discriminator 8)
  #7  0x40094975:0x3ffe7f00 in multi_heap_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c:321
  #8  0x40081f26:0x3ffe7f20 in heap_caps_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:232
  #9  0x4008704d:0x3ffe7f40 in _free_r at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/syscalls.c:42
  #10 0x4000bec7:0x3ffe7f60 in ?? ??:0
  #11 0x401c1329:0x3ffe7f80 in operator delete(void*) at /builds/idf/crosstool-NG/.build/src/gcc-5.2.0/libstdc++-v3/libsupc++/del_op.cc:46
  #12 0x400d2605:0x3ffe7fa0 in ClientCallbacks::~ClientCallbacks() at main/ZmqttDiscovery.ino:189
  #13 0x400f9e85:0x3ffe7fc0 in NimBLEClient::~NimBLEClient() at .pio/libdeps/esp32dev-ble/NimBLE-Arduino/src/NimBLEClient.cpp:451
  #14 0x400fad69:0x3ffe7fe0 in NimBLEDevice::deleteClient(NimBLEClient*) at .pio/libdeps/esp32dev-ble/NimBLE-Arduino/src/NimBLEDevice.cpp:632
  #15 0x400dafdd:0x3ffe8010 in zBLEConnect::~zBLEConnect() at main/ZmqttDiscovery.ino:189
      (inlined by) GENERIC_connect::~GENERIC_connect() at main/ZgatewayBLEConnect.h:62
      (inlined by) BLEconnect() at main/ZgatewayBT.ino:552
  #16 0x400db471:0x3ffe8090 in immediateBTAction(void*) at main/ZmqttDiscovery.ino:189
  #17 0x40090d52:0x3ffe8100 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

No worries, thanks for the help testing this.

I see the problem, should have it fixed in a few minutes.

Fix applied, feel free to test again when you get a chance.

I just realized that I need to add a security capability type to this, which is why the connection security will fail.

Ok, anyway it is not crashing anymore:

N: [ MQTT->OMG ]: {"ble_write_address":"AA:BB:CC:DD:EE:FF","mac_type":1,"ble_write_service":"932c32bd-0000-47a2-835a-a8d455b859dd","ble_write_char":"932c32bd-0002-47a2-835a-a8d455b859dd","ble_write_value":"01","value_type":"HEX","ttl":4,"immediate":true,"secure":true}
N: BLE Connect begin
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
N: Send on /BTtoMQTT/AABBCCDDEEFF msg {"id":"AA:BB:CC:DD:EE:FF","service":"932c32bd-0000-47a2-835a-a8d455b859dd","characteristic":"932c32bd-0002-47a2-835a-a8d455b859dd","write":"01","success":false}N: BLE Connect end
1 Like

Great!
I made the required changes, it should hopefully work now :slight_smile:

Still no luck unfortunately

N: [ MQTT->OMG ]: {"ble_write_address":"AA:BB:CC:DD:EE:FF","ble_write_service":"932c32bd-0000-47a2-835a-a8d455b859dd","ble_write_char":"932c32bd-0002-47a2-835a-a8d455b859dd","ble_write_value":"01","value_type":"HEX","mac_type":1,"ttl":4,"immediate":true,"secure":true}
N: BLE Connect begin
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
lld_pdu_get_tx_flush_nb HCI packet count mismatch (1, 2)
E: Connect to: aa:bb:cc:dd:ee:ff failed
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
N: Send on /BTtoMQTT/AABBCCDDEEFF msg {"id":"AA:BB:CC:DD:EE:FF","service":"932c32bd-0000-47a2-835a-a8d455b859dd","characteristic":"932c32bd-0002-47a2-835a-a8d455b859dd","write":"01","success":false}N: BLE Connect end

:frowning: That’s a shame, I would need to see the logs from NimBLE before going any further.

I do not get why no debug messages appear, this is my platformio.ini section:

[env:esp32dev-ble]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
build_type = debug
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'
  '-DCONFIG_NIMBLE_CPP_LOG_LEVEL=5'

I’m not sure either, you could try with ;'-DCORE_DEBUG_LEVEL=4' instead.

N: [ MQTT->OMG ]: {"ble_write_address":"AA:BB:CC:DD:EE:FF","ble_write_service":"932c32bd-0000-47a2-835a-a8d455b859dd","ble_write_char":"932c32bd-0002-47a2-835a-a8d455b859dd","ble_write_value":"01","value_type":"HEX","mac_type":1,"ttl":4,"immediate":true,"secure":true}
N: BLE Connect begin
D NimBLEClient: ">> connect(aa:bb:cc:dd:ee:ff)"
D NimBLEClient: "Got Client event "
I NimBLEClient: "Connected event"
D NimBLEClient: "Got Client event "
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
I NimBLEClient: "Connection established"
D NimBLEClient: "Got Client event "
D NimBLEClient: ">> deleteServices"
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
D NimBLEClient: "<< deleteServices"
D NimBLEClientCallbacks: "onConnect: default"
D NimBLEClient: "<< connect()"
D NimBLEDevice: "Setting bonding: 1, mitm: 1, sc: 1"
D NimBLEClient: "Got Client event "
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
D NimBLEClient: ">> disconnect()"
D NimBLEClient: "<< disconnect()"
D NimBLEClient: "Got Client event "
D NimBLEClientCallbacks: "onDisconnect: default"
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
D NimBLEClient: ">> connect(aa:bb:cc:dd:ee:ff)"
D NimBLEClient: "Got Client event "
I NimBLEClient: "Connected event"
D NimBLEClient: "Got Client event "
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
I NimBLEClient: "Connection established"
D NimBLEClient: "Got Client event "
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
D NimBLEClientCallbacks: "onConnect: default"
D NimBLEClient: "<< connect()"
D NimBLEDevice: "Setting bonding: 1, mitm: 1, sc: 1"
D NimBLEClient: "Got Client event "
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
D NimBLEClient: ">> disconnect()"
D NimBLEClient: "<< disconnect()"
D NimBLEClient: "Got Client event "
D NimBLEClientCallbacks: "onDisconnect: default"
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
D NimBLEClient: ">> connect(aa:bb:cc:dd:ee:ff)"
D NimBLEClient: "Got Client event "
I NimBLEClient: "Connected event"
D NimBLEClient: "Got Client event "
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
I NimBLEClient: "Connection established"
D NimBLEClient: "Got Client event "
D NimBLEClient: ">> deleteServices"
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
D NimBLEClient: "<< deleteServices"
D NimBLEClientCallbacks: "onConnect: default"
D NimBLEClient: "<< connect()"
D NimBLEDevice: "Setting bonding: 1, mitm: 1, sc: 1"
D NimBLEClient: "Got Client event "
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
D NimBLEClient: ">> disconnect()"
D NimBLEClient: "<< disconnect()"
D NimBLEClient: "Got Client event "
D NimBLEClientCallbacks: "onDisconnect: default"
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
D NimBLEClient: ">> connect(aa:bb:cc:dd:ee:ff)"
D NimBLEClient: "Got Client event "
I NimBLEClient: "Connected event"
D NimBLEClient: "Got Client event "
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
I NimBLEClient: "Connection established"
D NimBLEClient: "Got Client event "
D NimBLEClient: ">> deleteServices"
I NimBLEClient: "mtu update event; conn_handle=0 mtu=247"
D NimBLEClient: "<< deleteServices"
D NimBLEClientCallbacks: "onConnect: default"
D NimBLEClient: "<< connect()"
D NimBLEDevice: "Setting bonding: 1, mitm: 1, sc: 1"
D NimBLEClient: "Got Client event "
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
D NimBLEClient: ">> disconnect()"
N: Send on /BTtoMQTT/AABBCCDDEEFF msg {"id"D NimBLEClient: "<< disconnect()"
D NimBLEClient: "Got Client event "
D NimBLEClientCallbacks: "onDisconnect: default"
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
:"AA:BB:CC:DD:EE:FF","service":"932c32bd-0000-47a2-835a-a8d455b859dd","characteristic":"932c32bd-0002-47a2-835a-a8d455b859dd","write":"01","success":false}N: BLE Connect end

Well, that didn’t get us much further :(, thanks very much for the help though!

I guess I need to look at the BLE stack logs, if you want to try setting this '-DCONFIG_BT_NIMBLE_LOG_LEVEL=1' it should show the stack logs. Otherwise I’ll have to try to reproduce this with NimBLE directly with an emulated device.

Still no debug messages :confused: I do not understand why
platformio.ini:

[env:esp32dev-ble]
platform = ${com.esp32_platform}
build_type = debug
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.ble}
  ${libraries.decoder}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=2'
  '-DLED_SEND_RECEIVE_ON=0'
  '-DGateway_Name="OpenMQTTGateway_ESP32_BLE"'
  '-DCONFIG_BT_NIMBLE_LOG_LEVEL=1'

Serial output:

N: BLE Connect begin
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
lld_pdu_get_tx_flush_nb HCI packet count mismatch (1, 2)
E: Connect to: aa:bb:cc:dd:ee:ff failed
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
E: Failed to secure connection to aa:bb:cc:dd:ee:ff
N: BLE Connect end

Hi @christian-0s,

one other thing I came across was others having similar issues with not being able to connect, only after they reset all previous connections with other phones/PCs, by resetting the firmware of the lamp/bulb in the Hue App.

If you want to try that to see if the connections through OpenMQTTGateway will then work.

I’m sure that @h2zero would still want to see the logs to be able to fully understand the connection issue and possibly even give a warning if no more pairings are possible. Why they don’t show up for you hopefully can be figured out.

I’m a bit perplexed by the logs not working also. I’ll take a look into this.

In the mean time a factory reset as suggested might be the solution as the bulb likely has a limit to the number of bonds and you may have hit that when pairing with other devices.