Reputation: 15
I am having problem showing the topic from a mqtt broker. All I get is System.byte[]
I know I'm connected as every time I publish a message from hiveMQ another System.bytes get added to the console. Please help.
static void Main(string[] args)
{
MqttClient client = new MqttClient("myip", 1883,false,null,null,0,null,null);
client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
client.Connect(Guid.NewGuid().ToString());
ushort msgId = client.Subscribe(new string[] { "broTest" },
new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
client.ProtocolVersion = MqttProtocolVersion.Version_3_1_1;
}
static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
// handle message received
Console.WriteLine("message=" + e.Message.ToString());
}
Upvotes: 0
Views: 4562
Reputation: 5264
you have to convert byte[] to string, in order to show in console.
static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
Console.WriteLine(Encoding.UTF8.GetString(e.Message));
}
Upvotes: 3