Skip to content

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.

The SyMqttClientParameters class holds the essential settings required to target your broker:

PropertyTypeDefault ValueDescription
ClientIdstringAutomatic Random IDA unique identifier for the connection. Generated automatically if you leave it empty.
TcpServerstringRequiredThe host name or IP address of your MQTT broker.
TcpPortintRequiredThe network port (usually 1883 for unencrypted or 8883 for TLS).
Userstring""Username for broker authentication.
Passwordstring""Password for broker authentication.
CleanSessionbooltrueDictates if the broker should discard session state upon disconnection.
TlsOptionsSyMqttTlsOptionsnew()Configuration object handling encryption and certificates.
MqttProtocolVersionSyMqttProtocolVersionMqtt500Supports Mqtt310, Mqtt311, or Mqtt500.

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 to true to activate SSL/TLS encryption.
  • RootCertificateContents (string): The raw text contents of a custom Root CA certificate file (.crt or .pem). This is useful when working with private or self-signed certificates.
  • AllowUntrustedCertificates (bool): When true, 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.

Here is how you construct your client parameters and pass them to your SyMqttBox instance:

using SyMqtt;
// 1. Define the connection parameters
var 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.