Documentation Index
Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
Use this file to discover all available pages before exploring further.
Letting Web Apps Send Data to MQTT
Sometimes the data you need isn’t coming from a sensor — it’s coming from a web app, a mobile app, a partner’s webhook, or a system that only speaks HTTP. Coreflux’sREST_API route can run in server mode, exposing an HTTP endpoint on the broker itself. When something POSTs to that endpoint, the route publishes the body to an MQTT topic, just like a sensor message.
When to Reach for This
- A web dashboard or mobile app needs to push commands or readings without implementing an MQTT client
- A third-party service (Stripe, GitHub, Slack, your CRM, an IoT vendor’s cloud) supports HTTP webhooks but not MQTT
- A legacy system can call HTTP endpoints but doesn’t speak MQTT
- You’re behind a firewall that allows HTTP but not MQTT
The Pattern
- The route opens an HTTP server on port 8080.
- When something POSTs to
http://your-broker:8080/api/sensorswith the right Basic Auth credentials, the body of the request is published tosensors/from/http. - From there, any Action subscribed to that topic processes it like a normal MQTT message — type-cast, normalize, publish into your UNS, store in the database.
ENV and SECRET. Use the same approach for receiving CRM events, payment notifications, AI service callbacks, or anything else the outside world wants to push to you.
Pulling Data from External APIs
The mirror image of webhook ingestion: when you need to call out to a third-party API. The sameREST_API route in client mode turns an MQTT message into an outbound HTTP request, then publishes the response back to MQTT. Combined with GET ENV and GET SECRET, the credentials never appear in the route definition.
When to Reach for This
Whenever a Coreflux system needs information that lives outside it: weather forecasts for HVAC control, exchange rates for billing, geocoding for a fleet, traffic data for routing, AI/ML inference, public data feeds.The Pattern
Weather data is useful in nearly every domain — solar parks need irradiance forecasts, smart buildings adjust HVAC for outdoor temperature, fleets reroute around storms, agriculture schedules irrigation. Here’s a route that calls a weather API. The base URL and credentials come from environment variables and secrets, so the same route works in dev and prod:- Some Action publishes a JSON message like
{"location": "Lisbon"}toweather/request. - The route picks it up, builds the URL with the location filled in, and fires an authenticated HTTP GET.
- The API responds with the weather data.
- The route publishes that response to
weather/response.
weather/response:
secrets.json, the API URL sits in .env, and the Route definition stays portable across deployments. If the API key rotates, you update the secret and nothing else changes.
Live KPIs from a Database
Database routes are not just for inserting data. The sameEVENT syntax supports SELECT queries — either triggered by an MQTT message or run on a fixed schedule. This is how you turn a historian into a live KPI feed: one query, repeated automatically, results published as ordinary MQTT messages that any consumer can subscribe to.
When to Reach for This
When you need rolling KPIs (averages, counts, peaks) that consumers should subscribe to like any other topic, or when you need on-demand historical lookups (last hour of readings for a device) triggered by an MQTT request. Skip it for one-off ad-hoc queries — for those, just query the database directly.Scheduled Queries: Live Aggregates
A common need in solar operations: publish the average power output of the last 60 seconds every minute, for every inverter, with no polling code anywhere.- Every 60 seconds, the route automatically runs the SQL query against your historian.
- The result set is serialized as JSON and published to
kpi/inverters/avg_power_60s. - Anyone listening — a dashboard, an Action, an AI agent — sees a fresh KPI every minute as a regular MQTT message.
On-Demand Queries: Historical Lookups
For queries that should run when asked rather than on a clock, swapWITH EVERY for WITH SOURCE_TOPIC:
inv-01 to kpi/request/history returns the last hour of readings on kpi/result/history. Operators, AI agents, or other systems can pull historical context on demand.
The pattern at a glance: raw data lives in the database, KPIs and historical lookups are exposed as MQTT topics. Whether you’re tracking solar inverters, traffic light timings, or refrigerated truck temperatures, your dashboards and downstream consumers don’t care where the data physically lives — they just subscribe to topics like everything else.
Keeping Credentials Out of Your Code
Never hardcode database passwords, API keys, or broker credentials in your code. Coreflux gives you two runtime stores — one for ordinary configuration, one for secrets that need to be encrypted.When to Reach for This
The first time you deploy outside your laptop — or earlier if you’re committing your notebook to git from day one. Get the habit before you have any real credentials in flight; retrofittingGET SECRET into a working system is more painful than starting with it.
The Two Operations
GET ENV "NAME"reads from a managed.envfile. Use it for non-sensitive configuration: hostnames, ports, region tags, feature flags. Safe to log.GET SECRET "NAME"reads fromsecrets.json, which is encrypted at rest with AES-256-GCM. Use it for anything sensitive: passwords, API keys, tokens. Never logged.
.env file and secrets.json differ between environments.
To register a secret, run this once from a notebook or the broker console:
Next Steps
REST API Routes
Client and server mode, endpoints, and authentication.
Environment Variables and Secrets
.env, secrets.json, and secure deployment.
