Table of Contents

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

topic string

The MQTT topic to publish to (e.g. "cmd/thermostat-001/set-temp")

messageJson string

The 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

message string
topic string
clientId string

Returns

bool

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

topicFilter string

The MQTT topic filter pattern (e.g. "evt/thermostat-001/#")

addonId int

The 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)

Parameters

topicFilter string

The MQTT topic filter to unsubscribe from

addonId int

The id of the addon to unsubscribe