|
|
|
|
@ -17,6 +17,7 @@ namespace MqttTest |
|
|
|
|
// generate a clientID and connect to Broker |
|
|
|
|
string clientId = Guid.NewGuid().ToString(); |
|
|
|
|
client.Connect(clientId); |
|
|
|
|
Console.WriteLine($"Connect result: {client.IsConnected}"); |
|
|
|
|
// subscribe to a topic |
|
|
|
|
client.Subscribe(new string[] { "scada/status" }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); |
|
|
|
|
// Endless loop |
|
|
|
|
@ -29,7 +30,8 @@ namespace MqttTest |
|
|
|
|
if (key.Key == ConsoleKey.Spacebar) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine($"Sending \"Test Message\" to topic 'scada/status'"); |
|
|
|
|
client.Publish("scada/status", Encoding.ASCII.GetBytes("Test Message")); |
|
|
|
|
var publishResult = client.Publish("scada/status", Encoding.ASCII.GetBytes("Test Message")); |
|
|
|
|
Console.WriteLine($"Publish result: {publishResult}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|