Skip to content

Instantly share code, notes, and snippets.

@dnknth

dnknth/README.md Secret

Created March 13, 2019 14:24
Show Gist options
  • Save dnknth/13698a08ecf5ee5e1903b040c41a601b to your computer and use it in GitHub Desktop.
Save dnknth/13698a08ecf5ee5e1903b040c41a601b to your computer and use it in GitHub Desktop.
Bluetooth presence detection

Simple occupancy detection via Bluetooth

This flow checks whether a Bluetooth device is in range. It does not require BT pairing because name lookups are allowed on any device. Tested on a Raspberry Pi 3 with the integrated BT receiver and some cellphones.

Usage

  • For Raspian, install hcitool with sudo apt-get install bluez
  • Verify that BT works, e.g. with hciconfig
  • The user running Node-RED must be a member of the bluetooth group, e.g. sudo usermod -a -G bluetooth nodered
  • Replace the MAC in the cellphone node with the target device's MAC. If unsure where to find it, make the device discoverable and do hcitool scan
[
{
"id": "a2aa8fbd.4cf9c8",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "f01d11e6.a3026",
"type": "exec",
"z": "a2aa8fbd.4cf9c8",
"command": "/usr/bin/hcitool",
"addpay": true,
"append": "",
"useSpawn": "false",
"timer": "10",
"oldrc": false,
"name": "bt presence",
"x": 350,
"y": 160,
"wires": [
[
"124fdc39.b4a09c"
],
[],
[]
]
},
{
"id": "124fdc39.b4a09c",
"type": "function",
"z": "a2aa8fbd.4cf9c8",
"name": "nonempty",
"func": "msg.payload = msg.payload ? 1 : 0;\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 520,
"y": 160,
"wires": [
[
"df8114bf.397578"
]
]
},
{
"id": "df735f89.216f8",
"type": "inject",
"z": "a2aa8fbd.4cf9c8",
"name": "cellphone",
"topic": "",
"payload": "name 84:B1:53:E3:8A:18",
"payloadType": "str",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 180,
"y": 160,
"wires": [
[
"f01d11e6.a3026"
]
]
},
{
"id": "df8114bf.397578",
"type": "debug",
"z": "a2aa8fbd.4cf9c8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 680,
"y": 160,
"wires": []
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment