70 lines
2.1 KiB
Plaintext
70 lines
2.1 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
|
|
|
|
## Table: mir_server_missions
|
|
- ip: TEXT
|
|
- authorization: TEXT
|
|
- username: TEXT
|
|
- password: TEXT
|
|
- mission_id: TEXT
|
|
|
|
## Table: requested_missions
|
|
- state: TEXT
|
|
- start_time: TEXT
|
|
- mission: TEXT
|
|
- mission_name: TEXT
|
|
- robot_id: INTEGER
|
|
- id: INTEGER PRIMARY KEY
|
|
|
|
# Explanation of Functions in app.py
|
|
|
|
## Function: init_db
|
|
- Initializes the SQLite database.
|
|
- Creates four tables: logs, boards, mir_server_missions, and requested_missions.
|
|
- 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.
|
|
- The mir_server_missions table stores the information required to create a JSON post for a mission.
|
|
- The requested_missions table stores the response data from the mission post request.
|
|
|
|
## 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.
|
|
- Triggers the post_mission function if input1 is turned on.
|
|
|
|
## 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.
|
|
|
|
## Function: post_mission
|
|
- Sends a mission post request to the MIR server.
|
|
- Retrieves the IP, authorization, username, and password from the mir_server_missions table.
|
|
- Formats the headers and sends a POST request to the mission scheduler endpoint.
|
|
- Prints the result of the mission post request.
|
|
- Stores the response data in the requested_missions table. |