Read the statement by Michael Teeuw here.
MMM-OralB / Bluetooth equipped toothbrush integration
-
Exciting times!!
I have been able to move a bit further on this (I think)
With the help of this linkedin post (which funnily enough referenced this forum) and above mentioned post in the home-assistant forum I was able to dive a bit deeper into noble and the BLE interaction.
The current status:- I can read out battery status!! (with the help of this gitlab snippet (yeay!)
- I receive data when turning the brush on and off (and on again) and am able to filter this data. However I’m completely new to noble, the BLE services system and apparently need to learn a lot.
- I am using the npm module @abandonware/noble since the original noble has not been maintained for a few years.
- For some odd reason, I needed to put my js file into the noble folder and work from there. Still need to try working in the oral-b main folder
Here’s what I have learned:
According to the linkedin post (and I could validate that) the “manufacturerData” is NOT a fixed brush-specific value BUT CONTAINS ACTUALLY USEFUL INFORMATION. And it changes. Some of the brush information is written into this entry. You can get the status of the brush and the running time from this.
The question of course is if this is really needed.From my point of view you only need a reliable signal when turning on and off the brush. I’m not sure if I have that already, @SvenSommer might have been already further than I am now, but it is still exciting.
It is still a problem for me to properly talk to the brush :-D . I would like to have a constant flow of information (at least receive the “manufacturedata” every second or so) when the brush is active, and currently I don’t know how to do that. Guess I need to trigger this somehow with noble.TODOs:
- Implement a timer into the module and check if the current setup works well enough.
- Find more characteristics to use as data source
- Find out how to constantly trigger the brush to send its manufacturedata.
And finally here’s my code:
var async = require('async'); var noble = require('@abandonware/noble'); //var OralB_manufacturerData = 'dc0003220c0328000001010004'; process.env['NOBLE_HCI_DEVICE_ID'] = 0 noble.on('stateChange', function(state) { console.log('Changed state to:' + noble.state); if (state === 'poweredOn') { noble.startScanning([], true); } else { console.log('changed state to: ' + noble.state); noble.stopScanning(); } }); console.log('Searching for OralB Toothbrushes'); noble.on('discover', function(peripheral) { var ad = peripheral.advertisement || ""; if (ad.localName == "Oral-B Toothbrush") { //console.log('Found device with local name: ' + ad.localName); //console.log('advertising the following service uuid\'s: ' + ad.serviceUuids); //console.log("ID: "+peripheral.id); //console.log("Advertisement: "+ad); if (ad.manufacturerData) { console.log(ad.manufacturerData.toString('hex')); //console.log('Found OralB Toothbrush with ID: ' + peripheral.id); noble.stopScanning(); peripheral.connect(function(error) { if (error) { console.log("Error connecting to peripheral: " +error) } else { console.log('Connected to peripheral: ' + peripheral.uuid); peripheral.discoverServices([], function(error, services) { console.log("Discovering services...") if (error) { console.log("ERROR while discovering peripherals: " + error); } else { /*console.log('discovered the following services:'); for (var i in services) { console.log(' ' + i + ' uuid: ' + services[i].uuid); }*/ discoverChars(services[3]); /*setTimeout(() => { noble.startScanning([], true); }, 1000);*/ } //peripheral.disconnect(); }); } }); peripheral.on('disconnect', function() { //process.exit(0); console.log("Peripheral disconnected. Scanning again!"); noble.startScanning(); }); } }; }); function discoverChars(service) { service.discoverCharacteristics(null, function(error, characteristics) { //console.log(characteristics); for (var i in characteristics) { var charUUID = characteristics[i].uuid; //console.log("UUID: "+charUUID); if (characteristics[i].uuid == "a0f0ff0550474d5382084f72616c2d42") { characteristics[i].subscribe(function(error){ if(error !== null) console.log("error", error); }); characteristics[i].on('data', function(data, isNotification){ valueInt = data.readInt8(0); //console.log("Battery: "+valueInt+"%") }); characteristics[i].read(function(error, data) { if (data) { valueInt = data.readInt8(0); console.log("Battery: "+valueInt+"%") } }); } } }); }
-
@lavolp3 Thanks for your post. I will have a look into this, hopefully in the next week! I’m still convinced we should build this module.
-
@SvenSommer Thanks Sven and good you’re back on this :-)
I have one question on noble I can’t figure out.
withnoble.on('discover')
I can exchange information on discovery, so as soon as the brush sends a certain signal. All good.
But how can I trigger the brush to send its manufacturedata, let’s say, every 2 seconds?
Or is that not possible at all? -
A small heads-up: Still not getting to terms with noble.
But as I had some connection problems today, I used bluetoothctl again to connect to my brush.
And found out that scanning with bluetoothctl gets a constant output of the manufacturerData of the brush.With bluetoothctl it would be able to get information on
- running time
- mode (on/off)
- quadrant
in an interval of like 10 seconds
-
Hey guys,
I have tracked this topic for a while and I have created an own module for bluetooth devices based on (https://github.com/Hypfer/Cybele). Currently only Oral B toothbrush is supported: https://github.com/timodejong95/MMM-BluetoothDevices
I am still testing it but it seems to work stable’ish. Although I cannot test it with an actual mirror because that is still work in progress. If you want to check it out and test be my guest. If you have any improvements or tips let me know!
Hope this helps out.
-
@timodejong95 GREAT!!
I’ll try it out now.
One comment to the readme.
You have given the config entry in JSON style (with hyphens around the keys).
Config entries are in JS style.
I guess devices should also be an array of JS objects?Then it should be like this:
{ module: "MMM-BluetoothDevices", position: "bottom_bar", config: { devices: [ { type: "OralBToothbrush", name: "OralB", mac: "" } ] } },
-
@lavolp3 Also mentioning in the Readme that
npm install
is necessary would be helpful -
OK I have a first error message
[15:04:46.174] [ERROR] 15:04:46 <error> (node:1454) UnhandledPromiseRejectionWarning: Error: No such interface found at /home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/dbus-native/lib/introspect.js:31:23 at Parser.<anonymous> (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/xml2js/lib/parser.js:304:18) at Parser.emit (events.js:182:13) at SAXParser.onclosetag (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/xml2js/lib/parser.js:262:26) at emit (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/sax/lib/sax.js:624:35) at emitNode (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/sax/lib/sax.js:629:5) at closeTag (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/sax/lib/sax.js:889:7) at SAXParser.write (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/sax/lib/sax.js:1436:13) at Parser.exports.Parser.Parser.parseString (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/xml2js/lib/parser.js:323:31) at Parser.parseString (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/xml2js/lib/parser.js:5:59) (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut)
no Toothbrush activated yet. Only started the mirror with npm start dev.
Running on a RasPi 3b w/ on-board bluetooth -
Ooh good one, I have some time tonight, will update the docs.
Hmm you running on raspberry pi do you got bluetooth enabled? Can you find the toothbrush if you use the GUI bluetooth?
If you got the time could we skype or call, it’s faster to tackle issueus, PM me about that.
-
@timodejong95 that’s rather difficult for me juggling with family, (home) office and several other things I have to say. Will think about this and let you know.
I have worked successfully with bluetoothctl and noble (npm).
Both were able to connect to the brush.
With bluetoothctl I got a constant stream of the manufacturer data that contains some info. (see above)
I used that straight from the console.