Exemplo n.º 1
0
        private (Guid idDevace, int message, int[] logMoisture) ParseMessageReceived(MqttApplicationMessageReceivedEventArgs eventArgs)
        {
            Guid idDevace = eventArgs.GetGuidSerialNumberReceived();

            byte[] payload = eventArgs.ApplicationMessage.Payload;

            string[] message = Encoding.UTF8.GetString(payload, 0, payload.Length).Split('/');

            int[] arr   = new int[10];
            int   index = 0;

            for (int i = message.Length - 2; i > 1; i--)
            {
                arr[index] = Convert.ToInt32(message[i]);
                index++;
            }


            int  value;
            bool isParse = int.TryParse(message[1], out value);

            if (!isParse)
            {
                throw new Exception("Value is not valid");
            }

            return(idDevace, value, arr);
        }
Exemplo n.º 2
0
        private (Guid idDevice, string message) ParseMessageReceived(MqttApplicationMessageReceivedEventArgs eventArgs)
        {
            Guid idDevice = eventArgs.GetGuidSerialNumberReceived();

            byte[] payload = eventArgs.ApplicationMessage.Payload;

            string message = Encoding.UTF8.GetString(payload, 0, payload.Length).Split('/')[1];

            return(idDevice, message);
        }