LM as Bluetooth 4.0 gateway
Example: LogicMachine as Bluetooth 4.0 Low Energy gateway
Task
Interconnect LogicMachine with Mio Alpha watch and map heart-rate measurement to KNX group address. Upon excessing specific heart-rate measurement, switch on ventilation on group address 2/2/2. In same way any other Bluetooth LE 4.0 sensor with open API or iBeacon can be integrated with any supported standard by LogicMachine.
Some of supported Bluetooth 4.0 USB adapters
- Broadcom BCM20702A0
- Trust 18187
- Belkin F8T065bf
- Plugable USB Bluetooth 4.0
- Laird BT820
We will use Laird BT820 in this demo.
Install BLE packages on your LogicMachine
You need to install these packages first, the reboot:
libbluetooth
luable
genohm-scada-ble
You can download them in additional packages section on this page.
Add 1byte object 1/1/1 in Objects menu
Add the following code to Resident script with interval = 0 seconds
- if proc then
- line = proc:read()
- parseline(line)
- else
- mac = 'D7:2D:DA:DF:E4:34' -- MAC of AlphaMio watch
-
- -- bring bt interface up
- os.execute('hciconfig hci0 up')
- os.sleep(2)
-
- -- read heart rate data
- proc = io.popen('gatttool -b ' .. mac .. ' -t random --char-write-req -a 0x0025 -n 0100 --listen')
- count = 0
-
- function parseline(line)
- local pos, rate
-
- -- invalid data
- if not line then
- return
- end
-
- -- find value marker
- pos = line:find('value: ', 1, true)
- if not pos then
- return
- end
-
- -- get current heart rate
- rate = tonumber(line:sub(pos + 10, pos + 11), 16)
-
- -- send each 5 reads
- count = count + 1
- if count == 5 then
- grp.update('1/1/1', rate)
- count = 0
- end
- end
- end
Add event-based script heart-rate object 1/1/1
This script will switch on ventilation if the heart-rate is >80 and switch off if its lower.
- value = event.getvalue()
- if value > 80 then
- grp.write('2/2/2', true)
- else
- grp.write('2/2/2', false)
- end
Other Bluetooth watches integration
LM can support the Bluetooth devices which manufacturer is not hiding data encryption, which we can decode. For example:
- Xiaomi Mi Band: easy to connect, has acceleroemeter on-board which can be used for gesture control, and price $13!! Also, important is that it works in broadcast mode – sends reading to all and the receivers which understand what is received, do decryption
Notes:
- Taking into account that Bluetooth devices are quite cheap, we expect that in the close future it will be integrated in most home appliance devices – irons, kettles etc. so we can receive status from them and maybe switch off remotely.
- Problem with watches which are launched by Apple or Android are using OSes which are over-complicated / bloatware, thus consuming much energy. For example, MIO can work 3 months without charging.
- Watch should be set of sensors, and not replace or compete with smartphone.
- Plus if we compare Bluetooth Low Energy watches with Apple iBeacon system, e.g. Xiaomi-like devices which are sending broadcast all the time and we can count for example, count of people inside the warehouse; iBeacon – we don’t see its activity, we need to activate them by app first and information is sent by WiFi.