chickencoop/server/README.md

72 lines
1.9 KiB
Markdown

# Chicken Coop LDR Monitor Server
This is a Go server that receives and stores LDR (Light Dependent Resistor) readings from the ESP8266 and provides a web interface to visualize the data.
## Prerequisites
- Go 1.16 or later
- SQLite3 development libraries
On Ubuntu/Debian, install SQLite3 development libraries with:
```bash
sudo apt-get install libsqlite3-dev
```
## Setup
1. Install Go dependencies:
```bash
go mod tidy
```
2. Update the ESP8266 code with your Go server's IP address:
- Open `ESP8266/ESP8266.ino`
- Change the `goServerHost` value to your Go server's IP address
## Running the Server
1. Start the server:
```bash
go run main.go
```
2. Access the web interface at `http://localhost:8080`
The server will:
- Listen for LDR readings on `/api/ldr` endpoint
- Store readings in a SQLite database
- Provide a web interface with charts showing LDR values over time
- Support different time ranges (day, week, month, all time)
## Importing Historical Data
If you have a Telegram export file (`tg_export.json`) with historical LDR readings, you can import them into the database:
1. Make sure the Telegram export file is in the root directory of the project
2. Run the import script:
```bash
cd cmd/import_history
go run main.go
```
The script will:
- Read the Telegram export file
- Extract LDR readings from messages
- Import them into the SQLite database
- Show the number of readings imported
## API Endpoints
- `POST /api/ldr` - Receive LDR readings
- Body: `{"value": 123, "timestamp": "2024-03-14T12:00:00Z"}`
- Note: timestamp is optional, server will use current time if not provided
- `GET /api/readings?period=day|week|month|all` - Get LDR readings
- Returns JSON array of readings with timestamps
## Web Interface
The web interface provides:
- Line chart of LDR values over time
- Time range selector (24h, week, month, all time)
- Auto-refresh every 5 minutes