shmuelzon / ble2mqtt

A BLE to MQTT bridge
MIT License
60 stars 6 forks source link

bidirectional communication? #7

Closed Yury777 closed 5 years ago

Yury777 commented 5 years ago

If I send data in topic mqtt, it changes, but is not sent on BLE to the device

shmuelzon commented 5 years ago

Please provide more details as to what exactly you’re doing. Which service/characteristic? Which topic are you receiving the data on? Which topic are you trying to send the data?

Yury777 commented 5 years ago

mac/service/characteristic C0:E9:AF:B3:FE:97/00001523-1212-efde-1523-785feabcd123/00001525-1212-efde-1523-785feabcd123 data:255

shmuelzon commented 5 years ago

Assuming you didn’t change the default configuration, you need to append the ‘/Set’ suffix to the MQTT topic when you want to set a new value.

Yury777 commented 5 years ago

or remove "set_suffix": "/Set" from config.json?

shmuelzon commented 5 years ago

Right. But that would leave you in an ‘optimistic’ mode where you assume that writing will always succeed instead of writing to a different topic and waiting to see if the new value was really set.

Yury777 commented 5 years ago

not work without "set_suffix": "/Set" :-(

Yury777 commented 5 years ago

don't send data

shmuelzon commented 5 years ago

Does it work with the ‘/Set’ suffix? When you removed it, did you remove the entry or change it to an empty string? The latter should work.

shmuelzon commented 5 years ago

Please run the app with: npm run-script dev And post the resulting log. Specifically, I want to make sure the characteristic is writable, the MQTT request for writing was received and the data for sending was received and parsed correctly.

Yury777 commented 5 years ago

root@raspberrypi:~/ble2mqtt# npm run-script dev

ble2mqtt@1.0.0 dev /root/ble2mqtt DEBUG=* node app.js

ble2mqtt Connected to MQTT server +0ms Bluez An adapter was added: /org/bluez/hci0 +49ms Bluez:Adapter:/org/bluez/hci0 New adapter +1ms Bluez:Adapter:/org/bluez/hci0 Address changed from undefined to B8:27:EB:6D:2E:8B +11ms Bluez:Adapter:/org/bluez/hci0 Name changed from undefined to raspberrypi +1ms Bluez:Adapter:/org/bluez/hci0 Alias changed from undefined to raspberrypi +0ms Bluez:Adapter:/org/bluez/hci0 Class changed from undefined to 0 +0ms Bluez:Adapter:/org/bluez/hci0 Powered changed from undefined to false +0ms Bluez:Adapter:/org/bluez/hci0 Discoverable changed from undefined to false +1ms Bluez:Adapter:/org/bluez/hci0 DiscoverableTimeout changed from undefined to 180 +0ms Bluez:Adapter:/org/bluez/hci0 Pairable changed from undefined to true +1ms Bluez:Adapter:/org/bluez/hci0 PairableTimeout changed from undefined to 0 +0ms Bluez:Adapter:/org/bluez/hci0 Discovering changed from undefined to false +0ms Bluez:Adapter:/org/bluez/hci0 UUIDs changed from undefined to 00001112-0000-1000-8000-00805f9b34fb,00001801-0000-1000-8000-00805f9b34fb,0000110e-0000-1000-8000-00805f9b34fb,00001800-0000-1000-8000-00805f9b34fb,00001200-0000-1000-8000-00805f9b34fb,0000110c-0000-1000-8000-00805f9b34fb,0000110a-0000-1000-8000-00805f9b34fb,0000111f-0000-1000-8000-00805f9b34fb +1ms Bluez:Adapter:/org/bluez/hci0 Modalias changed from undefined to usb:v1D6Bp0246d052B +0ms ble2mqtt Found new adapter: [Object BluezAdapter (/org/bluez/hci0)] +2s Bluez:Adapter:/org/bluez/hci0 Class changed from 0 to 4718592 +126ms Bluez:Adapter:/org/bluez/hci0 Powered on +7ms ble2mqtt Powered on [Object BluezAdapter (/org/bluez/hci0)] +1ms Bluez:Adapter:/org/bluez/hci0 Powered changed from false to true +3ms Bluez:Adapter:/org/bluez/hci0 Set discovery filter: { Transport: 'le' } +6ms ble2mqtt Filtered only LE devices +16ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 +7ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 New device +2ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_E4_A7_C5_50_2C_8E +2ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E New device +2ms Bluez:Adapter:/org/bluez/hci0 Started discovering +2ms ble2mqtt Started discovery on [Object BluezAdapter (/org/bluez/hci0)] +1ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Address changed from undefined to C0:E9:AF:B3:FE:97 +21ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Name changed from undefined to Nordic_Blinky +0ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Alias changed from undefined to Nordic_Blinky +1ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Paired changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Trusted changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Blocked changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 LegacyPairing changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Connected changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 UUIDs changed from undefined to 00001523-1212-efde-1523-785feabcd123,00001800-0000-1000-8000-00805f9b34fb,00001801-0000-1000-8000-00805f9b34fb +0ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Adapter changed from undefined to /org/bluez/hci0 +1ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 ServicesResolved changed from undefined to false +1ms ble2mqtt Found new device: C0:E9:AF:B3:FE:97 (Nordic_Blinky) +5ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Address changed from undefined to E4:A7:C5:50:2C:8E +4ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Name changed from undefined to HUAWEI Band 2-c8e +1ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Alias changed from undefined to HUAWEI Band 2-c8e +0ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Paired changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Trusted changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Blocked changed from undefined to true +1ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E LegacyPairing changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Connected changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E UUIDs changed from undefined to 00001812-0000-1000-8000-00805f9b34fb +1ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E Adapter changed from undefined to /org/bluez/hci0 +0ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E ManufacturerData changed from undefined to [object Object] +1ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E ServicesResolved changed from undefined to false +0ms Bluez:Adapter:/org/bluez/hci0 Discovering changed from false to true +207ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_66_8E_B9_3A_8D_BE +13ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE New device +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Address changed from undefined to 66:8E:B9:3A:8D:BE +10ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Alias changed from undefined to 66-8E-B9-3A-8D-BE +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Paired changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Trusted changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Blocked changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE LegacyPairing changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE RSSI changed from undefined to -89 +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Connected changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE UUIDs changed from undefined to +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE Adapter changed from undefined to /org/bluez/hci0 +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE ManufacturerData changed from undefined to [object Object] +1ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE ServicesResolved changed from undefined to false +1ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_7E_4D_2A_44_DE_15 +103ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 New device +1ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Address changed from undefined to 7E:4D:2A:44:DE:15 +9ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Alias changed from undefined to 7E-4D-2A-44-DE-15 +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Paired changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Trusted changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Blocked changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 LegacyPairing changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 RSSI changed from undefined to -91 +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Connected changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 UUIDs changed from undefined to +1ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 Adapter changed from undefined to /org/bluez/hci0 +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 ManufacturerData changed from undefined to [object Object] +0ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 ServicesResolved changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E RSSI changed from undefined to -80 +535ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_44_C4_25_6C_1F_3B +192ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B New device +1ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_48_65_9D_7E_D0_28 +3ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 New device +2ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Address changed from undefined to 44:C4:25:6C:1F:3B +22ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Alias changed from undefined to 44-C4-25-6C-1F-3B +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Paired changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Trusted changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Blocked changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B LegacyPairing changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B RSSI changed from undefined to -99 +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Connected changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B UUIDs changed from undefined to +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B Adapter changed from undefined to /org/bluez/hci0 +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B ServicesResolved changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Address changed from undefined to 48:65:9D:7E:D0:28 +7ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Alias changed from undefined to 48-65-9D-7E-D0-28 +1ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Paired changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Trusted changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Blocked changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 LegacyPairing changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 RSSI changed from undefined to -82 +0ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Connected changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 UUIDs changed from undefined to +0ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 Adapter changed from undefined to /org/bluez/hci0 +1ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 ManufacturerData changed from undefined to [object Object] +0ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 ServicesResolved changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E RSSI changed from -80 to -89 +614ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E TxPower changed from undefined to 4 +0ms Bluez:Adapter:/org/bluez/hci0 A device was added: /org/bluez/hci0/dev_4C_ED_E9_2A_92_8E +6s Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E New device +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B RSSI changed from -99 to -96 +2ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Address changed from undefined to 4C:ED:E9:2A:92:8E +22ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Alias changed from undefined to 4C-ED-E9-2A-92-8E +1ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Paired changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Trusted changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Blocked changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E LegacyPairing changed from undefined to false +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E RSSI changed from undefined to -99 +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Connected changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E UUIDs changed from undefined to +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E Adapter changed from undefined to /org/bluez/hci0 +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E ManufacturerData changed from undefined to [object Object] +0ms Bluez:Device:/org/bluez/hci0/dev_4C_ED_E9_2A_92_8E ServicesResolved changed from undefined to false +1ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B RSSI changed from -96 to -98 +3s Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 RSSI changed from -82 to -84 +2ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 RSSI changed from -91 to -83 +45ms Bluez:Device:/org/bluez/hci0/dev_E4_A7_C5_50_2C_8E RSSI changed from -89 to -79 +175ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 RSSI changed from undefined to -82 +3s Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Connected changed from false to true +42ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 Connected +162ms ble2mqtt Connected to [Object BluezDevice (/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97)] +2ms Bluez:Device:/org/bluez/hci0/dev_48_65_9D_7E_D0_28 RSSI changed from -84 to -87 +204ms Bluez:Device:/org/bluez/hci0/dev_44_C4_25_6C_1F_3B RSSI changed from -98 to -96 +10ms Bluez:Device:/org/bluez/hci0/dev_7E_4D_2A_44_DE_15 RSSI changed from -83 to -89 +2ms Bluez:Device:/org/bluez/hci0/dev_66_8E_B9_3A_8D_BE RSSI changed from -89 to -90 +335ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 ServicesResolved changed from false to true +106ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 A service was added: /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b +25ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b New service +2ms Bluez:Device:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 A service was added: /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000a +2ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000a New service +2ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b UUID changed from undefined to 00001523-1212-efde-1523-785feabcd123 +15ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b Device changed from undefined to /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 +0ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b Primary changed from undefined to true +1ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000a UUID changed from undefined to 00001801-0000-1000-8000-00805f9b34fb +3ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000a Device changed from undefined to /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97 +0ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000a Primary changed from undefined to true +1ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b A characteristic was added: /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000f +11ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000f New characteristic +3ms Bluez:Service:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b A characteristic was added: /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c +2ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c New characteristic +3ms ble2mqtt Found new service: C0:E9:AF:B3:FE:97/00001523-1212-efde-1523-785feabcd123 +5ms ble2mqtt Found new service: C0:E9:AF:B3:FE:97/GenericAttribute +9ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000f UUID changed from undefined to 00001525-1212-efde-1523-785feabcd123 +16ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000f Service changed from undefined to /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b +2ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000f Value changed from undefined to +2ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000f Flags changed from undefined to read,write +2ms ble2mqtt Found new characteristic: C0:E9:AF:B3:FE:97/00001523-1212-efde-1523-785feabcd123/00001525-1212-efde-1523-785feabcd123 (read,write) +4ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c UUID changed from undefined to 00001524-1212-efde-1523-785feabcd123 +10ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c Service changed from undefined to /org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b +2ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c Value changed from undefined to +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c Notifying changed from undefined to false +1ms Bluez:Characteristic:/org/bluez/hci0/dev_C0_E9_AF_B3_FE_97/service000b/char000c Flags changed from undefined to read,notify +1ms ble2mqtt Found new characteristic: C0:E9:AF:B3:FE:97/00001523-1212-efde-1523-785feabcd123/00001524-1212-efde-1523-785feabcd123 (read,notify) +0ms /root/ble2mqtt/app.js:77 c.Value.length, characteristicsList[c.UUID].types); ^

