M2MqttUnity  1.0
M2MQTT for Unity
M2MqttUnity.M2mqttUnityClient Class Reference

Generic MonoBehavior wrapping a MQTT client, using a double buffer to postpone message processing in the main thread. More...

Inheritance diagram for M2MqttUnity.M2mqttUnityClient:

Public Member Functions

virtual void Connect ()
 Connect to the broker using current settings. More...
 
virtual void Disconnect ()
 Disconnect from the broker, if connected. More...
 

Public Attributes

string brokerAddress = "localhost"
 
int brokerPort = 1883
 
bool isEncrypted = false
 
int connectionDelay = 500
 
int timeoutOnConnection = MqttSettings.MQTT_CONNECT_TIMEOUT
 
bool autoConnect = false
 

Protected Member Functions

virtual void OnConnecting ()
 Ovverride this method to take some actions before connection (e.g. More...
 
virtual void OnConnected ()
 Override this method to take some actions if the connection succeeded. More...
 
virtual void OnConnectionFailed (string errorMessage)
 Override this method to take some actions if the connection failed. More...
 
virtual void SubscribeTopics ()
 Ovverride this method to subscribe to MQTT topics. More...
 
virtual void UnsubscribeTopics ()
 Ovverride this method to unsubscribe to MQTT topics (they should be the same you subscribed to with SubscribeTopics() ). More...
 
virtual void OnApplicationQuit ()
 Disconnect before the application quits. More...
 
virtual void Awake ()
 Initialize MQTT message queue Remember to call base.Awake() if you override this method. More...
 
virtual void Start ()
 Connect on startup if autoConnect is set to true. More...
 
virtual void DecodeMessage (string topic, byte[] message)
 Override this method for each received message you need to process. More...
 
virtual void OnDisconnected ()
 Override this method to take some actions when disconnected. More...
 
virtual void OnConnectionLost ()
 Override this method to take some actions when the connection is closed. More...
 
virtual void Update ()
 Processing of income messages and events is postponed here in the main thread. More...
 
virtual void ProcessMqttEvents ()
 

Protected Attributes

MqttClient client
 Wrapped MQTT client More...
 

Events

Action ConnectionSucceeded
 Event fired when a connection is successfully estabilished More...
 
Action ConnectionFailed
 Event fired when failing to connect More...
 

Detailed Description

Generic MonoBehavior wrapping a MQTT client, using a double buffer to postpone message processing in the main thread.

Member Function Documentation

◆ Awake()

virtual void M2MqttUnity.M2mqttUnityClient.Awake ( )
protectedvirtual

Initialize MQTT message queue Remember to call base.Awake() if you override this method.

◆ Connect()

virtual void M2MqttUnity.M2mqttUnityClient.Connect ( )
virtual

Connect to the broker using current settings.

◆ DecodeMessage()

virtual void M2MqttUnity.M2mqttUnityClient.DecodeMessage ( string  topic,
byte []  message 
)
protectedvirtual

Override this method for each received message you need to process.

◆ Disconnect()

virtual void M2MqttUnity.M2mqttUnityClient.Disconnect ( )
virtual

Disconnect from the broker, if connected.

◆ OnApplicationQuit()

virtual void M2MqttUnity.M2mqttUnityClient.OnApplicationQuit ( )
protectedvirtual

Disconnect before the application quits.

◆ OnConnected()

virtual void M2MqttUnity.M2mqttUnityClient.OnConnected ( )
protectedvirtual

Override this method to take some actions if the connection succeeded.

◆ OnConnecting()

virtual void M2MqttUnity.M2mqttUnityClient.OnConnecting ( )
protectedvirtual

Ovverride this method to take some actions before connection (e.g.

display a message)

◆ OnConnectionFailed()

virtual void M2MqttUnity.M2mqttUnityClient.OnConnectionFailed ( string  errorMessage)
protectedvirtual

Override this method to take some actions if the connection failed.

◆ OnConnectionLost()

virtual void M2MqttUnity.M2mqttUnityClient.OnConnectionLost ( )
protectedvirtual

Override this method to take some actions when the connection is closed.

◆ OnDisconnected()

virtual void M2MqttUnity.M2mqttUnityClient.OnDisconnected ( )
protectedvirtual

Override this method to take some actions when disconnected.

◆ ProcessMqttEvents()

virtual void M2MqttUnity.M2mqttUnityClient.ProcessMqttEvents ( )
protectedvirtual

◆ Start()

virtual void M2MqttUnity.M2mqttUnityClient.Start ( )
protectedvirtual

Connect on startup if autoConnect is set to true.

◆ SubscribeTopics()

virtual void M2MqttUnity.M2mqttUnityClient.SubscribeTopics ( )
protectedvirtual

Ovverride this method to subscribe to MQTT topics.

◆ UnsubscribeTopics()

virtual void M2MqttUnity.M2mqttUnityClient.UnsubscribeTopics ( )
protectedvirtual

Ovverride this method to unsubscribe to MQTT topics (they should be the same you subscribed to with SubscribeTopics() ).

◆ Update()

virtual void M2MqttUnity.M2mqttUnityClient.Update ( )
protectedvirtual

Processing of income messages and events is postponed here in the main thread.

Remember to call ProcessMqttEvents() in Update() method if you override it.

Member Data Documentation

◆ autoConnect

bool M2MqttUnity.M2mqttUnityClient.autoConnect = false

◆ brokerAddress

string M2MqttUnity.M2mqttUnityClient.brokerAddress = "localhost"

◆ brokerPort

int M2MqttUnity.M2mqttUnityClient.brokerPort = 1883

◆ client

MqttClient M2MqttUnity.M2mqttUnityClient.client
protected

Wrapped MQTT client

◆ connectionDelay

int M2MqttUnity.M2mqttUnityClient.connectionDelay = 500

◆ isEncrypted

bool M2MqttUnity.M2mqttUnityClient.isEncrypted = false

◆ timeoutOnConnection

int M2MqttUnity.M2mqttUnityClient.timeoutOnConnection = MqttSettings.MQTT_CONNECT_TIMEOUT

Event Documentation

◆ ConnectionFailed

Action M2MqttUnity.M2mqttUnityClient.ConnectionFailed

Event fired when failing to connect

◆ ConnectionSucceeded

Action M2MqttUnity.M2mqttUnityClient.ConnectionSucceeded

Event fired when a connection is successfully estabilished


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