MQTT broker add

This commit is contained in:
2026-02-09 15:28:48 -05:00
parent 62bb5cb60d
commit 65f951dfcc
6 changed files with 77 additions and 5 deletions

View File

@@ -90,6 +90,23 @@ environment:
- DATABASE_URL=sqlite:///./drugs.db
```
## MQTT
The system includes an MQTT broker (Mosquitto) with WebSocket support:
- **MQTT**: `localhost:1883`
- **WebSocket**: `localhost:9001` or `/mqtt` via nginx
To create a new MQTT user with a custom password:
```bash
docker run --rm -v $(pwd)/mosquitto/config:/temp eclipse-mosquitto mosquitto_passwd -b /temp/pwfile username password
```
Then restart the containers:
```bash
docker compose restart mosquitto
```
## Development
When you run `docker-compose up`, the backend automatically reloads when code changes (`--reload` flag). Just refresh your browser to see updates.

View File

@@ -5,8 +5,6 @@ services:
build:
context: ./backend
dockerfile: Dockerfile
ports:
- "${BACKEND_PORT}:8000"
volumes:
- ./backend/app:/app/app
- ./data:/app/data
@@ -23,13 +21,38 @@ services:
- LABEL_TEMPLATE_ID=${LABEL_TEMPLATE_ID:-vet_label}
- LABEL_SIZE=${LABEL_SIZE:-29x90}
- LABEL_TEST=${LABEL_TEST:-false}
networks:
- webapps
mosquitto:
image: eclipse-mosquitto:latest
volumes:
- ./mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
- ./mosquitto/config/pwfile:/mosquitto/config/pwfile:ro
- mosquitto_data:/mosquitto/data
- mosquitto_logs:/mosquitto/log
environment:
- PUID=1001
- PGID=1001
networks:
- webapps
frontend:
image: nginx:alpine
ports:
- "${FRONTEND_PORT}:80"
container_name: drugsdev
volumes:
- ./frontend:/usr/share/nginx/html:ro
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- backend
- mosquitto
networks:
- webapps
volumes:
mosquitto_data:
mosquitto_logs:
networks:
webapps:
external: true

View File

@@ -394,7 +394,7 @@ function renderDrugs() {
</div>
</div>
<div class="variant-actions">
<button class="btn btn-primary btn-small" onclick="prescribeVariant(${variant.id}, '${drug.name.replace(/'/g, "\\'")}', '${variant.strength.replace(/'/g, "\\'")}', '${variant.unit.replace(/'/g, "\\'")}')">🏷️ Prescribe</button>
<button class="btn btn-primary btn-small" onclick="prescribeVariant(${variant.id}, '${drug.name.replace(/'/g, "\\'")}', '${variant.strength.replace(/'/g, "\\'")}', '${variant.unit.replace(/'/g, "\\'")}')">🏷️ Prescribe & Print</button>
<button class="btn btn-success btn-small" onclick="dispenseVariant(${variant.id})">💊 Dispense</button>
<button class="btn btn-warning btn-small" onclick="openEditVariantModal(${variant.id})">Edit</button>
<button class="btn btn-danger btn-small" onclick="deleteVariant(${variant.id})">Delete</button>

View File

@@ -0,0 +1,20 @@
listener 1883
listener 9001
protocol websockets
persistence true
persistence_location /mosquitto/data/
# Authentication
allow_anonymous false
password_file /mosquitto/config/pwfile
# Logging
log_dest stdout
log_timestamp true
log_type all
# Performance
max_connections -1
max_queued_messages 1000

1
mosquitto/config/pwfile Normal file
View File

@@ -0,0 +1 @@
mqtt:$7$1000$x5foCeSdbDKyb+S/CkGI37HWJEIAQil+PfMwREfPHHbRGsUwTWKcoHXcOC4l15mj1HMH8GovYvGGOVDHkOrcBA==$kXYD9LRqSkThHyWTivw8l8/NBdXvpZ9d8qwmIJcGabyrohRdkfXcEgRbEJP7sJ43r6nPX7+p1lb+nF0Actt4ww==

View File

@@ -16,5 +16,16 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /mqtt {
proxy_pass http://mosquitto:9001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}