Appearance
Local development
The whole controller stack runs on a laptop with no hardware attached. sequentulator emulates the Sequent boards and smulator emulates the LCD, and the services talk to them through shared memory files in /tmp.
Everything here runs from the root of rpi-controller.
Prerequisites
- Docker with Compose
- Python 3.11 with
pyserial, for the board emulator make
Configure
bash
cp .env.template .envThen set the two addresses the services use to find each other. The dev stack runs on a Compose network where containers resolve by name, and the broker address is a bare hostname, not a URL.
bash
API_URL=http://controlfreak-api:8000
MQTT_BROKER_URL=mosquitto| Variable | Value | What it does |
|---|---|---|
USE_EMULATOR | 1 | Services use sequentulator and smulator instead of real hardware |
RS485_EMULATOR | 0 | 1 answers every RS485 port from an emulated unit |
RS485_POLL_SECONDS | 15 | How often each RS485 port is polled |
API_URL | http://controlfreak-api:8000 | Where services reach controlfreak-api |
MQTT_BROKER_URL, MQTT_BROKER_PORT | mosquitto, 1515 | Where services reach the broker |
DATABASE_PATH | sqlite:////app/data/controller.db | The API's database, inside the container |
DOCKER_REGISTRY | empty | Registry baked into locally built images. Empty means krumcontrolfreak. |
AWS_IOT_* | Only needed to run the AWS installer against a real IoT endpoint |
Build and start
bash
make dev-build
make devmake dev-build builds the mqtt-builder base image, then every service on top of it. make dev starts the stack. On first start the API seeds a default database into database-api/data/controller.db.
Run the emulators
Each emulator is a terminal UI. Run each one in its own terminal:
bash
make emulator # sequentulator, the boards
make smulator # smulator, the LCDsequentulator shows the relays, valves, flow sensors, thermistors and RS485 ports, and takes commands at its prompt. Type help for the list. Its state lives in /tmp/sequentulator/sequentulator.mmap, and smulator uses /tmp/smulator/smulator.mmap. Both folders are mounted into the containers that need them.
To emulate RS485 devices as well, set RS485_EMULATOR=1 in .env and recreate the RS485 containers:
bash
docker compose -f docker-compose.dev.yaml up -d --force-recreate \
controlfreak-subscriber-rs485 controlfreak-publisher-rs485What is running
| Service | Address on the laptop |
|---|---|
| REST API | http://localhost:8000, docs at http://localhost:8000/docs |
| MQTT over TCP | localhost:1515 |
| MQTT over WebSocket | ws://localhost:8080 |
The local broker allows anonymous connections.
bash
docker compose -f docker-compose.dev.yaml ps
docker logs -f controlfreak-api
mosquitto_sub -h localhost -p 1515 -t 'controller/#' -vMaking changes
| What changed | What to do |
|---|---|
database-api/ | Nothing. The source is mounted into the container and uvicorn reloads on save. |
A single service, such as scheduler/ or a publisher | Rebuild and restart just that service. |
shared-lib/, sequentulator/, smulator/ or the vendored firmware | Rebuild everything with make dev-build, since these are baked into mqtt-builder. |
.env | Recreate the affected containers with --force-recreate. |
Rebuilding one service:
bash
docker compose -f docker-compose.dev.yaml up -d --build --no-deps controlfreak-schedulerUse the container name, controlfreak-scheduler, not the folder name.
Connecting the mobile app
Point the app at the laptop by setting EXPO_PUBLIC_DEFAULT_HOST in mobile-controller/.env to the laptop's LAN address, then start the app as usual.
Stopping
bash
make dev-downThe database in database-api/data/ survives a restart. Delete database-api/data/controller.db to start over from the seeded defaults.
Troubleshooting
Services cannot open the emulator files. The folders in /tmp can end up owned by root after a container creates them. Reset them:
bash
sudo rm -f /tmp/sequentulator/sequentulator.lock /tmp/sequentulator/sequentulator.mmap
mkdir -p /tmp/sequentulator
sudo chown -R $USER:$USER /tmp/sequentulatorDo the same for /tmp/smulator if the display emulator has the problem.
A service keeps restarting. Every container restarts on failure, so a crash shows up as a loop. Check its logs with docker logs <container>. The usual causes are the API not being up yet, which clears on its own, or a missing emulator file, which the fix above solves.
A change to shared-lib does not show up. The service is still using the old mqtt-builder. Run make dev-build.