TypeError: Cannot read property 'types' of undefined at MqttClient.mqtt.on (/root/ble2mqtt/app.js:77:49) at MqttClient.emit (events.js:182:13) at MqttClient._handlePublish (/root/ble2mqtt/node_modules/mqtt/lib/client.js:765:12) at MqttClient._handlePacket (/root/ble2mqtt/node_modules/mqtt/lib/client.js:272:12) at process (/root/ble2mqtt/node_modules/mqtt/lib/client.js:230:12) at MqttClient._handlePacket (/root/ble2mqtt/node_modules/mqtt/lib/client.js:280:7) at process (/root/ble2mqtt/node_modules/mqtt/lib/client.js:230:12) at Writable.writable._write (/root/ble2mqtt/node_modules/mqtt/lib/client.js:240:5) at doWrite (/root/ble2mqtt/node_modules/readable-stream/lib/_stream_writable.js:237:10) at writeOrBuffer (/root/ble2mqtt/node_modules/readable-stream/lib/_stream_writable.js:227:5) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ble2mqtt@1.0.0 dev: DEBUG=* node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ble2mqtt@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-01T13_46_11_384Z-debug.log

shmuelzon commented 5 years ago

OK, so there’s a bug here when the characteristic’s value types aren’t defined (like the ones you’ve added before). You can get around it by adding this characteristic to the configuration file (and make sure to add the relevant ‘types’).

