Yup I found it. Scan and tell who’s discoverable. No use whatsoever to the outside world (that I’m aware of) but the basis of some funky retail marketing startup who think Bluetooth might be the way forward.
First of all if you haven’t got a Bluetooth dongle get yourselves to Tesco and buy their little Technik nano bluetooth dongle for a fiver. Works a treat.
Back to the Pi…
apt-get install bluetooth
Have a couple of games of Mario Kart or make a drink while it installs. Could take a while.
Twitter OAuth in R
If you were reading the Pi Twitter Sentiment Server posts then you’ll have all this set up. If not you can read it here. One thing you need to do is make sure your Twitter developer app can read/write to Twitter.
Scanning Bluetooth Devices
From the command line all you need to run (as root) is:
And it will produce a list of the MAC address and the name of the device.
We can run within R….
So, all together.
load("/path/to/credentials/RData") registerTwitterOAuth(cred) t<-try(system("hcitool scan", intern=TRUE)) ts<-strsplit(t,"\t") tweet(paste("Test BT Scan: ",ts[]))
The strsplit command will give you a two dimensional vector with three elements: space, MAC address and the discoverable name. So [] means give me value of the second row and third column of the vector.
Taking it from here.
Plenty of scope from here to save the MAC addresses to a datastore so the same names don’t keep appearing everytime the scan happens. Also if you read back on previous posts you’ll see it’s easy to knock up a cron job to run this every ten minutes or so.
It looks like the hcitool caches the scan for at least 30 seconds so there’s no use pounding the scanning for new devices for any duration less than that.