Read the statement by Michael Teeuw here.
MMM-OralB / Bluetooth equipped toothbrush integration
-
@timodejong95 OK I have identified the source of the error.
It originated from the connectDevice function on Dongle.js
I had a wrong mac address for the brush which leads to an unresolved promise.
Good luck finding the promise :smiling_face_with_open_mouth_smiling_eyes:
(I love/hate promises…)Correcting the mac address I get new unresolved rejection errors.
[11:54:35.940] [LOG] 11:54:35 <log> Retrying Dirks OralB 2/3 (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/src/Device.js:42 Promise) [11:54:35.964] [ERROR] 11:54:35 <error> (node:23373) UnhandledPromiseRejectionWarning: Software caused connection abort (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:54:35.970] [ERROR] 11:54:35 <error> (node:23373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:54:35.975] [ERROR] 11:54:35 <error> (node:23373) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:55:16.260] [LOG] 11:55:16 <log> Retrying Dirks OralB 3/3 (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/src/Device.js:42 Promise) [11:55:16.275] [ERROR] 11:55:16 <error> (node:23373) UnhandledPromiseRejectionWarning: Software caused connection abort (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:55:16.279] [ERROR] 11:55:16 <error> (node:23373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:55:56.582] [ERROR] 11:55:56 <error> (node:23373) UnhandledPromiseRejectionWarning: Error: Couldn't connect to Dirks OralB after 4 tries. at Promise (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/src/Device.js:46:16) at new Promise (<anonymous>) at tryConnect (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/src/Device.js:40:14) at Object.iFace.Connect (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/src/Device.js:56:13) at EventEmitter.<anonymous> (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/dbus-native/lib/bus.js:140:19) at EventEmitter.emit (events.js:187:15) at /home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/dbus-native/index.js:106:14 at Socket.<anonymous> (/home/pi/MagicMirror/modules/MMM-BluetoothDevices/node_modules/dbus-native/lib/message.js:55:9) at Socket.emit (events.js:182:13) at emitReadable_ (_stream_readable.js:540:12) (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:55:56.588] [ERROR] 11:55:56 <error> (node:23373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:55:56.593] [ERROR] 11:55:56 <error> (node:23373) UnhandledPromiseRejectionWarning: Software caused connection abort (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut) [11:55:56.599] [ERROR] 11:55:56 <error> (node:23373) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4) (/home/pi/MagicMirror/internal/process/warning.js:18 writeOut)
So… Software caused connection abort. Don’t know what that means unfortunately. Guess I need to learn a bit more about the connection process. But I get the feeling that this module is a bit too complex for just using with my toothbrush.
Let me know if you know my problem. -
@lavolp3 Check, I will update the docs, with more info soon.
Yeah promises could be really nice if implemented correctly, now debugging is a pain because the error logs are not as useful. I will make this better in the coming week.
When you hit the web interfase the node_helper is triggered, do you then have your brush on? Because when you start up the first time, alle the devices should be on and ready to connect.
-
I have tweaked the code a bit towards better exception handling, this might be helpful for you
-
Works great with my Oral B 9000!
Notes:
- I had to change the git clone to https instead of git clone git@github.com:timodejong95/MMM-BluetoothDevices.git
- Copying the file MMM.conf requires administrative rights
- I used bluetoothctl to find the MAC of the toothbrush
-
@djerik Nice! Good to hear, and thanks for the feedback I will update the readme where needed!
-
@timodejong95 Hi Timo, it works for me now as well. Very good!
So now let’s go for the holy grail! The battery status.
It is there and I managed to get it out using noble. Don’t ask me how. Lol.
Find the code below where I meddled with Advertisements and Characteristics: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('Found OralB Toothbrush with ID: ' + peripheral.id); console.log('ManufacturerData: '+ad.manufacturerData.toString('hex')); //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: "+characteristics); for (let i in characteristics) { var charUUID = characteristics[i].uuid; console.log(' ' + i + ' uuid: ' + charUUID); if (characteristics[i].uuid == "a0f0ff0550474d5382084f72616c2d42") { let j = i; characteristics[j].on('data', function(data, isNotification) { console.log("Data: "+data); var valueInt = data.readInt8(0); console.log("Battery: "+valueInt+"%"); }); /*characteristics[j].read(function(error, data) { if (data) { var valueInt = data.readInt8(0); console.log("Battery: "+valueInt+"%"); } });*/ characteristics[j].subscribe(function(error) { if (error !== null) { console.log("error", error); } }); } } }); }
I guess you can find the same using bluez?
If I find the time, I’ll also try out which way works better (for me).
Noble or your blues dbus way. I had several issues using noble but it had its charme (like the battery status :-) and only sending data when I activate or deactivate the brush) -
@timodejong95 nice that there was someone realizing this project at the end.
tried your app and getting a blank WHITE SCREEN.
so maybe u can help me troubleshooting1 cloned via https
2 did npm install
3 sudo cp MMM.conf
4 added conf including MAC (sidenote, white screen with wrong MAC address aswell)
5 paired the toothbrush via bluetoothtried to start mirror -> white screen, and whoops message in the log
any idea what could cause this? or where to start troubleshooting?
-
@lavolp3 Thanks for the code share and great to hear it works. This weekend I will spend some to see if I can fix it, I let you know.
@dfuerst Hmm oké, thats weird normally you would see a black screen. Doest the mirror work if you disable the plugin, if so what does the logs say?
FYI: I had some issues with my git commits so I deleted and recreated the repo, no worries it’s still under the same url and won’t go away.
-
@timodejong95 Hi Timo,
since I really want to have the battery status I am currently trying to use the front end code with noble as backend in node_helper. Your backend code and all the GATT bluez stuff is much too complicated for me.
Also, I have done some tweaks on the frontend:
- Hide timer after some time
- convert time to m:ss
- also count on beyond 2 minutes (circle is filled after 2 Minutes)
- make timer bright and circle blue when the brush is running and dim it back again if it is not running.
Like it very much. Very simple tweaks in the main.js. Let me know if you want to see any of it.
Also, two brushes work perfectly! :ok_hand:
Impressive work man!
-
Thanks I really appreciate that! Yeah sure I am willing to refactor it a bit, if needed, and make it a configurable option.
Again sorry for deleting the repo, I pushed wit the wrong git user (work one). I saw that you starred/forked it.Can you show me the changes or make a PR?
The GATT is a bit bugged I am not sure why but the services are not resolving. I am trying to fix that and I think that after that the battery status should be that hard anymore.