Yury777 commented 5 years ago

how I can make whitelist for service and characteristics?

Yury777 commented 5 years ago

I can't convert this Eddystone URL. https://nordicsemiconductor.github.io/Nordic-Thingy52-FW/documentation/firmware_architecture.html#arch_config

shmuelzon commented 5 years ago

how I can make whitelist for service and characteristics?

See the README file.

I can’t convert this Eddystone URL.

Unless you add specific support, you won’t get parsing to a ‘regular’ string. You can simply model it as 17 uint8’s and handle the URL logic itself at a higher level.

Yury777 commented 5 years ago

ok. "types": ["uint8", "uint8", "uint8", "uint8", "uint8", "uint8", "uint8", "uint8", "uint8", "uint8", "uint8", "uint8","uint8", "uint8", "uint8", "uint8","uint8"]

Yury777 commented 5 years ago

how about "Cloud token"? 250 bytes? :-)

Yury777 commented 5 years ago

and "Microphone characteristic" Max 273 bytes...

shmuelzon commented 5 years ago

I’m assuming the microphone is read-only so it shouldn’t be a problem.

Anyways, like I said, it’s a bug/missing feature. Defaulting to byte-arrays was only implemented for reading and not writing. Adding the definitions is only a work-around. I might get around to implementing it in the near future, but can’t make any promisses.

