Recently I have been working on a project which requires presence detection and I wanted something fairly quick and easy to implement but still be highly customisable. Thanks to some inexpensive Bluetooth transceivers and the OwnTracks iOS/Android app, I have managed to implement reliable presence detection along with location tracking.
OwnTracks is a smartphone application designed to periodically push its location to an MQTT or HTTP server; it also supports iBeacon monitoring (iOS only) for sending notifications to the server whenever the device enters or leaves the range of an iBeacon. The full feature set of OwnTracks is available on their website: owntracks.org.
By running Mosquitto on one of my servers ‘in the cloud’ I had somewhere which OwnTracks could connect to in order to send/receive events. I also set up a second Mosquitto server at home (behind a NAT and firewall) which opens a connection to the first in bridge mode so that both servers have exactly the same data. By doing this I had a static IP address for OwnTracks and also didn’t have to worry about opening/forwarding ports on my home network. In addition to Mosquitto I am also running Node-Red to handle all of the messages to/from MQTT – this saved a lot of time as I didn’t have to write much code to process location events.
I now had periodic location updates from my phone to my server running Node-Red but was unable to determine which room of the house my phone was in. To get per-room accuracy I went on eBay to find the cheapest iBeacons possible; I knew it was possible to make them using Bluetooth transceivers and Arduinos or even a Bluetooth enabled Raspberry Pi but I wanted something small and portable hence why I decided to buy a prebuilt beacon. I found a module for sale for under £5 on eBay which appears to be a HM-11 (which is based on the Texas Instruments CC2541 SoC) mounted on a breakout board and has a CR2032 battery holder – it is specifically advertised as an iBeacon but it can do much more. Configuring this particular module was very easy because the UART pins are broken out and clearly labelled and the AT commands are listed on various websites which allowed me to change the iBeacon configuration.
The following AT commands worked for me:
AT+RENEW - Factory Reset AT - responds 'ok' when ready for commands AT+MARJ0x0001 - sets the iBeacon major value (0000-FFFF) AT+MINO0x0001 - sets the iBeacon minor value (0000-FFFF) AT+ADVI3 - sets the broadcasting interval (0-F) AT+ADTY3 - sets 'advertising only' mode to save power AT+IBEA1 - enables iBeacon mode AT+PWRM0 - enables 'auto sleep' to save power
The full list of AT commands can be found at www.elecrow.com.
The broadcast interval command
AT+ADVI (0-F) values are listed below:
0: 100ms 1: 152.5 ms 2: 211.25 ms 3: 318.75 ms 4: 417.5 ms 5: 546.25 ms 6: 760 ms 7: 852.5 ms 8: 1022.5 ms 9: 1285 ms A: 2000ms B: 3000ms C: 4000ms D: 5000ms E: 6000ms F: 7000ms
I chose ‘3’ or 318.75ms as my advertising interval and I’ve not experienced any problems. It seems that iBeacons should broadcast every 100ms according to the specs but unless you’re trying to get extreme precision it’s probably overkill and a waste of battery. I used the same UUID for all beacons and incremented the minor number between each so OwnTracks can determine which beacon it is receiving signals from.
Using these Bluetooth modules and OwnTracks would even make it possible to receive notifications whenever you’ve left something behind (similar to Tile Premium Smart Alerts, and other Bluetooth trackers) if you have a beacon attached to it. Perhaps the best part is the fact that all data goes through whichever servers you decide to use so you don’t have to trust 3rd party companies with your location data 24/7. I now have a fairly powerful setup for presence detection as I can simply add a node into Node-Red to be called whenever I enter/leave a specific iBeacon region.