https://github.com/susji/ruuviscan
Minimalistic terminal tool for scanning Ruuvi sensors with Bluetooth Low Energy and dumping the data as JSON
https://github.com/susji/ruuviscan
ble bluetooth-low-energy go golang json ruuvi ruuvi-ble-devices ruuvitag ruuvitag-sensor
Last synced: about 2 months ago
JSON representation
Minimalistic terminal tool for scanning Ruuvi sensors with Bluetooth Low Energy and dumping the data as JSON
- Host: GitHub
- URL: https://github.com/susji/ruuviscan
- Owner: susji
- License: apache-2.0
- Created: 2024-03-30T17:49:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-01T15:02:36.000Z (over 2 years ago)
- Last Synced: 2025-02-07T19:13:48.573Z (over 1 year ago)
- Topics: ble, bluetooth-low-energy, go, golang, json, ruuvi, ruuvi-ble-devices, ruuvitag, ruuvitag-sensor
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ruuviscan
This is a small utility for scanning Bluetooth Low Energy (BLE) Advertisements
from [Ruuvi sensors](https://ruuvi.com) and dumping the values as JSON to
standard output.
# Building
Grab a precompiled [release](https://github.com/susji/ruuviscan/releases) or use
the Go toolchain.
# Usage
Set the environment value `VERBOSE=1` if you wish to see more details when a
RuuviTag Advertisement is received.
## Dumping human-readable temperature values in real time
```
$ ./ruuviscan \
| jq -rc 'select(.Temperature.Valid) | [.Timestamp, .MAC, .Temperature.Value] | @tsv'
```
## Storing temperature values in an SQLite database
First create a suitable database file with a table for temperature data:
```
$ sqlite3 temps.db <<'EOF'
CREATE TABLE temps (
timestamp TIMESTAMP NOT NULL,
mac STRING NOT NULL,
temp REAL NOT NULL
)
EOF
```
Then you can run the program to scan and store for the values:
```
$ ./ruuviscan \
| jq --unbuffered -rc \
'select(.Temperature.Valid) |
[.Timestamp, .MAC, .Temperature.Value] | @sh' \
| while read -r _ts _mac _temp; do
sqlite3 temps.db "INSERT INTO TEMPS VALUES ($_ts, $_mac, $_temp)"
done
```
You may also observe the latest values as they are recorded:
```
$ watch sqlite3 --readonly \
"temps.db \
'SELECT COUNT(*) FROM temps;
SELECT * FROM temps ORDER BY timestamp DESC LIMIT 10;'"
```
See [temps.plt](./temps.plt) for an example how to plot the temperature data
with gnuplot.