BTW - The ESP32 version of BLE2MQTT does not suffer from this issue

Yury777 commented 5 years ago

Thank you very much!

Yury777 commented 5 years ago

how I can make whitelist for service and characteristics?

See the README file.

I see about whitelist for mac. I don't want read all service from device, maybe I can read only 5 from special list? :-)

shmuelzon commented 5 years ago

Oh, I missread before. That feature doesn’t exist here. As before, it does in the ESP32 variant.

Yury777 commented 5 years ago

Make it please here. My home is going to be stupid. :-)

shmuelzon commented 5 years ago

You can try this (untested) patch to work with characteristics that aren't defined:

diff --git a/app.js b/app.js
index 8ad6c5b..c054b67 100644
--- a/app.js
+++ b/app.js
@@ -73,8 +73,9 @@ mqtt.on('message', (topic, message) => {
     return;

   /* Convert value back to byte array */
+  var info = characteristicsList[c.UUID];
   var newBuf = utils.gattTypesToBuffer(JSON.parse('[' + message + ']'),
-    c.Value.length, characteristicsList[c.UUID].types);
+    c.Value.length, info && info.types ? info.types : []);

   /* Is this a different value? */
   if (newBuf.compare(Buffer.from(c.Value)) == 0)
diff --git a/utils.js b/utils.js
index 9ee777f..c52528f 100644
--- a/utils.js
+++ b/utils.js
@@ -333,5 +333,9 @@ module.exports.gattTypesToBuffer = function(arr, length, types) {
     }
   });

