MQTT C#

Basically all you need can be found here. Tested and it worked with mosquitto

https://github.com/chkr1011/MQTTnet/wiki/Client

here is working sample to send message:

var client = new MqttFactory().CreateMqttClient();
var options = new MqttClientOptionsBuilder()
.WithClientId($"HomeMessenger1")
.WithTcpServer("192.168.1.10", 1883)
.WithCredentials("bud", "%spencer%")
//.WithTls()
.WithCleanSession()
.Build();

 System.Threading.CancellationToken cancellationToken;
        await client.ConnectAsync(options, cancellationToken);

        var message = new MqttApplicationMessageBuilder()
            .WithTopic("Home/gate")
            .WithPayload("H")
            .WithExactlyOnceQoS()
            .WithRetainFlag()
            .Build();
        await client.PublishAsync(message, cancellationToken);    

Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *