From 40357abbb3f6a426c2a30d295b24a5cff2bc69de Mon Sep 17 00:00:00 2001 From: Noah Date: Tue, 21 Apr 2026 13:54:23 +0300 Subject: [PATCH] docs: add backend setup and IoT sensor setup guides (closes #5) --- docs/backend_setup.md | 62 +++++++++++++++++++++++++++++++++++++++++++ docs/iot_setup.md | 46 ++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 docs/backend_setup.md create mode 100644 docs/iot_setup.md diff --git a/docs/backend_setup.md b/docs/backend_setup.md new file mode 100644 index 0000000..0ee033e --- /dev/null +++ b/docs/backend_setup.md @@ -0,0 +1,62 @@ +# Backend Setup Guide + +This guide covers setting up the LifeLine-ICT FastAPI backend locally. + +## Prerequisites + +- Python 3.11+ +- pip + +## Installation + +```bash +cd backend +python -m venv .venv +source .venv/bin/activate # Windows: .venv\Scripts\activate +pip install -r requirements.txt +``` + +## Running the API + +```bash +uvicorn backend.app.main:app --reload +``` + +API available at: `http://127.0.0.1:8000` +Swagger docs at: `http://127.0.0.1:8000/docs` + +## Database Migrations + +```bash +alembic upgrade head +``` + +## Running Tests + +```bash +pytest backend/tests +``` + +## API Endpoints + +| Method | Endpoint | Description | +|--------|---------------------------------|------------------------------| +| GET | /api/v1/projects | List all ICT projects | +| POST | /api/v1/projects | Create a new project | +| GET | /api/v1/projects/{id} | Get project by ID | +| PUT | /api/v1/projects/{id} | Update a project | +| DELETE | /api/v1/projects/{id} | Delete a project | +| GET | /api/v1/resources | List all ICT resources | +| POST | /api/v1/resources | Create a new resource | +| GET | /api/v1/locations | List all locations | +| POST | /api/v1/locations | Create a location | +| GET | /api/v1/maintenance-tickets | List maintenance tickets | +| POST | /api/v1/maintenance-tickets | Create a maintenance ticket | +| GET | /api/v1/sensor-sites | List IoT sensor sites | +| POST | /api/v1/sensor-sites | Create a sensor site | + +## Business Rules + +- A resource **cannot be deleted** while it has open maintenance tickets +- Closing a ticket **requires** a resolution note +- Sensor sites must be linked to an existing resource and location \ No newline at end of file diff --git a/docs/iot_setup.md b/docs/iot_setup.md new file mode 100644 index 0000000..72f04ea --- /dev/null +++ b/docs/iot_setup.md @@ -0,0 +1,46 @@ +# IoT Sensor Setup Guide + +This guide covers setting up the ESP32 sensor nodes and the Flask logging service. + +## Flask Logger Setup + +```bash +cd iot/logging +python -m venv .venv +source .venv/bin/activate +pip install flask +python app.py +``` + +Logger runs at: `http://0.0.0.0:5000` + +## Endpoints + +| Method | Endpoint | Description | +|--------|-----------|------------------------------| +| POST | /log | Receive sensor telemetry | +| GET | /health | Check logger status | +| GET | /logs | View recent log entries | + +## Sending Data from ESP32 + +Configure your ESP32 sketch with: +```cpp +const char* serverUrl = "http://YOUR-SERVER-IP:5000/log"; +``` + +## Sample Payload + +```json +{ + "sensor_id": "ESP32-001", + "temperature": 24.5, + "humidity": 68.2, + "flood_level": 12.3, + "timestamp": "2026-04-21T10:30:00Z" +} +``` + +## Data Storage + +Telemetry is stored in SQLite at `iot/logging/telemetry.db` \ No newline at end of file