a tool to distribute data for bluetooth beacons

The ruuvi bluetooth environment sensor tag has a myriad of uses. Unfortunately many people find it difficult to accesss the data because of the bluetooth protocol.

jakoavain is a simple tool to distribute the data collected by a beacon to the file domain on nearly any system.
This allows people with no bluethooth or network experience to work on their favorite system with their favorite language to make useful applications.

How it works

  1. hcitool and hcidump utilities catch the bluetooth packets.
  2. The packets from the beacons of interest are selected
  3. logger forwards the packet data to syslog. This system includes the ability to send data to a file, optionally on another system. It is robust enough to permit storing the data in a file and includes a utility ( newsyslog or logrotate) to archive & compress or expire files based on size or age.
    There are versions (rsyslog) which can store the data in a SQL database.

The system that initally receives the bluetooth packets can be running MS windows, Mac OS or linux.
It can receive and forward packets from any number of tags.

Specficitions needed

  1. The MAC addreses of the beacons which are to be collected
  2. The destination of the packet data
  3. The criteria to archive/purge the data

Install the script

The script to select the packet data and forward it to the syslog daemon is:

hcidump --timestamp --raw |\
grep --file beaconAddresses --line-buffered --after-context=1 |\
sed --unbuffered "N ;s/\n//; "| # join 2 lines together
logger -p local7.info

The file beaconAddresses contains the MAC addresses of the beacons to proceses one per line in the format: xx:xx:xx:xx:xx

hcidump formats packets like:

2018-04-16 19:36:46.080953 > 04 3E 17 02 01 00 00 AE 3B 97 75 32 4C 0B 02 01 06 07 FF 4C 
  00 10 02 0B 00 B7
grep selects the packets based on the MAC address. Since hcidump outputs multiple lines for each packet, it is neccessary to have grep include an additional line once it finds the line with the MAC address.
For the same reason, sed is used to put the multiple lines into a single line before sending the data to the logger.

Configure syslogd

syslogd is the system daemon which accepts messages from logger.
The file /etc/syslog.conf contains the specifications for handling all syslog messages.

Either use ftp to retrieve the current /etc/syslog.conf, save it , edit it to add the required line and then use ftp to put it back.

use ssh to log in to the system, copy the current /etc/syslog.conf to a save version and the edit /etc/syslog.conf

local7.info @anotherHost local7.info /media/data/beacons

Configure archiving/purging

The configuration file for handling all syslog repositories is /etc/logrotate.conf Update it as with the /etc/syslog.conf file, to include a line like:
/media/data/beacons                 owner:staff  640  3     100    *      J
This specifies that when the data file is archived a new file is inialized with the ownerID:groupID and permissions of 640
3 generations will be retained.
THe active file will be archived when it exceeds 100
 /media/data/beacons {
    rotate 3
    size 100k

The raspberry pi zero w option

The easiest way to get this setup is to purchase a kit. These include a "ready to boot" operating system image on the SD card.
To have the raspberry pi be battery operated check out battery pi.
This system will be run in "headless" mode so no keyboard or monitor is necessay.
Connect to it using a terminal emulator client like putty or ssh
update files using ftp

Ingics BLE <-> wifi and iGS02E BLE <-& gt; wifi more details

iGS01 iGS01 (£69.60) gateway listens for beacons, gets their advertising data and forwards it on to your server or an IoT server via TCP, HTTP(S) or MQTT. Can be used to feed back-end systems that report on the presence or absence of iBeacon or Eddystone beacons or act on beacon sensor (e.g. accelerometer, temperature, light, humidity) data.

Where to keep your data?

Relational database?

TimeScale time-series database.