|
3 | 3 | </p> |
4 | 4 |
|
5 | 5 | <p align="center"> |
6 | | - <img alt="License" src="https://img.shields.io/github/license/gasleakdetector/gasleakdetector-server?color=04A8F4&style=flat-square"/> |
7 | | - <img alt="Version" src="https://img.shields.io/badge/version-1.0-04A8F4?style=flat-square"/> |
8 | | - <img alt="Build" src="https://img.shields.io/github/actions/workflow/status/gasleakdetector/gasleakdetector-server/ci.yml?style=flat-square&color=04A8F4"/> |
9 | | - <img alt="Last commit" src="https://img.shields.io/github/last-commit/gasleakdetector/gasleakdetector-server?color=04A8F4&style=flat-square"/> |
| 6 | + <h3 align="center">Gas Leak Detector — Server</h3> |
10 | 7 | </p> |
11 | 8 |
|
12 | | -<div align="center"> |
13 | | - <h1>Gas Leak Detector — Server</h1> |
14 | | - |
15 | | - <p> |
16 | | - Backend API for the Gas Leak Detector system.<br/> |
17 | | - Handles ESP8266 sensor ingestion, persists data to Supabase,<br/> |
18 | | - and streams real-time updates to the Android app via WebSocket. |
19 | | - </p> |
20 | | - |
21 | | - <p> |
22 | | - Part of the <b>Gas Leak Detector</b> ecosystem: |
23 | | - <br/> |
24 | | - <a href="https://github.com/gasleakdetector/gasleakdetector-server">Server</a> • |
25 | | - <a href="https://github.com/gasleakdetector/gasleakdetector-esp">ESP8266 Firmware</a> • |
26 | | - <a href="https://github.com/gasleakdetector/gasleakdetector">Android App</a> |
27 | | - </p> |
28 | | -</div> |
| 9 | +<p align="center"> |
| 10 | + This is the backend API server for the Gas Leak Detector system.<br/> |
| 11 | + Receives sensor data from ESP8266, persists it to Supabase,<br/> |
| 12 | + and streams real-time readings to the Android app via WebSocket. |
| 13 | +</p> |
| 14 | + |
| 15 | +<p align="center"> |
| 16 | + <a href="https://github.com/gasleakdetector/gasleakdetector-server/actions"> |
| 17 | + <img src="https://img.shields.io/github/actions/workflow/status/gasleakdetector/gasleakdetector-server/build.yml?style=for-the-badge" alt="Build status"/> |
| 18 | + </a> |
| 19 | + <a href="https://github.com/gasleakdetector/gasleakdetector-server/blob/main/LICENSE"> |
| 20 | + <img src="https://img.shields.io/github/license/gasleakdetector/gasleakdetector-server?style=for-the-badge" alt="License"/> |
| 21 | + </a> |
| 22 | +</p> |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +> **Part of [gasleakdetector-app](https://github.com/gasleakdetector/gasleakdetector) and [gasleakdetector-esp](https://github.com/gasleakdetector/gasleakdetector-esp)** |
| 27 | +> — the main repository containing the full project including the ESP8266 firmware and Android app. |
| 28 | +> This repository is the server-only branch of that project. |
29 | 29 |
|
30 | 30 | --- |
31 | 31 |
|
32 | | -> ⚠️ This repository contains the server component only. |
33 | | -> No hosted instance or pre-built binaries are provided — deployment is your responsibility. |
| 32 | +> [!NOTE] |
| 33 | +> No pre-built binaries or hosted instances are provided. You are responsible for building and deploying this project yourself. |
34 | 34 |
|
35 | 35 | ## Quick Setup |
36 | 36 |
|
|
48 | 48 | ingest.js POST — primary ESP8266 data ingestion endpoint |
49 | 49 | logs.js GET — recent logs with pagination |
50 | 50 | realtime-config.js GET — Supabase credentials for Android WebSocket |
| 51 | + stats.js GET — hourly aggregated statistics per device |
51 | 52 | status.js GET — latest reading for a device |
52 | 53 | lib/ |
53 | 54 | email.js Resend email alert helper |
@@ -171,6 +172,37 @@ Returns the most recent reading for a specific device. Useful for a quick health |
171 | 172 |
|
172 | 173 | --- |
173 | 174 |
|
| 175 | +### GET /api/stats |
| 176 | + |
| 177 | +Returns hourly aggregated statistics from `gas_logs_hour`. This is the endpoint the Android statistics chart reads from — it never touches raw data, so queries stay fast regardless of data volume. |
| 178 | + |
| 179 | +**Query parameters:** |
| 180 | + |
| 181 | +| Parameter | Required | Default | Description | |
| 182 | +|-------------|----------|---------|-----------------------------------------------| |
| 183 | +| `device_id` | No | — | Filter by device. Omit to return all devices. | |
| 184 | +| `limit` | No | `10` | Number of hourly buckets to return (max 50) | |
| 185 | + |
| 186 | +**Response:** |
| 187 | + |
| 188 | +```json |
| 189 | +{ |
| 190 | + "data": [ |
| 191 | + { |
| 192 | + "bucket": "2026-03-21T10:00:00+00:00", |
| 193 | + "avg_gas": 213.45, |
| 194 | + "min_gas": 180.0, |
| 195 | + "max_gas": 310.0, |
| 196 | + "sample_count": 1800 |
| 197 | + } |
| 198 | + ] |
| 199 | +} |
| 200 | +``` |
| 201 | + |
| 202 | +Results are ordered by `bucket` descending — most recent hour first. Each bucket represents one full hour of aggregated readings from that device. |
| 203 | + |
| 204 | +--- |
| 205 | + |
174 | 206 | ### GET /api/realtime-config |
175 | 207 |
|
176 | 208 | Provides the Supabase URL and anonymous key required for the Android app to establish a direct WebSocket connection to Supabase Realtime. The primary purpose is to allow the Android client to dynamically obtain credentials for subscribing to real-time INSERT events on the gas_logs_raw table, eliminating the need to hardcode sensitive information in the APK. |
@@ -312,16 +344,9 @@ Don't forget to give the project a star! Thanks again! |
312 | 344 |
|
313 | 345 | --- |
314 | 346 |
|
315 | | -## License |
316 | | - |
317 | | -Apache 2.0 © [Gas Leak Detector](LICENSE) |
318 | | - |
319 | | ---- |
320 | | - |
321 | 347 | ## Closing |
322 | 348 |
|
323 | 349 | <p align="center"> |
324 | 350 | Have questions or ran into issues? Reach out at <a href="mailto:pan2512811@gmail.com">pan2512811@gmail.com</a>.<br/> |
325 | 351 | Found this project useful? Consider giving it a ⭐ — it means a lot and helps others discover it. Thanks! |
326 | | -</p> |
327 | | - |
| 352 | +</p> |
0 commit comments