1.9 KiB
1.9 KiB
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:
sudo apt-get install libsqlite3-dev
Setup
- Install Go dependencies:
go mod tidy
- 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
- Start the server:
go run main.go
- 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:
- Make sure the Telegram export file is in the root directory of the project
- Run the import script:
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
- Body:
-
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