Read the statement by Michael Teeuw here.
Toothbrush integration
-
ok integrated “hcitool con”, because of the very fast response,
had to alter the parsing of NetworkScanner.
i think i got the parsing, but networkscanner says NO DEVICES
when i “console.log(macAddresses)” , at the end of node_helper script i get during MM in console :MMM-NetworkScanner received SCAN_NETWORK MMM-NetworkScanner is scanning for mac addresses [ ‘E0:E5:CF:FC:4D:8C’ ]shouldn’t this “macAddresses parse” be understand by NetworkScanner? What am i missing here?
nodehelper script is as follows:
scanNetwork: function() { console.log(this.name + " is scanning for mac addresses"); var self = this; var arp = sudo(['hcitool', 'con']); var buffer = ''; var errstream = ''; arp.stdout.on('data', function (data) { buffer += data; }); arp.stderr.on('data', function (data) { errstream += data; }); arp.on('error', function (err) { errstream += err; }); arp.on('close', function (code) { if (code !== 0) { console.log(self.name + " received an error running arp-scan: " + code + " - " + errstream); return; } //Parse the response var rows = buffer.split('\n'); var macAddresses = []; // HCI-TOOL SCAN table for (var i = 1; i < rows.length; i++) { var cells = rows[i].split(' ').filter(String); if (cells[2] && macAddresses.indexOf(cells[2].toUpperCase()) === -1) { macAddresses.push(cells[2].toUpperCase()); } } self.sendSocketNotification('MAC_ADDRESSES', macAddresses); console.log(macAddresses); }); }
Note from admin: Please use Markdown on code snippets for easier reading!
-
@dfuerst Hey, I liked your approach how to get the information about a running or a stopped toothbrush.
So, I played some time with hcitool within the console and checked the responsive times(if the toothbrush is beeing detected as connected or not, as a turn it on or off). Unfortunately, this wasn’t very reliable nor very accurate.I would suggest a better approach is to use a javascript library for bluetooth such as noble to track if the toothbrush is connected or not.
Unfortunately I wasn’t able to get noble running within the MagicMirror framework. I tried to install it with npm anbd several versions of node.js (6.x and 7.x) but got always an error like "Error: Module version mismatch. Expected 50, got 51." within the bluetooth-hci-socket - part of noble.Starting MagicMirror: v2.1.0 Loading config ... Loading module helpers ... No helper found for module: alert. No helper found for module: clock. WARNING! Could not load config file. Starting with default configuration. Error found: Error: Module version mismatch. Expected 50, got 51. Loading module helpers ... No helper found for module: alert. No helper found for module: clock. App threw an error during load Error: Module version mismatch. Expected 50, got 51. at Error (native) at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20) at Object.Module._extensions..node (module.js:583:18) at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Object. (/home/pi/MagicMirror/modules/MMM-OralB/node_modules/bluetooth-hci-socket/lib/native.js:3:15) Whoops! There was an uncaught exception... Error: Module version mismatch. Expected 50, got 51. at Error (native) at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20) at Object.Module._extensions..node (module.js:583:18) at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Object. (/home/pi/MagicMirror/modules/MMM-OralB/node_modules/bluetooth-hci-socket/lib/native.js:3:15)I tried rebuilding the noble included packeages and tried it also with a clean Magicmirror installation under node.js 7.x. unfortunately nothing helped.
-
@SvenSommer
hi. nice to know that someone else (with programming skills) is interested too.ohh yes . ‘hcitool con’ is not perfect, first activation of the toothbrush is very accurate but as you mentioned any interruption is detected unreliably, and late.
your problem sounds like the “white screen” issue of mmm-button, so maybe rebuilding/downgrading your electron version might help. (see the forum for this issue)
as you can see in the posts above there is an API by OralB. At the end using it would give the highest quality of input/output. as you can also read between the lines i dont know enough about coding stuff, so i went for the low level approach via mmm-networkscanner and to integrate thereafter a simple stopwatch.
Any help is highly welcome.
-
I already had a look to the API provided by OralB. It’s quite disappointing.
They will provide you with classes to develop tools for android or ios apps. Not what we are looking for right now. :wink:
But maybe the documentation could be usefull.I tried to find the forum page you mentioned. Found nothing usefull yet. Maybe you can have a look and help me out here.
I made a first attempt with noble and got some pretty nice results by reading out the braodcasted information from my brush.
I you wanna try on your own, do the following:
- Install noble in a directory of your choice, by following the instructions on the noble page:
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-devsudo ln -s /usr/bin/nodejs /usr/bin/nodenpm install noble- Move into the new node_modules/noble/ - folder and create a new file ‘toothbrush.js’ with the following content
var async = require('async'); var noble = require('./index'); var OralB_manufacturerData = 'dc00010205030000000101'; console.log('Lookinhg for OralB Toothbrushes with manufacturerData: "' + OralB_manufacturerData +'"'); noble.on('stateChange', function(state) { if (state === 'poweredOn') { noble.startScanning(); } else { noble.stopScanning(); } }); noble.on('discover', function(peripheral) { var advertisement = peripheral.advertisement; console.log('Found device with manufacturerData: "' + advertisement.manufacturerData.toString('hex') +'" localName: ' + advertisement.localName); if (advertisement.manufacturerData.toString('hex') === OralB_manufacturerData) { noble.stopScanning(); console.log('peripheral with ID ' + peripheral.id + ' found'); var localName = advertisement.localName; var txPowerLevel = advertisement.txPowerLevel; var manufacturerData = advertisement.manufacturerData; var serviceData = advertisement.serviceData; var serviceUuids = advertisement.serviceUuids; if (localName) { console.log(' Local Name = ' + localName); } if (txPowerLevel) { console.log(' TX Power Level = ' + txPowerLevel); } if (manufacturerData) { console.log(' Manufacturer Data = ' + manufacturerData.toString('hex')); } if (serviceData) { console.log(' Service Data = ' + serviceData); } if (serviceUuids) { console.log(' Service UUIDs = ' + serviceUuids); } console.log(); explore(peripheral); } }); function explore(peripheral) { console.log('services and characteristics:'); peripheral.on('disconnect', function() { process.exit(0); }); peripheral.connect(function(error) { peripheral.discoverServices([], function(error, services) { var serviceIndex = 0; async.whilst( function () { return (serviceIndex < services.length); }, function(callback) { var service = services[serviceIndex]; var serviceInfo = service.uuid; if (service.name) { serviceInfo += ' (' + service.name + ')'; } console.log(serviceInfo); service.discoverCharacteristics([], function(error, characteristics) { var characteristicIndex = 0; async.whilst( function () { return (characteristicIndex < characteristics.length); }, function(callback) { var characteristic = characteristics[characteristicIndex]; var characteristicInfo = ' ' + characteristic.uuid; if (characteristic.name) { characteristicInfo += ' (' + characteristic.name + ')'; } async.series([ function(callback) { characteristic.discoverDescriptors(function(error, descriptors) { async.detect( descriptors, function(descriptor, callback) { return callback(descriptor.uuid === '2901'); }, function(userDescriptionDescriptor){ if (userDescriptionDescriptor) { userDescriptionDescriptor.readValue(function(error, data) { if (data) { characteristicInfo += ' (' + data.toString() + ')'; } callback(); }); } else { callback(); } } ); }); }, function(callback) { characteristicInfo += '\n properties ' + characteristic.properties.join(', '); if (characteristic.properties.indexOf('read') !== -1) { characteristic.read(function(error, data) { if (data) { var string = data.toString('ascii'); characteristicInfo += '\n value ' + data.toString('hex') + ' | \'' + string + '\''; } callback(); }); } else { callback(); } }, function() { console.log(characteristicInfo); characteristicIndex++; callback(); } ]); }, function(error) { serviceIndex++; callback(); } ); }); }, function (err) { peripheral.disconnect(); } ); }); }); }- Start the script by with
sudo node toothbrush.jsHere is what I got:
Lookinhg for OralB Toothbrushes with mac address:54:4a:16:21:20:9f peripheral with ID 544a1621209f found Manufacturer Data = dc00010205020000000101 Service Data = Service UUIDs = services and characteristics: 1800 (Generic Access) 2a00 (Device Name) properties read value 4f72616c2d4220546f6f74686272757368 | 'Oral-B Toothbrush' 2a01 (Appearance) properties read value 0000 | '' 2a02 (Peripheral Privacy Flag) properties read, write value 00 | '' 2a03 (Reconnection Address) properties read, write value 000000000000 | '' 2a04 (Peripheral Preferred Connection Parameters) properties read value 5000a0000000e803 | 'P h' 1801 (Generic Attribute) 2a05 (Service Changed) properties indicate a0f0fff050474d5382084f72616c2d42 a0f0fff150474d5382084f72616c2d42 (Command) properties read, write, notify value 00 | '' a0f0fff250474d5382084f72616c2d42 (Data) properties read, write value 00000000 | '' a0f0fff350474d5382084f72616c2d42 (Auth) properties read, write value 00 | '' a0f0fff450474d5382084f72616c2d42 (Secret) properties read, write value 00000000 | '' a0f0ff0050474d5382084f72616c2d42 a0f0ff0150474d5382084f72616c2d42 (Handle ID) properties read value 00000000 | '' a0f0ff0250474d5382084f72616c2d42 (Handle Type) properties read value 02 | '' a0f0ff0350474d5382084f72616c2d42 (User Account) properties read value 01 | '' a0f0ff0450474d5382084f72616c2d42 (Device State) properties read, notify value 0200 | '' a0f0ff0550474d5382084f72616c2d42 (Battery Level) properties read, notify value 63 | 'c' a0f0ff0650474d5382084f72616c2d42 (Button State) properties read, notify value 00000000 | '' a0f0ff0750474d5382084f72616c2d42 (Brushing Mode) properties read, notify value 01 | '' a0f0ff0850474d5382084f72616c2d42 (Brushing Time) properties read, notify value 0000 | '' a0f0ff0950474d5382084f72616c2d42 (Quadrant) properties read, notify value 00 | '' a0f0ff0a50474d5382084f72616c2d42 (Smiley) properties read, notify value 00 | '' a0f0ff0b50474d5382084f72616c2d42 (Pressure Sensor) properties read, notify value 00 | '' a0f0ff0c50474d5382084f72616c2d42 (Cache) properties read, write, notify value | '' a0f0ff2050474d5382084f72616c2d42 a0f0ff2150474d5382084f72616c2d42 (Status) properties read, write, notify value 8100 | '' a0f0ff2250474d5382084f72616c2d42 (RTC) properties read, write value 97d81120 | 'X ' a0f0ff2350474d5382084f72616c2d42 (Timezone) properties read, write ' value 0d | ' a0f0ff2450474d5382084f72616c2d42 (Brushing Timer) properties read, write value 0f | '' a0f0ff2550474d5382084f72616c2d42 (Brushing Modes) properties read, write value 0105020403000000 | '' PuTTY a0f0ff2650474d5382084f72616c2d42 (Quadrant Times) properties read, write value 1e001e001e001e000000000000000000 | '' a0f0ff2750474d5382084f72616c2d42 (Tongue Time) properties read, write value 00 | '' a0f0ff2850474d5382084f72616c2d42 (Pressure) properties read, write value 03 | '' a0f0ff2950474d5382084f72616c2d42 (Data) properties read value 68d6fd1f7700010100000063d1e7fd1f | 'hV}wcQg}' a0f0ff2a50474d5382084f72616c2d42 (Flight Mode) properties read, write value 00 | '' -
try :
cd ~/MagicMirror/modules/MMM-Button sudo npm rebuild --runtime=electron --target=1.4.6 --disturl=https://atom.io/download/atom-shell --abi=50 -
not in the mmmbutton folder of course
-
@dfuerst It worked! Thank you very much!!
-
exciting.
you get everything needed for a really high quality piece of module.battery level
brushing mode
brushing time
pressure
quadrant
smileyi am a bit concerned about the user readout. (Do you think it might be possible to determine which of eg. 3 brushes is presently used?)
-
Hey,
I have bad news.The readable informations provided by the brush via bluetooth aren’t changing. Not while the toothbrush is running. I guess the characteristics we were able to readout, are used like placeholder for the sdk.
Second try was to get notified if a broadcastd value (characteristic) is changing. Nothing here either.
Every characteristic (like brushing time, battery level, etc) is using the same id and only provides a different name. So a notification service wasn’t possible.Seems like there is no way to get the information read out via bluetooth without using the sdk…
I also tried to include the provided sdk into the MM-framework.
Therefore I had a try with node-java, which allows to run java classes within nodejs. The files from the android sdk are java classes.It went pretty nice in the beginning. But then I ran into an error
‘Expected stackmap frame at this location.’ which is caused by the compiling the sdk classes on another system (linux not android), I would assume.I was amazed that I wasn’t able to find any code snippets of frameworks from other developers to “hack the brush” when I first started. By now its seems obvious that it’s not that easy.
If anybody else is gonna have a try, please don’t hesitate to ask if you need assistance.
-
should we go back to the “low level approach”?
as i understand you can instantly determine if there is a certain brush(matching the macaddress via the config) within the bluetooth range upon activation of these.
any interruption of brushing is detected, 20 sec or so too late of course i know, when the brush goes offline again.
so can we start a stopwatch (let’s say at the center position) upon detection, stopping when not detecting the brush anymore and reseting to 00:00 after 2min followed by vanishing the stopwatch.
i know that this wouldn’t be very accurate, but better then nothing. giving the user a feel for the time
and for a pro like you i guess this would be very easy to develop.
examples for start/stop/reset timers are quiet a lot available in the web.how do you think about
-
maybe contacting oralB via the developer program homepage ( https://developer.oralb.com/ ) could be helpful. there might be a support team helping developers creating new apps for their brush
-
Hey,
guided by the idea of your simple approach I wrote a little script which tries to detect, if the brush is running or not.
Caused by the bluetooth behavior of the brush it is very limited in guessing when the brush was stopped or resumed.
Here are some details:- If the toothbrush is started bluetooth is activated for 3 Seconds.
- If the brush is paused/stopped bluetooth is activated again for 32 Seconds.
This leads to the following limited possiblities in tracking a brush session.
- A start of a session is only trackable, if the programm/script has started with a (for 32 seconds) silent brush.
- A stop is only trackable 3 seconds after start.
- A stop/pause leads to a 32 Seconds “cooldown phase”, were no tracking is possible. This will reset the timer to 0:00.
This is only helpfull if you do not interrupt you brushing session. :smile:
If you wanna try the current setup you can run the script by:
- Enter your module-directory:
cd ~/MagicMirror/modules - Clone repository :
git clone https://github.com/SvenSommer/MMM-OralB - Enter new directory:
cd ~/MagicMirror/modules/MMM-OralB - Install dependencies:
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev - Install noble module:
npm install noble - Exceute helper programm to find your brushID (this is not the mac-address):
sudo node findBrushId.js
This should lead to a output like
Searching for OralB Toothbrushes with manufacturerData: "dc00010205030000000101"... changed state to:poweredOn Found OralB Tootbrush with ID: 544a1621209f- Copy and paste your ID into the brushTimer.js file:
sudo nano brushTimer.js
(Save and exit with STRG + O and STRG + X )
"use strict"; var NodeHelper = require("node_helper"); var noble = require('noble'); //Copy Paste your ID here var toothbrush_uuid = '544a1621209f';- Run script with
sudo node brushTimer.js
This should lead to an output like:
scanning started... Toothbrush is running 0:1 0:2 0:3 0:4 0:5 0:6 0:7 0:8 0:9 0:10 0:11 0:12 0:13 0:14 0:15 0:16 0:17 0:18 Toothbrush stopped. "Cool down" for 32 seconds needed! -
Wow that was really fast!
Testing your script brought me to 2 problems:
testing brushTimer.js in the console worked for detecting the brush but did never stop, also not after 32 sec!
including your module into the MM i got an error message upon activating the brush:
“noble warning: unknown handle 64 disconnected!”
“scanning was started. Everything is working fine.”this two message’s i get upon every activation, so the MM show always SEARCHING…
any suggestions?
-
Now i made a reinstall.
brushtimer.js works until i rebuild electron!!!
but without rebuilding MM just shows the white screen error.after rebuilding i get this upon
sudo node brushTimer.js:pi@raspberrypi:~/MagicMirror/modules/MMM-OralB $ sudo node brushTimer.js module.js:597 return process.dlopen(module, path._makeLong(filename)); ^ Error: Module version mismatch. Expected 48, got 50. at Error (native) at Object.Module._extensions..node (module.js:597:18) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (/home/pi/MagicMirror/modules/MMM-OralB/node_modules/bluetooth-hci-socket/lib/native.js:3:15) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10)so, after this rebuild i get the error of my previous post in MM
-
@dfuerst
Module version mismatch-Error
Just to summarize and for clarification:
TheModule version mismatch. Expected 48, got 50
or
NODE_MODULE_VERSION 50. This version of Node.js requires
NODE_MODULE_VERSION 51. Please try re-compiling or re-installing
is a known “bug”, which we were able to solve by the rebuilding of electron as you posted a few days ago.So if you want to use the module in MM you have to use this statement in the MMM-OralB-folder:
sudo npm rebuild --runtime=electron --target=1.4.6 --disturl=https://atom.io/download/atom-shell --abi=50If you want to test brushtimer.js-script standalone in the console, you need to build the packeges in the MMM-OralB-folder with
npm rebuildBehavior of brushTimer.js script
So if I understood you correctly, you were able to start the timer, but it never stopped?
For a better understanding I added some debug information in the brushtimer.js -script. Cut you please trigger an update bycd ~/MagicMirror/modules/MMM-OralB git pulland try the following scenarios and provide me with the console output text.
- Start the Brush; wait like 10 seconds and stop.
- Start and stop within 3 seconds.
- Start, wait like 10 seconds and stop. Start again within the next 10 seconds for like 5 seconds.
- Start, wait like 10 seconds and stop. Start again after 40 seconds and stop whenever you like.
Behavior of the module within the MM-framework
You wrote:“noble warning: unknown handle 64 disconnected!” “scanning was started. Everything is working fine.” this two message’s i get upon every activation, so the MM show always SEARCHING…"Actually this behavior is the intended action right now. As I wrote in this Bug Hunt Post I have problems in bringing noble alive within MM²-framework.
Surprisingly you aren’t suffering from this error, so could you please tell me:- Which platform (Rasperry Pi 2/3, etc.),
- Node - version:
node --version - npm - version:
npm --version - MagicMirror:
cd ~/MagicMirror/andDISPLAY=:0 npm start
you are using?
-
of course, i used the electron downgrade. obviously i didn’t know that i have to enter " npm rebuild" to test the .js, sorry for that.
you understood me correct. the timer never stopped, i will check that again after git pull
as i 'm abroad till monday i will provide this infos to you on monday.
you wrote the error is the xpected behaviour? as i mentioned MM showed just SEARCHING…many thanks for your effort
-
For the Bug Hunt Post I reduced the code of the MM-scripts to a absolute minmum.
That’s the reason the module is always showing ‘SEARCHING…’ right now.If the scripts would work as exspected the console output would show
scanning was started. Everything is working fine.all the time the MM² is started.
Thats all I’m hoping to see right now. -
ok. i understand. full reply on monday
-
RPi3
NODE : v6.9.2
NPM: 3.10.9
MagicMirror@2.0.0 -
scenario 1:
scanning started…
Toothbrush connection ALIVE atMon Jan 30 2017 17:12:15 GMT+0100 (CET)
Toothbrush is running
0:1
0:2
Toothbrush connection LOST at Mon Jan 30 2017 17:12:17 GMT+0100 (CET) was alive since Mon Jan 30 2017 17:12:15 GMT+0100 (CET)
two input in less than 3 sec! (2 sec) => ignoring input!
0:3
0:4
0:5
endless countingscenario 2:
scanning started…
noble: unknown peripheral e0e5cffc4d8c connected!
noble: unknown peripheral e0e5cffc4d8c disconnected!
Toothbrush connection ALIVE atMon Jan 30 2017 17:14:25 GMT+0100 (CET)
Toothbrush is running
0:1
0:2
Toothbrush connection LOST at Mon Jan 30 2017 17:14:28 GMT+0100 (CET) was alive since Mon Jan 30 2017 17:14:25 GMT+0100 (CET)
two input in less than 3 sec! (2 sec) => ignoring input!
0:3
0:4
0:5
0:6
endless countingscenario 3:
same result as in scenario1
scenario 4:
same result as in scenario1
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