+  /* Assume the rest is a byte array */
+  for (i = types.length; i < arr.length; i++)
+    buf.writeUIntLE(arr[i], offset++, 1);
+
   return buf;
 }

As for services/characteristic filtering, I don't think I'll implement it, but a pull request would be welcome. This project is pretty much deprecated in favour of the ESP32 variant. I'll make a note of that in the README.

Yury777 commented 5 years ago

root@raspberrypi:~/ble2mqtt# npm run-script dev

ble2mqtt@1.0.0 dev /root/ble2mqtt DEBUG=* node app.js

internal/modules/cjs/loader.js:605 throw err; ^

Error: Cannot find module './resources/services' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15) at Function.Module._load (internal/modules/cjs/loader.js:529:25) at Module.require (internal/modules/cjs/loader.js:658:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (/root/ble2mqtt/app.js:8:22) at Module._compile (internal/modules/cjs/loader.js:722:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10) at Module.load (internal/modules/cjs/loader.js:620:32) at tryModuleLoad (internal/modules/cjs/loader.js:560:12) at Function.Module._load (internal/modules/cjs/loader.js:552:3) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ble2mqtt@1.0.0 dev: DEBUG=* node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ble2mqtt@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-02T07_33_47_638Z-debug.log

shmuelzon commented 5 years ago

Did you remove the resources/services.json file that was automatically created? If so, it's only created automatically when executing npm start. You can create it manually with: node utils/getGattAssignedNumbers.js

Yury777 commented 5 years ago

root@raspberrypi:~/ble2mqtt# npm start

ble2mqtt@1.0.0 prestart /root/ble2mqtt node utils/getGattAssignedNumbers.js

ble2mqtt@1.0.0 start /root/ble2mqtt DEBUG=ble2mqtt node app.js

internal/modules/cjs/loader.js:744 throw err; ^

SyntaxError: /root/ble2mqtt/config.json: Unexpected string in JSON at position 743 at JSON.parse () at Object.Module._extensions..json (internal/modules/cjs/loader.js:741:27) at Module.load (internal/modules/cjs/loader.js:620:32) at tryModuleLoad (internal/modules/cjs/loader.js:560:12) at Function.Module._load (internal/modules/cjs/loader.js:552:3) at Module.require (internal/modules/cjs/loader.js:658:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (/root/ble2mqtt/app.js:7:16) at Module._compile (internal/modules/cjs/loader.js:722:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ble2mqtt@1.0.0 start: DEBUG=ble2mqtt node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ble2mqtt@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-02T08_08_28_327Z-debug.log

shmuelzon commented 5 years ago

SyntaxError: /root/ble2mqtt/config.json: Unexpected string in JSON at position 743

Your configuration file isn't a valid JSON. You can use linters (e.g. https://jsonlint.com/) to verify your JSON format is correct

Yury777 commented 5 years ago

:-))))

Yury777 commented 5 years ago

whitelist in services&characteristics isn't work. all characteristics from config.json publishing, other publishing too...

Yury777 commented 5 years ago

