Skip to content

Commit ac8e2dd

Browse files
docs: add api/stats to project structure and API reference
1 parent b2982ad commit ac8e2dd

1 file changed

Lines changed: 56 additions & 31 deletions

File tree

README.md

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@
33
</p>
44

55
<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>
107
</p>
118

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.
2929
3030
---
3131

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.
3434
3535
## Quick Setup
3636

@@ -48,6 +48,7 @@ api/
4848
ingest.js POST — primary ESP8266 data ingestion endpoint
4949
logs.js GET — recent logs with pagination
5050
realtime-config.js GET — Supabase credentials for Android WebSocket
51+
stats.js GET — hourly aggregated statistics per device
5152
status.js GET — latest reading for a device
5253
lib/
5354
email.js Resend email alert helper
@@ -171,6 +172,37 @@ Returns the most recent reading for a specific device. Useful for a quick health
171172

172173
---
173174

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+
174206
### GET /api/realtime-config
175207

176208
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!
312344

313345
---
314346

315-
## License
316-
317-
Apache 2.0 © [Gas Leak Detector](LICENSE)
318-
319-
---
320-
321347
## Closing
322348

323349
<p align="center">
324350
Have questions or ran into issues? Reach out at <a href="mailto:pan2512811@gmail.com">pan2512811@gmail.com</a>.<br/>
325351
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

Comments
 (0)