Aquarium Cooling Controller
ESP32 firmware for aquarium cooling fan control, monitoring, telemetry, and fault handling.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
MqttTelemetry Class Reference

Maintains Wi-Fi/MQTT connections and publishes controller telemetry. More...

#include <mqtt_telemetry.h>

Public Member Functions

 MqttTelemetry ()
 Creates an uninitialized telemetry publisher.
 
void begin (uint32_t nowMs)
 Starts telemetry connection management.
 
void update (uint32_t nowMs)
 Maintains Wi-Fi and MQTT reconnect attempts.
 
bool publishTelemetry (uint32_t nowMs, const ControlSnapshot &controlSnapshot, const ControlConfig &controlConfig, const OtaTelemetrySnapshot &otaSnapshot, const FaultMonitorSnapshot &faultSnapshot, const FaultPolicySnapshot &policySnapshot, const RemoteConfigStatus &remoteConfigStatus, bool force)
 Publishes a complete telemetry snapshot when connected.
 
void setRemoteConfigCallback (RemoteConfigCallback callback, void *context)
 Registers a callback for validated MQTT /set topic dispatch.
 
void printStatus (Stream &out)
 Prints current Wi-Fi/MQTT status to a stream.
 
bool enabled () const
 Indicates whether network telemetry is configured and enabled.
 
bool wifiConnected () const
 Indicates whether Wi-Fi is currently connected.
 
bool mqttConnected ()
 Indicates whether MQTT is currently connected.
 

Detailed Description

Maintains Wi-Fi/MQTT connections and publishes controller telemetry.

Connection management is non-blocking from the caller's point of view: update() performs periodic reconnect attempts while publishTelemetry() emits the latest controller state when a broker connection is available. Topic names and credentials come from the network configuration macros.

Member Function Documentation

◆ begin()

void MqttTelemetry::begin ( uint32_t  nowMs)

Starts telemetry connection management.

Parameters
nowMsCurrent monotonic timestamp in milliseconds.

◆ enabled()

bool MqttTelemetry::enabled ( ) const

Indicates whether network telemetry is configured and enabled.

Returns
True when telemetry should attempt Wi-Fi/MQTT operation.

◆ mqttConnected()

bool MqttTelemetry::mqttConnected ( )

Indicates whether MQTT is currently connected.

Returns
True when the MQTT client is connected.

◆ printStatus()

void MqttTelemetry::printStatus ( Stream &  out)

Prints current Wi-Fi/MQTT status to a stream.

Parameters
outDestination stream.

◆ publishTelemetry()

bool MqttTelemetry::publishTelemetry ( uint32_t  nowMs,
const ControlSnapshot controlSnapshot,
const ControlConfig controlConfig,
const OtaTelemetrySnapshot otaSnapshot,
const FaultMonitorSnapshot faultSnapshot,
const FaultPolicySnapshot policySnapshot,
const RemoteConfigStatus remoteConfigStatus,
bool  force 
)

Publishes a complete telemetry snapshot when connected.

The payload is split across stable topic suffixes so FHEM or other home automation integrations can subscribe to individual state values. When force is false, the method respects the configured publish interval.

Parameters
nowMsCurrent monotonic timestamp in milliseconds.
controlSnapshotLatest control-engine state.
controlConfigLatest active staged-control configuration.
otaSnapshotLatest OTA maintenance state.
faultSnapshotLatest fan fault-monitor state.
policySnapshotLatest fault-policy state.
remoteConfigStatusLatest remote-configuration apply status.
forceTrue to publish even before the normal interval elapses.
Returns
True when the publish attempt completed successfully.

◆ setRemoteConfigCallback()

void MqttTelemetry::setRemoteConfigCallback ( RemoteConfigCallback  callback,
void *  context 
)

Registers a callback for validated MQTT /set topic dispatch.

The telemetry layer only routes the subscribed topic suffix and raw payload bytes. Validation and persistence remain in the sketch so local control policy is owned by the main firmware orchestration.

Parameters
callbackCallback invoked for supported remote configuration topics.
contextOpaque caller-owned pointer forwarded to the callback.

◆ update()

void MqttTelemetry::update ( uint32_t  nowMs)

Maintains Wi-Fi and MQTT reconnect attempts.

Parameters
nowMsCurrent monotonic timestamp in milliseconds.

◆ wifiConnected()

bool MqttTelemetry::wifiConnected ( ) const

Indicates whether Wi-Fi is currently connected.

Returns
True when Wi-Fi is connected.

The documentation for this class was generated from the following files: