This repository contains a script to automatically control the power output of a device using the CAT protocol. The script connects to a CAT server and adjusts the drive level to maintain a target power output.
The purpose of this repository is to provide a solution for automatically controlling the power output of a device using the CAT protocol. The script connects to a CAT server, reads the current power output, and adjusts the drive level to maintain the target power output specified by the user.
To set up and run the Docker container using the provided Dockerfile, follow these steps:
-
Build the Docker image:
docker build -t cat-auto-power . -
Run the Docker container:
docker run -e IP_ADDRESS=<your_ip_address> -e PORT=<your_port> -e TARGET_PWR=<your_target_power> -e API_KEY=<your_api_key> cat-auto-power
To run the main.py script directly, follow these steps:
-
Set the required environment variables:
export IP_ADDRESS=<your_ip_address> export PORT=<your_port> export TARGET_PWR=<your_target_power> export API_KEY=<your_api_key>
-
Run the script:
python main.py
Here are some examples of how to set the environment variables and run the script:
docker run -e IP_ADDRESS=192.168.1.100 -e PORT=13013 -e TARGET_PWR=10 -e API_KEY=your_api_key cat-auto-powerexport IP_ADDRESS=192.168.1.100
export PORT=13013
export TARGET_PWR=10
export API_KEY=your_api_key
python main.pyThe script now includes a REST API to set and get the desired power level on the fly using Flask.
Access the web dashboard by opening a browser and navigating to http://<your_ip_address>:5000/
The dashboard provides:
- A form to change the target power level
- Real-time visualization of power output history with target power overlay
- Real-time visualization of drive settings history
- Current target power display
GET /api/power: Returns the current target power level.POST /api/power: Sets a new target power level. The request body should be in JSON format and include thetarget_powerandapi_keyfields.
curl -X GET http://<your_ip_address>:5000/api/powercurl -X POST -H "Content-Type: application/json" -d '{"target_power": 15, "api_key": "your_api_key"}' http://<your_ip_address>:5000/api/power