SyMqttBox initialization
After defining your topology, you must initialize the internal MQTT engine. This step prepares the underlying client with network coordinates, security credentials, and protocol versions, but it does not open the connection yet.
To initialize the box, you will use the Initialize method and pass a configured instance of the SyMqttClientParameters class.
Network and protocol parameters
Section titled “Network and protocol parameters”The SyMqttClientParameters class holds the essential settings required to target your broker:
| Property | Type | Default Value | Description |
|---|---|---|---|
ClientId | string | Automatic Random ID | A unique identifier for the connection. Generated automatically if you leave it empty. |
TcpServer | string | Required | The host name or IP address of your MQTT broker. |
TcpPort | int | Required | The network port (usually 1883 for unencrypted or 8883 for TLS). |
User | string | "" | Username for broker authentication. |
Password | string | "" | Password for broker authentication. |
CleanSession | bool | true | Dictates if the broker should discard session state upon disconnection. |
TlsOptions | SyMqttTlsOptions | new() | Configuration object handling encryption and certificates. |
MqttProtocolVersion | SyMqttProtocolVersion | Mqtt500 | Supports Mqtt310, Mqtt311, or Mqtt500. |
Secure connections (TLS/SSL)
Section titled “Secure connections (TLS/SSL)”If you work in an industrial or production environment, you will likely need encrypted tunnels. You can configure this via the nested SyMqttTlsOptions class:
UseTls(bool): Set totrueto activate SSL/TLS encryption.RootCertificateContents(string): The raw text contents of a custom Root CA certificate file (.crtor.pem). This is useful when working with private or self-signed certificates.AllowUntrustedCertificates(bool): Whentrue, it bypasses standard chain and revocation verification errors. Use this strictly for local testing or development.
Under the hood: certificate validation logic
Section titled “Under the hood: certificate validation logic”When you populate RootCertificateContents, SyMqtt avoids relying on the operating system’s global trust store. Instead, it utilizes a custom .NET X509Chain validator inside the initialization engine. It loads your custom Root CA directly into temporary memory as a strict trust anchor, verifying the broker’s handshake cryptographically without installing files globally onto your host machine.
Initialization example
Section titled “Initialization example”Here is how you construct your client parameters and pass them to your SyMqttBox instance:
using SyMqtt;
// 1. Define the connection parametersvar clientParams = new SyMqttClientParameters{ TcpServer = "broker.hivemq.com", TcpPort = 8883, User = "app_operator", Password = "secure_password_123", CleanSession = true, MqttProtocolVersion = SyMqttProtocolVersion.Mqtt500, TlsOptions = new SyMqttTlsOptions { UseTls = true, AllowUntrustedCertificates = false // RootCertificateContents = File.ReadAllText("rootCA.crt") // Uncomment for private CA }};
// 2. Initialize the box// This prepares the internal structures but does not connect yet.mqttBox.Initialize(clientParams);Now that your orchestrator is initialized and knows how and where to connect, you are ready to fire up the network connection.
Let’s move to the next step to see how to open and manage the connection actively.