Package HiveMqtt by Peter Giacomo Lombardo 0.2.0

Hi, I using package HiveMqtt by Peter Giacomo Lombardo 0.2.0 , but I can’t publish data to MQTT broker.
Client was connected succes.

Example C#:
var res = await client.PublishAsync(
“hivemqdemo/telemetry/netica/temparature/sensor1”,
“55”,
QualityOfService.AtMostOnceDelivery
).ConfigureAwait(false);

With WebClient I publish message successffuly.

Hello @Mitja ,

Welcome to the HiveMQ Community!

To confirm, is the broker that is being utilized a HiveMQ Cloud deployment, or is this a local broker implementation?

If using the HiveMQ Cloud broker, it is important to remember that TLS is required to establish a connection. Is TLS configured for this client implementation? This is typically configured via HiveMQClientOptions - a code snippet is included below.

var options = new HiveMQClientOptions
{
    Host = "CloudIdentifier.s1.eu.hivemq.cloud",
    Port = 8883,
    UseTLS = true,
    UserName = 'myusername',
    Password = "mypassword',
}

Best,
Aaron from the HiveMQ Team

Hello Aaron. Thanks for the quick reply.
I use HiveMQ Cloud broker.
I configure TLS configuration when connect to HiveMQ Cloud broker.

For test I use C# windows form app.
I have 4 basic buttons on the form.
MQTT Connect, Publish, Subscribe and Disconnect.

  1. When I press the MTQQ Connect button, the code below (Connect) is executed.
    According to the returned status, the client successfully connects to HiveMQ Cloud broker.

public async Task Connect()
{
// Connect to MQTT broker …
var options = new HiveMQClientOptions();
options.Host = “e3153f490eb146e091ccb7178e61ff39.s2.eu.hivemq.cloud”;
options.Port = 8883;
options.UseTLS = true;
options.UserName = “*******”;
options.Password = “*****”;

        Console.WriteLine($"Connecting to {options.Host} on port {options.Port} ...");
        var client = new HiveMQClient(options);
        client.AfterConnect += AfterConnectHandler;

        // Once complete, you can connect to your MQTT broker and display your connection status on the console.
        Console.WriteLine($"Connecting to {options.Host} on port {options.Port} ...");

        // Connect
        HiveMQtt.Client.Results.ConnectResult connectResult;
        try
        {
            connectResult = await client.ConnectAsync().ConfigureAwait(false);
            if (connectResult.ReasonCode == ConnAckReasonCode.Success)
            {
                Console.WriteLine($"Connect successful: {connectResult}");
            }
            else
            {
                // FIXME: Add ToString
                Console.WriteLine($"Connect failed: {connectResult}");
                Environment.Exit(-1);
            }
        }
        catch (System.Net.Sockets.SocketException e)
        {
            Console.WriteLine($"Error connecting to the MQTT Broker with the following socket error: {e.Message}");
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine($"Error connecting to the MQTT Broker with the following message: {e.Message}");
            Environment.Exit(-1);
        }
    }
  1. When the connection is established, I press the Published button and the code below is executed.

    var res = await client.PublishAsync(
    “hivemqdemo/telemetry/netica/temparature/sensor1”,
    “55”,
    QualityOfService.AtMostOnceDelivery
    ).ConfigureAwait(false);

and return result value

Regards,

Mitja

Now I try use MQTTnet and this works OK.

Regards,

Mitja