45 lines
1.2 KiB
Plaintext
45 lines
1.2 KiB
Plaintext
# Database Schema
|
|
|
|
## Table: logs
|
|
- timestamp: TEXT
|
|
- hostname: TEXT
|
|
- ip_address: TEXT
|
|
- message: TEXT
|
|
|
|
## Table: boards
|
|
- hostname: TEXT PRIMARY KEY
|
|
- ip_address: TEXT
|
|
- input1: TEXT
|
|
- input2: TEXT
|
|
- input3: TEXT
|
|
- input4: TEXT
|
|
- relay1: TEXT
|
|
- relay2: TEXT
|
|
- relay3: TEXT
|
|
- relay4: TEXT
|
|
|
|
# Explanation of Functions in app.py
|
|
|
|
## Function: init_db
|
|
- Initializes the SQLite database.
|
|
- Creates two tables: logs and boards.
|
|
- The logs table stores log entries with timestamp, hostname, IP address, and message.
|
|
- The boards table stores the status of each board with hostname, IP address, and status of inputs and relays.
|
|
|
|
## Function: log
|
|
- Endpoint: /log
|
|
- Method: POST
|
|
- Receives log messages from the ESP board.
|
|
- Extracts hostname, IP address, and message from the JSON payload.
|
|
- Prints the hostname, IP address, and message.
|
|
- Updates the status of inputs and relays based on the message.
|
|
- Records the log in the logs table.
|
|
- Updates the board status in the boards table.
|
|
|
|
## Function: control
|
|
- Endpoint: /control
|
|
- Method: POST
|
|
- Receives control commands to update the status of relays.
|
|
- Extracts the relay status from the JSON payload.
|
|
- Prints the new relay status.
|
|
- Updates the status of the relays. |