Live Data
SpokeZone.liveData provides publish-focused MQTT support for one-off messages and scheduled telemetry.
Connection Lifecycle
Section titled “Connection Lifecycle”- Start MQTT with
await spokeZone.liveData.connect(). - Stop MQTT with
await spokeZone.liveData.disconnect(). - Observe current connection state via
spokeZone.liveData.isConnected. - Periodic registrations are paused while disconnected and resume on the next successful
connect().
One-Off Publishing
Section titled “One-Off Publishing”Use publishJson(topic, payload, retained: ...) for direct JSON publishes.
- Returns
truewhen publish succeeds. - Returns
falsewhen not delivered (for example disconnected or transport failure). - Does not throw for runtime publish failures.
- Throws
SpokeZoneExceptionwithvalidationErroronly for invalid topic/payload input. - Supports retained messages using the
retainedflag.
Periodic Broadcasting
Section titled “Periodic Broadcasting”Use the generic scheduler for custom topics:
registerJsonBroadcast(...)accepts an async callback returningFuture<Map<String, dynamic>?>.- No message is published at registration time.
- The first publish happens on the first interval tick.
- Returning
nullskips that tick without publishing.
Each registration can be canceled independently by calling cancel() on its returned handle.
Fixed Topic Helpers
Section titled “Fixed Topic Helpers”The SDK provides helper registrations for common telemetry topics:
registerLocationBroadcast(...)publishes tomrs/d/<device-id>/mon/locationwith retained MQTT messages and payload{lat, lon, heading, speed}.registerSoftwareVersionsBroadcast(...)publishes tomrs/d/<device-id>/mon/versionswith payloadMap<String, String>.
Device IDs in these topics must be the positive integers your DeviceAuthCallbacks.deviceId implementation resolves, ensuring the numeric identifier is embedded into the MQTT topic path.
Default intervals:
- Location: every 15 seconds.
- Software versions: every 60 seconds.
Registration Status and Observability
Section titled “Registration Status and Observability”Each registration handle exposes status fields:
state:idle,running,failed, orcanceled.lastSuccessAt: timestamp of the most recent successful publish.consecutiveFailures: failure streak for recent publish attempts.
Status behavior:
- Successful publish transitions state to
running, updateslastSuccessAt, and resetsconsecutiveFailures. - Failed publish transitions state to
failedand incrementsconsecutiveFailures. cancel()transitions to terminalcanceled.
Reconnect and Auth Behavior
Section titled “Reconnect and Auth Behavior”- Connect and reconnect attempts always request the current access token from the active
SpokeZoneauth provider. - Device auth proactively refreshes tokens when JWT expiry is within 12 hours.
- MQTT connect timeout defaults to 20 seconds.
- Reconnect delay behavior is configured with
SpokeZoneConfig.liveDataBackoffStrategy.- Default sequence:
5s,15s,30s,60s,120s,300s, then repeat300s.
- Default sequence: