Firmware-server is an OTA (Over-The-Air) server for devices to check for firmware updates and download them. It is built using FastAPI and Python, and it utilizes Google Sheets to store and manage device information. The server supports handling multiple firmware versions but serves only the current version as specified in the configuration file.
- Check Firmware Version: Devices can check the current firmware version available on the server.
- Download Firmware: Devices can download the firmware binary from the server.
- Device Information Management: The server collects and reports device information to Google Sheets, including the last seen time, update time, firmware version, and MAC address.
- Asynchronous Execution: The server performs I/O operations asynchronously to enhance performance.
- Python 3.8+
- FastAPI
- Uvicorn
- Google Sheets API client
- gspread
- decouple
- pytest for testing
- Clone the repository:
git clone https://github.com/DmytroHlazyrin/Firmware-server.git
cd Firmware-server- Create and activate a virtual environment:
python -m venv .venv
.venv\Scripts\activate # On Windows
source .venv/bin/activate # On Unix or MacOS- Install the required packages:
pip install -r requirements.txt-
Configure Google Sheets integration:
- Place your Google Sheets credentials JSON file in the config/ directory and name it credentials.json.
- Set up the SPREADSHEET_ID in a .env file or in the environment variables.
-
Configuration File: config/config.json
{ "current_version": "v1.0.0" }
-
Environment Variables: Create a .env file in the root directory with the following content:
CREDENTIALS_FILE_PATH=config/credentials.json
SPREADSHEET_ID=your_spreadsheet_id
To run the server locally, use the following command:
uvicorn app.main:app --reloadTo run with Docker:
docker build -t firmware-server .
docker run -d -p 8000:8000 --name firmware-server firmware-serverTo stop and remove container:
docker stop firmware-server
docker rm firmware-serverTo communicate with a server requests must have the next headers:
_br_mac_- device MAC address_br_fwv_- current device firmware version
Check firmware version request:
curl -X GET http://localhost:8000/version.txt -H 'cache-control: no-cache' -H 'Connection: close' -H '_br_mac_: 00:11:22:33:44:55' -H '_br_fwv_: v1.0.0'Download firmware binary request:
curl -X GET http://localhost:8000/firmware.bin -H 'cache-control: no-cache' -H 'Connection: close' -H '_br_mac_: 00:11:22:33:44:55' -H '_br_fwv_: v1.0.0'To run the tests, use:
pytestHTTPS: HTTPS is not yet implemented. For security in production, you should set up HTTPS with a valid SSL certificate.
Systemd Service: Systemd service file is not implemented.
For managing server processes on Linux systems, you would need to create a systemd service file or run with Docker.
Implement HTTPS: Secure the server with HTTPS using a valid SSL certificate.
Create Systemd Service File: Automate the server's start/restart with a systemd service file for Linux systems.
Enhance Testing: Expand tests to cover all edge cases and ensure high code coverage.
For any inquiries or issues, please contact dmytro.hlazyrin@gmail.com