ble2mqtt Found new characteristic: C5:4A:D2:94:7D:11/GenericAttribute/ServiceChanged (indicate) +0ms internal/buffer.js:54 throw new ERR_OUT_OF_RANGE(type || 'offset', ^

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 5 at boundsError (internal/buffer.js:54:9) at writeUInt8 (internal/buffer.js:571:5) at Buffer.writeUIntLE (internal/buffer.js:482:12) at .each (/root/ble2mqtt/utils.js:246:13) at Function..each..forEach (/root/ble2mqtt/nodemodules/underscore/underscore.js:153:9) at .(anonymous function) [as each] (/root/ble2mqtt/node_modules/underscore/underscore.js:1496:34) at Object.module.exports.gattTypesToBuffer (/root/ble2mqtt/utils.js:227:12) at MqttClient.mqtt.on (/root/ble2mqtt/app.js:77:22) at MqttClient.emit (events.js:182:13) at MqttClient._handlePublish (/root/ble2mqtt/node_modules/mqtt/lib/client.js:765:12) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ble2mqtt@1.0.0 dev: DEBUG=* node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ble2mqtt@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-02T08_52_07_836Z-debug.log

shmuelzon commented 5 years ago

whitelist in services&characteristics isn't work.

Yes, as I stated earlier...

As for the crash, you can try the following instead of the previous patch:

diff --git a/app.js b/app.js
index 8ad6c5b..c054b67 100644
--- a/app.js
+++ b/app.js
@@ -73,8 +73,9 @@ mqtt.on('message', (topic, message) => {
     return;

   /* Convert value back to byte array */
+  var info = characteristicsList[c.UUID];
   var newBuf = utils.gattTypesToBuffer(JSON.parse('[' + message + ']'),
-    c.Value.length, characteristicsList[c.UUID].types);
+    c.Value.length, info && info.types ? info.types : []);

   /* Is this a different value? */
   if (newBuf.compare(Buffer.from(c.Value)) == 0)
diff --git a/utils.js b/utils.js
index 9ee777f..8726115 100644
--- a/utils.js
+++ b/utils.js
@@ -221,7 +221,7 @@ module.exports.bufferToGattTypes = function(buf, types) {
 }

 module.exports.gattTypesToBuffer = function(arr, length, types) {
-  var buf = Buffer.allocUnsafe(length);
+  var buf = Buffer.allocUnsafe(1024);
   var offset = 0;

   _(types).each((type, i) => {
@@ -333,5 +333,9 @@ module.exports.gattTypesToBuffer = function(arr, length, types) {
     }
   });

-  return buf;
+  /* Assume the rest is a byte array */
+  for (i = types.length; i < arr.length; i++)
+    buf.writeUIntLE(arr[i], offset++, 1);
+
+  return buf.slice(0, offset);
 }
Yury777 commented 5 years ago

... ble2mqtt Found new characteristic: C5:4A:D2:94:7D:11/ThingyConfiguration/DeviceName (read,write) +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b UUID changed from undefined to 00002a05-0000-1000-8000-00805f9b34fb +3ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Service changed from undefined to /org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Value changed from undefined to +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Notifying changed from undefined to false +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Flags changed from undefined to indicate +0ms ble2mqtt Found new characteristic: C5:4A:D2:94:7D:11/GenericAttribute/ServiceChanged (indicate) +1ms ble2mqtt Writing "0,0,0,0" to EXTpin +2ms ble2mqtt Writing "0,26,113,199,13" to LED +2ms undefined:1 [Bedroom] ^

SyntaxError: Unexpected token B in JSON at position 1 at JSON.parse () at MqttClient.mqtt.on (/root/ble2mqtt/app.js:77:45) at MqttClient.emit (events.js:182:13) at MqttClient._handlePublish (/root/ble2mqtt/node_modules/mqtt/lib/client.js:765:12) at MqttClient._handlePacket (/root/ble2mqtt/node_modules/mqtt/lib/client.js:272:12) at process (/root/ble2mqtt/node_modules/mqtt/lib/client.js:230:12) at MqttClient._handlePacket (/root/ble2mqtt/node_modules/mqtt/lib/client.js:280:7) at process (/root/ble2mqtt/node_modules/mqtt/lib/client.js:230:12) at Writable.writable._write (/root/ble2mqtt/node_modules/mqtt/lib/client.js:240:5) at doWrite (/root/ble2mqtt/node_modules/readable-stream/lib/_stream_writable.js:237:10) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ble2mqtt@1.0.0 dev: DEBUG=* node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ble2mqtt@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-02T09_29_51_261Z-debug.log

shmuelzon commented 5 years ago
diff --git a/app.js b/app.js
index 8ad6c5b..6bea573 100644
--- a/app.js
+++ b/app.js
@@ -73,8 +73,9 @@ mqtt.on('message', (topic, message) => {
     return;

   /* Convert value back to byte array */
-  var newBuf = utils.gattTypesToBuffer(JSON.parse('[' + message + ']'),
-    c.Value.length, characteristicsList[c.UUID].types);
+  var info = characteristicsList[c.UUID];
+  var newBuf = utils.gattTypesToBuffer(message.split(','),
+    c.Value.length, info && info.types ? info.types : []);

   /* Is this a different value? */
   if (newBuf.compare(Buffer.from(c.Value)) == 0)
diff --git a/utils.js b/utils.js
index 9ee777f..63ad110 100644
--- a/utils.js
+++ b/utils.js
@@ -221,15 +221,15 @@ module.exports.bufferToGattTypes = function(buf, types) {
 }

 module.exports.gattTypesToBuffer = function(arr, length, types) {
-  var buf = Buffer.allocUnsafe(length);
+  var buf = Buffer.allocUnsafe(1024);
   var offset = 0;

   _(types).each((type, i) => {
-    var val = arr[i];
+    var val = Number(arr[i]);

     switch (type) {
       case 'boolean':
-        buf.writeUIntLE(val == true ? 1 : 0, offset, 1);
+        buf.writeUIntLE(arr[i] === 'true' ? 1 : 0, offset, 1);
         offset += 1;
         break;
       case '2bit':
@@ -295,10 +295,10 @@ module.exports.gattTypesToBuffer = function(arr, length, types) {
         break;
       /* String values consume the rest of the buffer */
       case 'utf8s':
-        offset += buf.write(val, offset, 'utf8');
+        offset += buf.write(arr[i], offset, 'utf8');
         break;
       case 'utf16s':
-        offset += buf.write(val, offset, 'utf16');
+        offset += buf.write(arr[i], offset, 'utf16');
         break;
       /* IEEE-754 floating point format */
       case 'float32':
@@ -333,5 +333,9 @@ module.exports.gattTypesToBuffer = function(arr, length, types) {
     }
   });

-  return buf;
+  /* Assume the rest is a byte array */
+  for (i = types.length; i < arr.length; i++)
+    buf.writeUIntLE(arr[i], offset++, 1);
+
+  return buf.slice(0, offset);
 }
Yury777 commented 5 years ago

ble2mqtt Found new characteristic: C0:E9:AF:B3:FE:97/MyRelay/Button1 (read,notify) +2ms ble2mqtt Publishing C0:E9:AF:B3:FE:97/MyRelay/Button1: 0 +2ms /root/ble2mqtt/app.js:77 var newBuf = utils.gattTypesToBuffer(message.split(','), ^

TypeError: message.split is not a function at MqttClient.mqtt.on (/root/ble2mqtt/app.js:77:48) at MqttClient.emit (events.js:182:13) at MqttClient._handlePublish (/root/ble2mqtt/node_modules/mqtt/lib/client.js:765:12) at MqttClient._handlePacket (/root/ble2mqtt/node_modules/mqtt/lib/client.js:272:12) at process (/root/ble2mqtt/node_modules/mqtt/lib/client.js:230:12) at MqttClient._handlePacket (/root/ble2mqtt/node_modules/mqtt/lib/client.js:280:7) at process (/root/ble2mqtt/node_modules/mqtt/lib/client.js:230:12) at Writable.writable._write (/root/ble2mqtt/node_modules/mqtt/lib/client.js:240:5) at doWrite (/root/ble2mqtt/node_modules/readable-stream/lib/_stream_writable.js:237:10) at writeOrBuffer (/root/ble2mqtt/node_modules/readable-stream/lib/_stream_writable.js:227:5) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! ble2mqtt@1.0.0 dev: DEBUG=* node app.js npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the ble2mqtt@1.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-02T10_06_13_489Z-debug.log

shmuelzon commented 5 years ago

Try to change:

message.split(',')

to:

message.toString().split(',')
Yury777 commented 5 years ago

ok. more stable. but "Device name characteristic" Bedroom" convert to "edroom" and not change from mqtt. in config.json DeviceName - "types": ["utf8s"] https://nordicsemiconductor.github.io/Nordic-Thingy52-FW/documentation/firmware_architecture.html#arch_config

shmuelzon commented 5 years ago

I'm not sure what you mean... If you attempt to read the characteristic from a different device, you get "Bedroom"? What happens when you try to set it via MQTT?

Yury777 commented 5 years ago

"ef680101-9b35-4933-9b10-52ffa9740042": { "name": "DeviceName", "types": ["utf8s"] }, is "Device name characteristic" from this: https://nordicsemiconductor.github.io/Nordic-Thingy52-FW/documentation/firmware_architecture.html#arch_config

Yury777 commented 5 years ago

before start ble2mqtt Device name characteristic = "Bedroom", after = "edroom"

Yury777 commented 5 years ago

ble2mqtt Found new characteristic: C5:4A:D2:94:7D:11/ThingyConfiguration/DeviceName (read,write) +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b UUID changed from undefined to 00002a05-0000-1000-8000-00805f9b34fb +2ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Service changed from undefined to /org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Value changed from undefined to +1ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Notifying changed from undefined to false +0ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service000a/char000b Flags changed from undefined to indicate +0ms ble2mqtt Found new characteristic: C5:4A:D2:94:7D:11/GenericAttribute/ServiceChanged (indicate) +0ms ble2mqtt Writing "1,1" to SoundConfig +3ms ble2mqtt Writing "0,0,0,0" to EXTpin +1ms ble2mqtt Writing "0,26,113,199,13" to LED +1ms ble2mqtt Writing "232,3,244,1,244,1,10,0,1" to MotionConfig +1ms ble2mqtt Writing "208,7,208,7,208,7,220,5,2,103,78,29" to Configuration +0ms ble2mqtt Writing "0,5,2" to MTUrequest +1ms ble2mqtt Writing "3,103,111,111,46,103,108,47,112,73,87,100,105,114" to EddystoneURL +0ms ble2mqtt Writing "6,0,24,0,0,0,64,1" to ConnectionParam +1ms ble2mqtt Writing "96,2,180" to AdvertisingParam +0ms ble2mqtt Writing "edroom" to DeviceName +40ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service0060/char0061 Notifying changed from false to true +76ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service0060/char0061 Listening on notifications +1ms Bluez:Characteristic:/org/bluez/hci0/dev_C5_4A_D2_94_7D_11/service0060/char0061 Value changed from to 85 +150ms ble2mqtt Publishing C5:4A:D2:94:7D:11/BatteryService/BatteryLevel: 85 +0ms

shmuelzon commented 5 years ago

The ble2mqtt Writing XXX log contains the exact message that was received from MQTT. My guess is that you've removed the '/Set' suffix and are publishing topic values with the retained flag. This means that once connected to a BLE device the app subscribes to MQTT topics for setting the characteristic values. But the set topics (same as the value topics) are already saved in the MQTT broker and are retained. That's why you see the ble2mqtt Writing XXX message logs right after connection. In this case, you could probably just publish an MQTT topic (retained) with the correct device name and it will be set, as expected.

Yury777 commented 5 years ago

I modify config.json.... now whit prefix "Set".