I use MQTTnet broker:
_mqttServer = mqttFactory.CreateMqttServer(mqttServerOptions);
_mqttServer.ClientConnectedAsync += MqttServer_ClientConnectedAsync;
_mqttServer.InterceptingPublishAsync += args =>
{
_logger.LogInformation("Message received: {0}", Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment));
return CompletedTask.Instance;
}; await _mqttServer.StartAsync(mqttServerOptions);
The connection works fine and I'm able to get a message from a client with a payload but I'm not able to encode the message. Here is an example payload:
{ 209, 4, 37, 0, 0, 0, 65, 56, 48, 48, 48, 95, 67, 80, 56, 48, 53, 120, 95, 116, 101, 115, 116, 95, 99, 108, 105, 101, 110, 116, 95, 71, 70, 50, 50, 48, 55, 48, 55, 49, 51, 54, 54, 1, 232, 3, 235, 1, 222, 3, 217, 203, 211, 44, 217, 203, 211, 44, 1, 0, 1, 0, 0, 0, 8, 0, 192, 175, 112, 32, 148, 12, 218, 1, 0, 0, 176, 65 }
using UTF-8 I get:
�%???A8000_CP805x_test_client_GF2207071366������,���,?????��p ��??�A
I have no control what is sent by a client but I have been told that it is a json message. I haven't found any solution to encode it into a json format.
Please help.