aranet-service
Background collector and HTTP REST API for Aranet sensors.
A service daemon that continuously monitors Aranet devices and exposes sensor data via a REST API. Built with Axum for high-performance async HTTP handling.
Features
- Background collection - Automatically poll configured devices at regular intervals
- REST API - Query current readings, history, and device information via HTTP
- WebSocket support - Real-time streaming of sensor updates
- Prometheus metrics -
/metricsendpoint for Grafana dashboards and alerting - MQTT publisher - Broadcast readings to MQTT brokers for IoT integration
- Local persistence - Store readings in SQLite via aranet-store
- Configurable - TOML-based configuration for devices, intervals, and server settings
- Health endpoint - Monitor service status for integration with monitoring systems
- Service management - Install as system service (launchd/systemd/Windows Service)
Installation
Or build from source:
Usage
# Start the service with default configuration
# Specify a custom config file
# Specify bind address and port
Configuration
Create a configuration file at ~/.config/aranet/service.toml:
[]
= "127.0.0.1:3000"
[]
= "~/.local/share/aranet/data.db"
[[]]
= "AA:BB:CC:DD:EE:FF"
= "Living Room"
= 60 # seconds
# Prometheus metrics (optional)
[]
= true
# push_gateway = "http://localhost:9091" # Optional push gateway
# push_interval = 60 # Push interval in seconds
# MQTT publishing (optional)
[]
= true
= "mqtt://localhost:1883" # or mqtts:// for TLS
= "aranet"
= "aranet-service"
= 1 # 0=AtMostOnce, 1=AtLeastOnce, 2=ExactlyOnce
= true
# username = "user" # Optional authentication
# password = "secret"
API Endpoints
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Service health check |
| GET | /api/health/detailed |
Detailed health with database, collector, and platform diagnostics |
| GET | /api/status |
Full service status with collector state |
| GET | /api/devices |
List all configured devices |
| GET | /api/devices/:id |
Get device details |
| GET | /api/devices/:id/current |
Get current reading |
| GET | /api/devices/:id/readings |
Query stored readings |
| GET | /api/devices/:id/history |
Query device history |
| GET | /api/readings |
Query all readings across devices |
| POST | /api/collector/start |
Start background collector |
| POST | /api/collector/stop |
Stop background collector |
| GET | /api/config |
Get current configuration |
| PUT | /api/config |
Update configuration |
| POST | /api/config/devices |
Add device to monitoring |
| PUT | /api/config/devices/:id |
Update device config |
| DELETE | /api/config/devices/:id |
Remove device |
| GET | /metrics |
Prometheus metrics endpoint |
| WS | /api/ws |
WebSocket for real-time updates |
Query Parameters
For /readings and /history endpoints:
| Parameter | Type | Description |
|---|---|---|
since |
Unix timestamp | Filter records after this time |
until |
Unix timestamp | Filter records before this time |
limit |
Integer | Maximum number of records |
offset |
Integer | Skip this many records (pagination) |
Example Requests
# Check service health
# List devices
# Get current reading
# Query history with time range
# Get Prometheus metrics
Prometheus Metrics
When enabled, the /metrics endpoint exports sensor data in Prometheus format:
Sensor readings (per device):
aranet_co2_ppm- CO2 concentrationaranet_temperature_celsius- Temperaturearanet_humidity_percent- Humidityaranet_pressure_hpa- Pressurearanet_battery_percent- Battery levelaranet_reading_age_seconds- Age of reading
Radon/radiation (if available):
aranet_radon_bqm3- Radon concentrationaranet_radiation_rate_usvh- Radiation dose ratearanet_radiation_total_msv- Total radiation dose
Collector statistics:
aranet_collector_running- Collector status (1=running, 0=stopped)aranet_collector_uptime_seconds- Collector uptimearanet_device_poll_success_total- Successful polls per devicearanet_device_poll_failure_total- Failed polls per device
MQTT Topics
When MQTT is enabled, readings are published to the following topics:
{prefix}/{device}/json - Full reading as JSON
{prefix}/{device}/co2 - CO2 (ppm)
{prefix}/{device}/temperature - Temperature (°C)
{prefix}/{device}/humidity - Humidity (%)
{prefix}/{device}/pressure - Pressure (hPa)
{prefix}/{device}/battery - Battery level (%)
{prefix}/{device}/status - Status (green/yellow/red/error)
{prefix}/{device}/radon - Radon (Bq/m³, if available)
{prefix}/{device}/radiation_rate - Radiation rate (µSv/h, if available)
{prefix}/{device}/radiation_total - Total radiation (mSv, if available)
Where {prefix} is the configured topic prefix (default: "aranet") and {device} is the device alias or address.
Service Management
Install and manage aranet-service as a system service:
# Install as user service
# Start/stop/status
# Install as system service (requires root/admin)
Related Crates
This crate is part of the aranet workspace:
| Crate | crates.io | Description |
|---|---|---|
| aranet-core | Core BLE library for device communication | |
| aranet-types | Shared types for sensor data | |
| aranet-store | Local data persistence | |
| aranet-cli | Command-line interface | |
| aranet-tui | Terminal UI dashboard | |
| aranet-gui | Desktop GUI application |
License
MIT
Made with ❤️ by Cameron Rye