guild icon
Toit
#BLE advertising only advertises Object Transfer Service
Thread channel in help
z3ugma
z3ugma 02/07/2024 04:51 AM
For whatever reason, no matter how many times I change my BLE sketch, it only advertises these services as mentioned in the heart_rate BLE sample sketch


Service
#[0x18, 0x25]

Characteristic
#[0x63, 0x4b, 0x3c, 0x6e, 0xac, 0x41, 0x40, 0x85,
0xa9, 0x7c, 0xdd, 0x68, 0x7f, 0xa1, 0xe5, 0x0d]
z3ugma
z3ugma 02/07/2024 04:51 AM
I've now successfully deployed
import ble show * import uuid show Uuid RANDOM_UUID1 ::= BleUuid "2a6e01e0-2789-4311-b35b-85fcc8e66b12" RANDOM_UUID2 ::= BleUuid "f081e493-d276-4018-a6ff-31f887eb1834" RANDOM_UUID3 ::= BleUuid "f467834d-35d3-42c8-a462-dc6db2d0d709" RANDOM_UUID4 ::= BleUuid "be11d6d8-0ba8-4181-a0f1-636c555a31e0" main: adapter := Adapter adapter.set_preferred_mtu 512 peripheral := adapter.peripheral print "Add Service 1" service1 := peripheral.add_service RANDOM_UUID1 some_characteristic := service1.add_write_only_characteristic RANDOM_UUID2 print "Add Service 2" service2 := peripheral.add_service RANDOM_UUID3 some_characteristic = service2.add_write_only_characteristic RANDOM_UUID4 print "Deploy Service 1" service1.deploy print "Deploy Service 2" service2.deploy connection_mode := BLE_CONNECT_MODE_UNDIRECTIONAL peripheral.start_advertise --connection_mode=connection_mode AdvertisementData --name="Sedisto Door Lock" --connectable=true print "Advertising!" while true: print "foo bar" sleep --ms=100000
z3ugma
z3ugma 02/07/2024 04:51 AM
but still, when I open the nRFConnect or LightBlue BLE app, it only shows the Object Transfer services advertised
z3ugma
z3ugma 02/07/2024 05:03 AM
I'm specifically trying to do

main: adapter := Adapter adapter.set_preferred_mtu 512 peripheral := adapter.peripheral print "Add DeviceInformationSerice" service1 := peripheral.add_service BleUuid #[0x18, 0x0A] some_characteristic := service1.add-read-only-characteristic BleUuid #[0x2a, 0x29] --value = "Demo".to-byte-array

In the BLE Spec, this is
Service: 180a // DeviceInformationservice 0x180A
Characteristic: 2a29 // ManufacturerNameString 0x2A29
z3ugma
z3ugma 02/07/2024 05:05 AM
Maybe referencing https://github.com/toitlang/toit/issues/974#issuecomment-1286772146 as a possible, relevant comment?
Andreas Spiess complains in its Youtube-Review that the Documentation contains a Bluetooth Tutorial but misses to explain or show how to actually transmit data - he failed there (he got only manufa...
z3ugma
z3ugma 02/07/2024 05:18 AM
and a bunch of tasty stacktrace crashing:

Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled. Core 0 register dump: PC : 0x40122c87 PS : 0x00060d30 A0 : 0x8012afb4 A1 : 0x3fff6da0 A2 : 0xf0c8ffff A3 : 0x3fff6dd4 A4 : 0x00000000 A5 : 0x00000000 A6 : 0x00000010 A7 : 0x00000000 A8 : 0x80120de7 A9 : 0x3fff6d80 A10 : 0x3fff503b A11 : 0x00000002 A12 : 0x00000000 A13 : 0x3fff5018 A14 : 0x3ffc87fc A15 : 0x01100004 SAR : 0x00000018 EXCCAUSE: 0x0000001c EXCVADDR: 0xf0c8ffff LBEG : 0x4000c349 LEND : 0x4000c36b LCOUNT : 0xffffffff ****************************************************************************** Backtrace: 0x40122c84:0x3fff6da0 0x4012afb1:0x3fff6dc0 0x4011ec25:0x3fff6e40 0x4011eaeb:0x3fff6e70 0x4011e3b0:0x3fff6ea0 0x4011e3bb:0x3fff6ec0 0x401be923:0x3fff6ee0 0x40089a49:0x3fff6f00 0x400d2f2f:0x3fff6f20 0x400e74b2:0x3fff6f40 0x400e74d9:0x3fff6f60 jag: Failed to decode line. ****************************************************************************** ELF file SHA256: ceb4bed33fee4f08 Rebooting... ets Jun 8 2016 00:22:57 rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:184 load:0x40078000,len:13240 load:0x40080400,len:2920 entry 0x40080578 [toit] INFO: starting <v2.0.0-alpha.130> [toit] INFO: running on ESP32 - revision 1.0
z3ugmaOPz3ugma
and a bunch of tasty stacktrace crashing: ``` Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled. Core 0 register dump: PC : 0x40122c87 PS...
floitsch
floitsch 02/07/2024 07:40 AM
Looking.
floitsch
floitsch 02/07/2024 07:43 AM
The decoded backtrace is:
0x40122c84: ble_uuid_cmp + 0x0 0x4012afb1: ble_att_svr_rx_read_group_type + 0x18d 0x4011ec25: ble_att_rx + 0x5d 0x4011eaeb: ble_hs_hci_evt_acl_process + 0x7b 0x4011e3b0: ble_hs_process_rx_data_queue + 0x10 0x4011e3bb: ble_hs_event_rx_data + 0x3 0x401be923: npl_freertos_event_run + 0xb 0x40089a49: nimble_port_run + 0x25 0x400d2f2f: non-virtual thunk to toit::BleResourceGroup::entry() + 0x3 0x400e74b2: toit::Thread::_boot() + 0x22 0x400e74d9: toit::esp_thread_start(void*) + 0x5
Will try to figure out what went wrong.
floitsch
floitsch 02/07/2024 07:51 AM
Can you reproduce the crash?
It's somewhere in the Nimble code, and a repro would help a lot...
floitsch
floitsch 02/07/2024 08:01 AM
Ok. It seems like I can reproduce the crash.
Now let's see if I can fix it...
floitsch
floitsch 02/07/2024 10:28 AM
I think we are hitting again https://github.com/toitlang/toit/issues/1660
Fixing this would require a bigger rewrite of the BLE layer...
If I create multiple services for an BLE peripheral I can always only add one service to it. Adding and deploying a second one always crashes with a core-panic. s1 := peripheral.add_service uuid1 /...
👍1
11 messages in total