microbitとBluetooth連携

I want to link microbit and node-red with bluetooth and get sensor data with node-red, but I can only connect, but I can't read sensor data. The node used is node-red-contrib-generic-ble.
I am not familiar with bluetooth. The settings on the microbit side are not well understood.
For example, if you press the A button on the microbit, I want to do something like 1 appears in the node-red debug.

Thank you very much.

Seems the microbit supports GATT services. Besides, you have to activate Button Service somehow:

Button Service Custom optional Allow button state changes to be notified to the client

https://lancaster-university.github.io/microbit-docs/ble/profile/#gatt-services

Have you tried some of the other node & solutions discussed here?

I asked the question over on twitter (as that's where I know some microbit people) and best answer so far is only over USB serial

using

Your question has taken me down a very large rabbit hole :slight_smile:

If you run this makecode on your microbit

image

ensuring no paring is set

then connect an android phone using app - nRF connect for mobile

scan and find your microbit

scrolldown to microbit button service - select it and press the 3 down arrows next to button A State

then click on the microbit button A and you should see the it update status on the phone :slight_smile:

Now "all" we need to do is work out what message the android app sends to the microbit to enable the notifications and send the same message from Node-RED :slight_smile:

EUREKA!!! :slight_smile:

[{"id":"4fe8abf7.5e0a24","type":"debug","z":"3d21c343.43135c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1250,"y":160,"wires":[]},{"id":"c03f56cb.e04df8","type":"Generic BLE in","z":"3d21c343.43135c","name":"","genericBle":"5a12ec5b.c1ff74","useString":true,"notification":true,"x":1070,"y":160,"wires":[["4fe8abf7.5e0a24"]]},{"id":"aff7143.6c19ee8","type":"inject","z":"3d21c343.43135c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":660,"y":100,"wires":[["c03f56cb.e04df8"]]},{"id":"4018a3ae.3483ec","type":"inject","z":"3d21c343.43135c","name":"","topic":"","payload":"{   \"notify\": true,   \"period\": 0 }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":650,"y":180,"wires":[["c03f56cb.e04df8"]]},{"id":"5a12ec5b.c1ff74","type":"Generic BLE","z":"","localName":"BBC micro:bit [tezov]","address":"fd:89:16:52:11:57","uuid":"fd8916521157","muteNotifyEvents":false,"operationTimeout":"","characteristics":[{"uuid":"2a00","name":"Device Name","type":"org.bluetooth.characteristic.gap.device_name","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"2a01","name":"Appearance","type":"org.bluetooth.characteristic.gap.appearance","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a04","name":"Peripheral Preferred Connection Parameters","type":"org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a05","name":"Service Changed","type":"org.bluetooth.characteristic.gatt.service_changed","notifiable":false,"readable":false,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d93b1251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"e97d3b10251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":false,"writable":false,"writeWithoutResponse":true},{"uuid":"2a24","name":"Model Number String","type":"org.bluetooth.characteristic.model_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a25","name":"Serial Number String","type":"org.bluetooth.characteristic.serial_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a26","name":"Firmware Revision String","type":"org.bluetooth.characteristic.firmware_revision_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d9775251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d5404251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":true},{"uuid":"e95d23c4251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":false},{"uuid":"e95db84c251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda90251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda91251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false}]}]

:+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1: :+1:

1 Like

I've made this cleaner and easier to use thanks to help from @afelix :slight_smile:

[{"id":"c03f56cb.e04df8","type":"Generic BLE in","z":"3d21c343.43135c","name":"","genericBle":"52932639.b8fa68","useString":false,"notification":true,"x":330,"y":120,"wires":[["4fe8abf7.5e0a24","7bc7f513.4f938c","95f4ae3b.79af7"]]},{"id":"4018a3ae.3483ec","type":"inject","z":"3d21c343.43135c","name":"Start Notifications","topic":"","payload":"{   \"notify\": true,   \"period\": 0 }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["c03f56cb.e04df8"]]},{"id":"bb6ebd6b.69156","type":"comment","z":"3d21c343.43135c","name":"e95dda90251d470aa062fa1922dfa9a8 is Button A","info":"","x":270,"y":40,"wires":[]},{"id":"4adbd1e2.a2d2","type":"comment","z":"3d21c343.43135c","name":"e95dda91251d470aa062fa1922dfa9a8 is ButtonB","info":"","x":680,"y":40,"wires":[]},{"id":"95f4ae3b.79af7","type":"switch","z":"3d21c343.43135c","name":"","property":"$keys(payload.characteristics.$sift(function($val,$key) {$key ~> /[a-f0-9]{32}/}))","propertyType":"jsonata","rules":[{"t":"eq","v":"e95dda90251d470aa062fa1922dfa9a8","vt":"str"},{"t":"eq","v":"e95dda91251d470aa062fa1922dfa9a8","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":120,"wires":[["5493f10.0edff1"],["af6ef78e.cc3d28"]]},{"id":"e42aac6.8060e5","type":"debug","z":"3d21c343.43135c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":930,"y":80,"wires":[]},{"id":"5493f10.0edff1","type":"change","z":"3d21c343.43135c","name":"ButtonA","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.characteristics.$sift(function($val,$key) {$key ~> /[a-f0-9]{32}/}).*","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":80,"wires":[["e42aac6.8060e5"]]},{"id":"af6ef78e.cc3d28","type":"change","z":"3d21c343.43135c","name":"ButtonB","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.characteristics.$sift(function($val,$key) {$key ~> /[a-f0-9]{32}/}).*","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":140,"wires":[["bcbaed84.16fb5"]]},{"id":"bcbaed84.16fb5","type":"debug","z":"3d21c343.43135c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":930,"y":140,"wires":[]},{"id":"52932639.b8fa68","type":"Generic BLE","z":"","localName":"BBC micro:bit [tiguv]","address":"e5:a8:1e:1c:cd:5c","uuid":"e5a81e1ccd5c","muteNotifyEvents":false,"operationTimeout":"","characteristics":[{"uuid":"2a00","name":"Device Name","type":"org.bluetooth.characteristic.gap.device_name","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"2a01","name":"Appearance","type":"org.bluetooth.characteristic.gap.appearance","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a04","name":"Peripheral Preferred Connection Parameters","type":"org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a05","name":"Service Changed","type":"org.bluetooth.characteristic.gatt.service_changed","notifiable":false,"readable":false,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d93b1251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"e97d3b10251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":false,"writable":false,"writeWithoutResponse":true},{"uuid":"2a24","name":"Model Number String","type":"org.bluetooth.characteristic.model_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a25","name":"Serial Number String","type":"org.bluetooth.characteristic.serial_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a26","name":"Firmware Revision String","type":"org.bluetooth.characteristic.firmware_revision_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d9775251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d5404251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":true},{"uuid":"e95d23c4251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":false},{"uuid":"e95db84c251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda90251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda91251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false}]}]

Note - if you long press on a button it will output a 1 and then a 2

Hi @cymplecy . First of all, I would like to thank you your help.
The project I am doing It consist on a IoT which is formed by microbits and a Nordic.

I am trying to install bluetooth ble libraries in windows but I am getting some errors like "No bluetooth 4.0 devices found". After that, I investigate and found a solution which is install Zadig (a programm that install bluetooth ble drivers). However , It doesnt find any devices , as I read , Windows support in a native way BLE devices ( before installing Zadig I could Connect vía bluetooth with microbits, but not vía Node-Red because of the error I mentioned).

I have some questions about what you did:
1.- ¿Do you know if Windows sopports this libraries?
2.- ¿What O.S did you use?
3.- ¿Did you use your phone and then the data which took the phone were redirected yo Node-Red?

Thank you,
Best regards
:grinning:

Hi

  1. I do not know
  2. I used a Raspberry Pi 4 running Raspbian
  3. I used my phone to connect to a microbit to find out what data it was sending out. Then I used that information to connect to the microbit from Node-RED

Hi,
It's interesting the way you used. I would like to ask you a last question.
Why did you decide to do with the phone? I mean , why didnt you use only Raspberry - microbit ?

I had not used Bluetooth before so I thought it would be a good first step

I only did this work because someone asked a question about it and I was curious