private static IoTCMessage parseMqttMessage(byte[] payload)
        {
            var         stringPayload = Encoding.UTF8.GetString(payload);
            IoTCMessage iotcMessage   = new IoTCMessage();

            var jsonElement = JsonDocument.Parse(stringPayload).RootElement;

            iotcMessage.payload.creationTimeUtc = jsonElement.GetProperty("time").ToString();

            var device = jsonElement.GetProperty("device");

            iotcMessage.deviceId = device.GetProperty("id").ToString();
            iotcMessage.modelId  = device.GetProperty("driver").ToString();

            var state = jsonElement.GetProperty("state");

            if (state.GetProperty("payload").ValueKind == JsonValueKind.Object)
            {
                iotcMessage.payload.data = state.GetProperty("payload");
            }
            else
            {
                iotcMessage.payload.data = new { raw = state.GetProperty("payload").ToString() };
            }

            return(iotcMessage);
        }
        private static async Task sendDeviceMessage(IoTCMessage iotcMessage)
        {
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            var content = iotcMessage.GetPayloadAsStringContent();

            content.Headers.Add("x-api-key", httpApiKey);

            var completeUrl = String.Format("{0}/devices/{1}/messages/events", httpUrl, iotcMessage.deviceId);

            Console.WriteLine(completeUrl);
            await httpClient.PostAsync(completeUrl, content);
        }