OpenNETCF MQTT Updated to .NET Standard

I’ve refactored the OpenNETCF MQTT library, which is a simple MQTT Client, to ne a .NET Standard 1.3 Library.  I also added a few async methods to bring it a little more up-to-date.

Source is in GitHub
Library is available via NuGet (as package ID ‘OpenNETCF.MQTT’)

Here’s a test method that generally shows how it can be used:


    [TestMethod()]
    public void ClientReceiveTest()
    {
        var receivedMessage = false;

        // create the client
        var client = new MQTTClient("test.mosquitto.org", 1883);

        // hook up the MessageReceived event with a handler
        client.MessageReceived += (topic, qos, payload) =>
        {
            Debug.WriteLine("RX: " + topic);
            receivedMessage = true;
        };

        var i = 0;
        // connect to the MQTT server
        client.Connect("OpenNETCF");
        // wait for the connection to complete
        while (!client.IsConnected)
        {
            Thread.Sleep(1000);

            if (i++ > 10) Assert.Fail();
        }

        Assert.IsTrue(client.IsConnected);

        // add a subscription
        client.Subscriptions.Add(new Subscription("OpenNETCF/#"));

        i = 0;
        while (true)
        {
            if (receivedMessage) break;

            Thread.Sleep(1000);

            // publish on our own subscribed topic to see if we hear what we send
            client.Publish("OpenNETCF/Test", "Hello", QoS.FireAndForget, false);

            if (i++ > 10) break;
        }

        Assert.IsTrue(receivedMessage);
    }

One thought on “OpenNETCF MQTT Updated to .NET Standard”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s