Class CPMQTTBaseClass
- Namespace
- Contensive.BaseClasses
- Assembly
- CPBase.dll
MQTT interface for publishing messages to IoT devices and subscribing to receive messages from them. Configuration is set through site properties: mqtt endpoint, mqtt broker port, mqtt certificate filename, mqtt certificate password, mqtt root certificate filename.
public abstract class CPMQTTBaseClass
- Inheritance
-
CPMQTTBaseClass
- Inherited Members
Methods
Publish(string, string)
Publish a JSON message to an MQTT topic (e.g. to send a command to an IoT device).
public abstract bool Publish(string topic, string messageJson)
Parameters
topicstringThe MQTT topic to publish to (e.g. "cmd/thermostat-001/set-temp")
messageJsonstringThe JSON message payload
Returns
- bool
true if the message was published successfully
Publish(string, string, string)
Publish a message to a topic (legacy overload, prefer Publish(topic, messageJson))
[Obsolete("Use Publish(topic, messageJson) instead. The clientId is now managed internally.")]
public abstract bool Publish(string message, string topic, string clientId)
Parameters
Returns
Subscribe(string, int)
Subscribe an addon to receive messages matching an MQTT topic filter. When a message arrives on a matching topic, the addon is executed with cp.Doc.GetText("mqtt-topic") and cp.Doc.GetText("mqtt-message") available. Supports MQTT wildcards: + (single-level) and # (multi-level).
public abstract void Subscribe(string topicFilter, int addonId)
Parameters
topicFilterstringThe MQTT topic filter pattern (e.g. "evt/thermostat-001/#")
addonIdintThe id of the addon to execute when a matching message arrives
Unsubscribe(string, int)
Unsubscribe an addon from an MQTT topic filter.
public abstract void Unsubscribe(string topicFilter, int addonId)