MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    MMM-OralB / Bluetooth equipped toothbrush integration

    Scheduled Pinned Locked Moved Development
    68 Posts 13 Posters 35.2k Views 20 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C Offline
      CedericPrivat
      last edited by

      Someone on the Home Assistant Forum seems to have the code figured out:
      https://community.home-assistant.io/t/oral-b-bluetooth-connected-toothbrush/35595/10

      Is it now possible, to display the same information like the app does?

      1 Reply Last reply Reply Quote 0
      • lavolp3L Offline
        lavolp3 Module Developer
        last edited by

        Guys, I would like to relive this topic. Using the project from the home assistant guy( who even referenced us :-) ) and our combined effort we should be able to reach something, shouldn’t we?

        @SvenSommer are you still listening? :-) I’ve looked through your repository but have not found a final implementation of a timer. There is still no server-client communication, or have I overseen something?

        The problem is still that every toothbrush version may behave a bit differently but having at least a timer on the mirror and maybe even a bit more (battery status) after that would be a big win.

        So while I’m trying to understand this code https://github.com/rfaelens/domotica/blob/master/mqtt-toothbrush.py which should present at least part of the solution, I’m happy for everyone who joins the effort to make toothbrushing great again!!

        How to troubleshoot modules
        MMM-soccer v2, MMM-AVStock

        lavolp3L 1 Reply Last reply Reply Quote 0
        • lavolp3L Offline
          lavolp3 Module Developer @lavolp3
          last edited by

          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+"%")
                      }
                  });
                }
              }
            });
          }
          
          

          How to troubleshoot modules
          MMM-soccer v2, MMM-AVStock

          SvenSommerS 1 Reply Last reply Reply Quote 0
          • SvenSommerS Offline
            SvenSommer @lavolp3
            last edited by

            @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.

            Looking for some building inspiration?
            Check out my large, thin and metal framed mirror on robstechlog.com.

            Modules released:
            MMM-GoogleAnalytics
            MMM-GrafanaChart
            MMM-GrafanaGauges

            lavolp3L 1 Reply Last reply Reply Quote 0
            • lavolp3L Offline
              lavolp3 Module Developer @SvenSommer
              last edited by

              @SvenSommer Thanks Sven and good you’re back on this :-)

              I have one question on noble I can’t figure out.
              with noble.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?

              How to troubleshoot modules
              MMM-soccer v2, MMM-AVStock

              lavolp3L 1 Reply Last reply Reply Quote 0
              • lavolp3L Offline
                lavolp3 Module Developer @lavolp3
                last edited by

                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

                How to troubleshoot modules
                MMM-soccer v2, MMM-AVStock

                1 Reply Last reply Reply Quote 0
                • T Offline
                  timodejong95
                  last edited by

                  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.

                  lavolp3L 1 Reply Last reply Reply Quote 1
                  • lavolp3L Offline
                    lavolp3 Module Developer @timodejong95
                    last edited by

                    @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: "" }
                            ]
                          }
                        },
                    
                    

                    How to troubleshoot modules
                    MMM-soccer v2, MMM-AVStock

                    lavolp3L 1 Reply Last reply Reply Quote 0
                    • lavolp3L Offline
                      lavolp3 Module Developer @lavolp3
                      last edited by

                      @lavolp3 Also mentioning in the Readme that npm install is necessary would be helpful

                      How to troubleshoot modules
                      MMM-soccer v2, MMM-AVStock

                      1 Reply Last reply Reply Quote 0
                      • lavolp3L Offline
                        lavolp3 Module Developer
                        last edited by lavolp3

                        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

                        How to troubleshoot modules
                        MMM-soccer v2, MMM-AVStock

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          timodejong95
                          last edited by timodejong95

                          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.

                          lavolp3L 2 Replies Last reply Reply Quote 0
                          • lavolp3L Offline
                            lavolp3 Module Developer @timodejong95
                            last edited by lavolp3

                            @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.

                            How to troubleshoot modules
                            MMM-soccer v2, MMM-AVStock

                            1 Reply Last reply Reply Quote 0
                            • lavolp3L Offline
                              lavolp3 Module Developer @timodejong95
                              last edited by lavolp3

                              @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.

                              How to troubleshoot modules
                              MMM-soccer v2, MMM-AVStock

                              T 1 Reply Last reply Reply Quote 0
                              • T Offline
                                timodejong95 @lavolp3
                                last edited by

                                @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.

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  timodejong95
                                  last edited by

                                  I have tweaked the code a bit towards better exception handling, this might be helpful for you

                                  1 Reply Last reply Reply Quote 0
                                  • D Offline
                                    djerik
                                    last edited by

                                    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
                                    T 1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      timodejong95 @djerik
                                      last edited by

                                      @djerik Nice! Good to hear, and thanks for the feedback I will update the readme where needed!

                                      lavolp3L D 2 Replies Last reply Reply Quote 0
                                      • lavolp3L Offline
                                        lavolp3 Module Developer @timodejong95
                                        last edited by lavolp3

                                        @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)

                                        How to troubleshoot modules
                                        MMM-soccer v2, MMM-AVStock

                                        T 1 Reply Last reply Reply Quote 0
                                        • D Offline
                                          dfuerst @timodejong95
                                          last edited by

                                          @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 troubleshooting

                                          1 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 bluetooth

                                          tried to start mirror -> white screen, and whoops message in the log

                                          any idea what could cause this? or where to start troubleshooting?

                                          1 Reply Last reply Reply Quote 0
                                          • T Offline
                                            timodejong95 @lavolp3
                                            last edited by timodejong95

                                            @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.

                                            lavolp3L 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 2 / 4
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy