adacam-api/adacam_api/config.py
kayos 37aefb84c8 Initial commit: adacam-api v1.0.0
Clean Python Flask replacement for odc-api (434k lines Node.js → ~350 lines Python)
- GET /api/1/landmarks/last/{N} - last N detections from SQLite
- POST /api/1/landmarks - ingest detections + forward to AdaMaps
- GET /api/1/gnssConcise/latestValid - GPS fix from Redis
- GET /api/1/status - device status
- GET /api/1/deviceinfo - device identity
- GET /api/1/recording/frames/latest - latest frame path

No /api/1/cmd - that's the CVE, it's gone.

Includes:
- SQLite for local storage + offline queue
- Background thread for AdaMaps retry
- systemd service unit
- install.sh for device deployment
2026-03-14 08:13:04 -07:00

52 lines
1.2 KiB
Python

"""Config management for adacam-api."""
import json
import os
import uuid
CONFIG_PATH = "/data/adacam/config.json"
FIRMWARE_VERSION = "adacam-1.0.0"
_defaults = {
"device_id": None,
"adamaps_key": "adamaps-ingest-2026",
"adamaps_api": "https://api.adamaps.org",
"ap_interface": "wlp1s0f0",
"tunnel_host": "",
"tunnel_user": "",
"tunnel_port": 2222,
}
_config = None
def load():
"""Load config from disk, creating defaults if needed."""
global _config
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
if os.path.exists(CONFIG_PATH):
with open(CONFIG_PATH) as f:
_config = {**_defaults, **json.load(f)}
else:
_config = _defaults.copy()
# Generate device_id on first run
if not _config.get("device_id"):
_config["device_id"] = str(uuid.uuid4())
save()
return _config
def save():
"""Persist config to disk."""
os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
with open(CONFIG_PATH, "w") as f:
json.dump(_config, f, indent=2)
def get(key, default=None):
"""Get a config value."""
if _config is None:
load()
return _config.get(key, default)