Backend service responsible for logging metrics into timeseries database (influx). Expected to run in the cloud and receive IoT data from beehives.
Main goal and feature is described in Notion
- ✅ temperature
- TODO: add 3d temperature endpoint
/metrics/temperature
- TODO: add 3d temperature endpoint
- ✅ beehive weight (over time)
- ✅ humidity
- CO2 levels
- atmospheric pressure
- bee traffic (in/out) at the hive entrance
- audio noise volume
- vibrations
- wind speed
| URL | Description |
|---|---|
| http://telemetry.gratheon.com | Production |
| http://localhost:8600 | Local dev |
This service provides two types of APIs:
Most flexible and type-safe for web-app, not versioned. Available at /graphql.
temperatureCelsius(hiveId, timeRangeMin)- Get temperature metricshumidityPercent(hiveId, timeRangeMin)- Get humidity metricsweightKg(hiveId, timeRangeMin)- Get weight metricsweightKgAggregated(hiveId, days, aggregation)- Get aggregated weight data (DAILY_AVG, DAILY_MAX, DAILY_MIN)entranceMovementToday(hiveId, boxId)- Get today's bee movement summaryentranceMovement(hiveId, boxId, timeFrom, timeTo)- Get bee movement historypopulationMetrics(hiveId, days)- Get population metrics (bee count, drone count, varroa mites)
addMetric(hiveId, fields)- Add IoT sensor metrics (temperature, humidity, weight)addPopulationMetric(hiveId, fields, inspectionId, timestamp)- Add population data
See schema.graphql for full API specification.
Legacy API intended for IoT devices, versioned. Available at /iot/v1/metrics.
POST /iot/v1/metrics
- Accepts single metric or array of metrics
- Requires Bearer token authentication
- Supports batch operations (up to 1000 metrics per request)
Example:
{
"hiveId": "123",
"timestamp": 1234567890,
"fields": {
"temperatureCelsius": 25.5,
"humidityPercent": 65.0,
"weightKg": 45.2
}
}The service uses PostgreSQL with three main tables:
Stores IoT sensor data (temperature, humidity, weight)
- id (INT, auto increment)
- hive_id (VARCHAR(50))
- temperature_celsius (FLOAT)
- humidity_percent (FLOAT)
- weight_kg (FLOAT)
- time (TIMESTAMP)Stores bee entrance movement data from video processing
- id (INT, auto increment)
- hive_id (VARCHAR(50))
- box_id (VARCHAR(50))
- bees_out (FLOAT)
- bees_in (FLOAT)
- net_flow (FLOAT)
- avg_speed_px_per_frame (FLOAT)
- p95_speed_px_per_frame (FLOAT)
- stationary_bees_count (INT)
- detected_bees (INT)
- bee_interactions (INT)
- time (TIMESTAMP)Stores manual inspection data about hive population
- id (INT, auto increment)
- hive_id (VARCHAR(50))
- inspection_id (VARCHAR(50))
- bee_count (INT)
- drone_count (INT)
- varroa_mite_count (INT)
- time (TIMESTAMP)See migrations/ for full schema definitions.
This project uses Go tests for both unit-style and integration-style coverage.
# Run all Go tests
go test ./...
# Run tests in Docker (includes all dependencies)
docker compose -f docker-compose.test.yml up --build --abort-on-container-exit
# Start test environment for manual testing
docker compose -f docker-compose.test.yml up -d
# Stop test environment
docker compose -f docker-compose.test.yml down -vGo tests cover:
- REST request validation and success paths
- GraphQL query and mutation validation
- Resolver and controller behavior
- Prometheus metrics wiring
- Optional Postgres roundtrip testing against Dockerized PostgreSQL
Tests include:
- Input validation and error cases
- REST and GraphQL contract checks
- Time range queries and aggregations
- Database migration and storage roundtrip coverage
Start telemetry API:
just startOr run locally without Docker:
just runWe are NOT using timeseries DB (influx, clickhouse) because we don't have manpower to maintain multiple storage engines at this time. So we're relying on PostgreSQL for ease of management, even though its not as efficient.
flowchart LR
hardware-beehive-sensors[<a href="https://github.com/Gratheon/hardware-beehive-sensors">hardware-beehive-sensors</a>] -."send aggregate (5sec)\n metric value".-> telemetry-api
telemetry-api --"update beehive entrance daily traffic counters"--> postgres[(<a href="https://github.com/Gratheon/postgres">postgres</a>)]
beehive-entrance-video-processor[<a href="https://github.com/Gratheon/beehive-entrance-video-processor">beehive-entrance-video-processor</a>] -."send entrance\n traffic metric".-> telemetry-api
telemetry-api --"store bee traffic timeseries" --> postgres
grafana[(<a href="https://github.com/Gratheon/grafana">grafana</a>)] --"fetch history"--> postgres
telemetry-api --"verify API tokens for REST calls"--> user-cycle[<a href="https://github.com/Gratheon/user-cycle">user-cycle</a>]
web-app[<a href="https://github.com/Gratheon/web-app">web-app</a>] --"display advanced configureable graphs"--> grafana
web-app --"query for simplistic metrics\nPOST graphql"-->graphql-router[<a href="https://github.com/Gratheon/graphql-router">graphql-router</a>]--> telemetry-api
This project is dual-licensed:
-
AGPL v3 - For open source use:
- ✅ You can use, modify, and distribute the software
- ✅ Source code is freely available
⚠️ If you modify and host a public instance, you must share your modifications⚠️ Any derivative work must also be licensed under AGPL v3
-
Commercial License - For enterprise customers who need:
- 🏢 On-premise deployment without source disclosure
- 🔧 Custom modifications without copyleft obligations
- 📞 Priority support and SLA guarantees
