livebox:hah_hahnode:bluenode

This is an old revision of the document!


BlueNode

Integration of a BlueTooth sensor onto a JeeNode for the purposes of detecting devices as they come into, and go out of, range so that events can be triggered.

The BlueTooth unit is connected to a JeeNode and it will perform an inquiry check for available devices every 30 seconds. As each device reports in its device ID will be transmitted via the RFM12B. A total of 6 bytes are needed to represent the 48 bit address, to a receiving unit.

On the receiver side the RF is decoded and transmitted as an ASCII string out the serial port for decoding.

xap_serial will pickup the serial transmission from our receiver node and transmit this data as an xAP message for decoding.

The decoder is an Lua applet that creates a BSC endpoint dynamically sending a xAPBSC ON event when the device is first registered. As long as the device updates itself within 35 seconds, the endpoint will remain alive. When the device moves out of range a reaper will take care of expiring the endpoint sending an xAPBSC OFF event and removing the endpoint.

These on/off events can then be used by other scripts to drive an action.

A packet will arrive on the Receiver. The first byte is the sender node ID, in this case its node 18. The remaining data is the Device ID packed into 6 bytes.

[HAHCentral.1]1 g212 @ 868Mhz
OK 18 18 0 55 18 9 233

This message will be picked up by xap-serial and transmitted as an xAP packet for something to decode

xap-header
{
v=12
hop=1
uid=FF00DD00
class=serial.comms
source=dbzoo.livebox.serial
}
Serial.Received
{
port=/dev/ttyUSB0
data=OK 18 18 0 55 18 9 233
}

That something doing the decoding is an applet running inside plugboard.

We are running the Lua decoder in debug mode so the lifecycle of an endpoint can be seen.

Loading jeenodeApplet.lua                [ JeeNode ]
build BlueNode[18]
Running...
{
  data = "OK 18 18 0 55 18 9 233",
  port = "/dev/ttyUSB0"
}
process BlueNode[18]
        12:37:e90912=on
BlueNode reaper 12:37:e90912 alive=true ttl=35 timeout=4
BlueNode reaper 12:37:e90912 alive=true ttl=35 timeout=14
BlueNode reaper 12:37:e90912 alive=true ttl=35 timeout=24
BlueNode reaper 12:37:e90912 alive=true ttl=35 timeout=34
BlueNode reaper 12:37:e90912 alive=true ttl=35 timeout=44
expire 12:37:e90912

When a new bluetooth device is decoded the following endpoint is created and the state is set to ON, to indicate that its presence is known. The source xAP address will be dynamically created based on the device ID if a named address has not been defined.

A bluetooth device address breaks down like this: NAP:UAP:LAP
Each Bluetooth device is assigned a 48-bit address consisting of three parts: a 24-bit lower address part (LAP), an 8-bit upper address part (UAP), and a 16-bit so-called non-significant address part (NAP).
As a : has special meaning when used as part of the xAP address we translate the address 12:37:e90912 to 12.37.e90912 when creating the endpoint.

xap-header
{
v=12
hop=1
uid=FF00D801
class=xAPBSC.event
source=dbzoo.wombat.bluetooth:presence.12.37.e90912
}
input.state
{
state=on
displaytext=12:37:e90912
}

All going well you should see an endpoint dynamically appear in xFXViewer when your Bluetooth device comes into range.

Wiring for JeeNode/Hahnode/Arduino

Arduino Port 1 HC-05
Digital 4 D RX
Digital 3 I TX
Analog 0 A KEY
3.3v + 3.3V
GND GND GND
5v (NC) P (NC) 5v (NC)

We don't connect the 5v pins together, 3.3v is sufficient.

The source code for the SKETCH is call BlueNode there is also a useful terminal emulator that uses the Arduino as a passthrough device.

The LUA decoder logic is found in bluenode.lua or on your HAH system in /usr/share/lua/5.1/xap

The decoder can operate in two modes; named device endpoints or dynamically created. Each are setup and configured in your /etc/plugboard/jeenodeApplet.lua configuration file.

Step 1 - Make sure you are include the BlueNode class decoder.

module(...,package.seeall)
local monitor = require("xap.jeenode").monitor
RoomNode = require("xap.roomnode").RoomNode
BlueNode = require("xap.bluenode").BlueNode

Step 2 - Assign the remote node ID to this BlueNode class, choose use dynamic or static endpoints.

If you omit the endpoints table defintion all devices will derive their xAP source addresses dynamically. This snippet is for a static configuration as we have named the devices. Those devices not configured will be created with computed endpoint names.

In this example our remote node is configure as 18 and we have setup two known bluetooth devices.

-- Keyed by NODE ID
local nodes = {
   [18] = BlueNode{instance="bluetooth:presence",
                   endpoints={
                    ["1d:fe:720479"] = "brett.1",
                    ["12:37:e90912"] = "brett.2",
                   }
                }
}

This is a dynamic configuration and it will be your starting configuration until you know what your Bluetooth device ID's are.

local nodes = {
   [18] = BlueNode{instance="bluetooth:presence"}
}
  • livebox/hah_hahnode/bluenode.1389046110.txt.gz
  • Last modified: 2014/01/06 22:08
  • by brett