Backend for the CREW test stand control
This project relies on the following dependencies, see their official documentation for more information:
The config.py
file in the project allows for several configurations to be set via environment variables or a .env.local
file. Below is a list of all the configurable options and their descriptions:
Configuration Variable | Description | Default | Example | Required |
---|---|---|---|---|
DEBUG_LEVEL | The level of debugging information to log. | INFO | DEBUG | No |
FLOWMETER_COUNT | The number of flowmeters connected to the system. | 1 | 2 | |
GPIO_MODE | Specifies the mode of GPIO usage. | None | mock | No |
GPIOZERO_PIN_FACTORY | Determines the pin factory to use when interacting with GPIO pins. This setting affects how the GPIOZero library operates. For more information, refer to the official GPIOZero documentation. Although not used in the project, this variable's value is read by the Config to display it for debugging purposes. | None | mock | No |
PROJECT_NAME | The name of the project. | swncrew backend | swncrew backend | No |
PROPORTIONAL_CAN_INTERFACE | The name of the CAN interface to use for the proportional valves. | can0 | can1 | No |
PROPORTIONAL_GPIO | A comma-separated string of GPIO pins used for the proportional valves. | None | 10,11 | No |
PROPORTIONAL_MODE | Specifies the control mode for the proportional valves. It can be set to GPIO for GPIO control, which generates a PWM signal on the Pins defined in PROPORTIONAL_GPIO . This option is useful for development as the output can be mapped to an LED and supports the mock mode. To use CAN , the CAN interface must be set up properly on the device. |
Not Set | CAN | Yes |
PUMP_GPIO | A comma-separated string of GPIO pins used for the pumps. | Not set | 20,21,23,24 | Yes |
SOLENOID_GPIO | A comma-separated string of GPIO pins used for the solenoid valves. | Not set | 4,5,6 | Yes |
VERSION | The version of the software. | Read from version.txt |
0.0.1 | No |
The project uses a logger to log messages in the console. The debug level is set based on the DEBUG_LEVEL configuration. Possible debug levels include
- DEBUG
- INFO
- WARNING
- ERROR
- CRITICAL
To control the GPIO mode, set the GPIO_MODE
configuration variable. By default, this variable is not set, which allows the project to use actual GPIO pins. However, for testing and development purposes, you can set GPIO_MODE
to mock
to utilize a simulated GPIO factory, eliminating the need for physical hardware interaction.
To use the CAN bus control for the proportional valves, you need to set up the CAN interface on your device. Refer to the official documentation for your specific device to configure the CAN interface (e.g. Waveshare CAN-HAT).
Following instructions apply for setting up and using the Waveshare RS485 CAN HAT on a Raspberry Pi running Ubuntu. Please note that the steps might differ if you are using another device or a different configuration.
- Configure Your Raspberry Pi:
- Add the following lines to your
/boot/firmware/config.txt
to enable SPI and configure the CAN interface:
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000>
enable uart=1
- Reboot your Raspberry Pi to apply the changes.
- Bring Up the CAN Interface
sudo ip link set can0 up type can bitrate 500000
sudo ifconfig can0 up
- You might initialize the CAN interface on boot.
To get started quickly, follow these steps:
- Clone the repository:
git clone https://github.com/FelizCoder/crewstand.backend
- Install dependencies:
pip install -r requirements.txt
- Create a
.env.local
file and set the desired configurations (e.g., PROJECT_NAME, VERSION, etc.) - Run the backend:
fastapi dev app/main.py
You can easily run this project using Docker. Here's how:
- Pull the Docker image:
docker pull ghcr.io/felizcoder/crewstand.backend:latest
- Set environment variables: Configure the required environment variables using the
-e
flag. - Run the Docker container: The API will be exposed on port 5000.
docker run -p 5000:5000 -e <environment variables> ghcr.io/felizcoder/crewstand.backend:latest
Example command:
docker run -p 5000:5000 -e DEBUG_LEVEL=DEBUG -e GPIO_MODE=mock -e GPIOZERO_PIN_FACTORY=mock -e PROJECT_NAME=swncrew_backend -e PROPORTIONAL_GPIO=10,11 -e PROPORTIONAL_MODE=GPIO -e PUMP_GPIO=20,21,23,24 -e SOLENOID_GPIO=4,5,6 ghcr.io/felizcoder/crewstand.backend:latest