Beispiel #1
0
        public static void processMqttMessage(dynamic payload, string clientId)
        {
            MqttDataSet dataSet = new MqttDataSet();

            dataSet.deviceId    = clientId;
            dataSet.metricDate  = payload.metricDate.ToString();
            dataSet.metricValue = payload.metricValue.ToString();
            dataSet.deviceType  = payload.deviceType.ToString();
            dataSet.macAddress  = payload.macAddress.ToString();
            dataSet.deviceName  = payload.name.ToString();
            string jsonDataSet = JsonConvert.SerializeObject(dataSet);

            jsonDataSet = "{\"action\": \"telemetry\",\"source\": \"\",\"callback\": \"\",\"payload\": " + jsonDataSet + "}";
            Console.WriteLine(jsonDataSet);
            BrokerClient.sendMqttMessage(jsonDataSet, "Data-Controller");
        }
Beispiel #2
0
        public byte[] processMqttMessage(string topic, byte[] message)
        {
            string[] urlMembers = topic.Split("/");
            if (urlMembers.Length == 3 || urlMembers.Length == 4)
            {
                if (urlMembers[0] == "device" && urlMembers[2] == "telemetry")
                {
                    string      idDevice = urlMembers[1];
                    string      jsonData = Encoding.UTF8.GetString(message);
                    MqttDataSet data     = JsonConvert.DeserializeObject <MqttDataSet>(jsonData);
                    data.deviceId = idDevice;
                    string finalJson = JsonConvert.SerializeObject(data);

                    return(Encoding.UTF8.GetBytes(finalJson));
                }
            }
            return(Encoding.UTF8.GetBytes("null"));
        }