Field setups often relay through a phone/gateway that owns the MQTT connection, so the publishing credential and the instrument are now separate concepts: - Points messages carry a "serial" identifying the locator receiver; unknown serials are auto-registered as devices in the publisher's org (name "Locator <serial>"). Device.mqttUsername is now optional and serialNumber is unique per org. - LocatePoint gains standard receiver telemetry: frequencyHz, currentMa, signalDb, gainDb, locateMode (PEAK/NULL/BROAD_PEAK/SONDE), phaseDeg, compassDeg, distortionPct, plus GPS quality columns vAccuracy, satellites, hdop. All optional; raw payload still kept. - Migration hand-edited to preserve the generated geom column and its GIST index (Prisma diff wanted to drop both). - REST create/point DTOs, map tooltips, job-detail latest-point readout, devices settings form, seed, and the sample publisher all carry the new fields. - Added .dockerignore for backend/web: COPY . . was clobbering the image's freshly generated Prisma client with the host's stale node_modules, breaking image builds after schema changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
"""Publish sample locate points to the UlHub backend via MQTT.
|
|
|
|
The backend subscribes to devices/# and expects points at
|
|
devices/{mqttUsername}/points with a JSON body:
|
|
|
|
{"serial": "...", "ticket": "TKT-...",
|
|
"points": [{"lat": .., "lng": .., "ts": "ISO8601", ...}]}
|
|
|
|
The MQTT username identifies the publisher (app/gateway) and its org; "serial"
|
|
names the locator receiver the readings came from (auto-registered on first
|
|
sight). Points for an unknown ticket auto-create a stub job (source=DEVICE).
|
|
"""
|
|
|
|
import random
|
|
|
|
import json
|
|
import os
|
|
import time
|
|
from datetime import datetime, timezone
|
|
|
|
import paho.mqtt.client as mqtt
|
|
|
|
BROKER_HOST = os.getenv("MQTT_HOST", "127.0.0.1")
|
|
BROKER_PORT = int(os.getenv("MQTT_PORT", "1883"))
|
|
USERNAME = os.getenv("MQTT_USERNAME", "testuser")
|
|
PASSWORD = os.getenv("MQTT_PASSWORD", "testpass")
|
|
SERIAL = os.getenv("SERIAL", "DEMO-0001")
|
|
TICKET = os.getenv("TICKET", "TKT-2026-0001")
|
|
INTERVAL = float(os.getenv("MQTT_INTERVAL", "2"))
|
|
|
|
# Walk northeast from this location, one point per interval
|
|
START_LAT = float(os.getenv("START_LAT", "33.15012345"))
|
|
START_LNG = float(os.getenv("START_LNG", "-96.83512345"))
|
|
|
|
TOPIC = f"devices/{USERNAME}/points"
|
|
|
|
client = mqtt.Client()
|
|
client.username_pw_set(USERNAME, PASSWORD)
|
|
client.connect(BROKER_HOST, BROKER_PORT, 60)
|
|
client.loop_start()
|
|
|
|
try:
|
|
seq = 0
|
|
while True:
|
|
payload = {
|
|
"serial": SERIAL,
|
|
"ticket": TICKET,
|
|
"points": [
|
|
{
|
|
"lat": START_LAT + seq * 0.0000135,
|
|
"lng": START_LNG + seq * 0.0000042,
|
|
"alt": 187.4 + seq * 0.02,
|
|
"fix": "FIXED_RTK",
|
|
"hAcc": 0.014,
|
|
"vAcc": 0.021,
|
|
"sats": random.randint(18, 26),
|
|
"hdop": 0.7,
|
|
"depth": round(1.1 + random.uniform(0, 0.3), 2),
|
|
"freqHz": 33000,
|
|
"currentMa": round(50 - seq * 0.4 + random.uniform(-1, 1), 1),
|
|
"signalDb": round(62 - seq * 0.2 + random.uniform(-0.5, 0.5), 1),
|
|
"gainDb": 40,
|
|
"mode": "PEAK",
|
|
"compassDeg": round(17.5 + random.uniform(-3, 3), 1),
|
|
"distortionPct": round(random.uniform(2, 8), 1),
|
|
"utility": "GAS",
|
|
"seq": seq + 1,
|
|
"ts": datetime.now(timezone.utc).isoformat(),
|
|
}
|
|
],
|
|
}
|
|
client.publish(TOPIC, json.dumps(payload), qos=1)
|
|
print(f"published point {seq + 1} to {TOPIC} (ticket {TICKET})")
|
|
seq += 1
|
|
time.sleep(INTERVAL)
|
|
except KeyboardInterrupt:
|
|
print("stopped")
|
|
finally:
|
|
client.loop_stop()
|
|
client.disconnect()
|