コード例 #1
0
        async void Upload()
        {
#if (ACCESS_IOT_HUB)
            var now           = DateTime.Now;
            var sensorReading = new Models.SensorReading();
            lock (this)
            {
                sensorReading.temp      = lastTemperature;
                sensorReading.accelx    = lastAccelX;
                sensorReading.accely    = lastAccelY;
                sensorReading.accelz    = lastAccelZ;
                sensorReading.time      = now;
                sensorReading.Latitude  = Latitude;
                sensorReading.Longitude = Longitude;
            }
            var payload = JsonConvert.SerializeObject(sensorReading);
            var message = new Message(System.Text.UTF8Encoding.UTF8.GetBytes(payload));
            try
            {
                await deviceClient.SendEventAsync(message);

                Debug.WriteLine("Send[" + counter++ + "]@" + now.Ticks);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Event Hub Send Failed:" + ex.Message);
            }
#endif
        }
コード例 #2
0
        async void Upload()
        {
#if (ACCESS_IOT_HUB)
            var sensorReading = new Models.SensorReading();
            lock (this)
            {
                sensorReading.deviceId    = deviceId.ToString();
                sensorReading.time        = DateTime.Now;
                sensorReading.Temperature = lastTemperature;
                sensorReading.Humidity    = lastHumidity;
                sensorReading.Pressure    = lastPressure;
            }
            var payload = JsonConvert.SerializeObject(sensorReading);
            var message = new Message(System.Text.UTF8Encoding.UTF8.GetBytes(payload));
            try
            {
                await deviceClient.SendEventAsync(message);

                Debug.WriteLine("Measured[" + counter++ + "]" + " T=" + sensorReading.Temperature + ", H=" + sensorReading.Humidity + ", P=" + sensorReading.Pressure);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Event Hub Send Failed:" + ex.Message);
            }
#endif
        }
コード例 #3
0
        async void Upload()
        {
#if (ACCESS_IOT_HUB)
            var now = DateTime.Now;
            var sensorReading = new Models.SensorReading()
            {
                msgId = deviceId.ToString() + now.ToString("yyyyMMddhhmmssfff")
            };
            lock (this)
            {
                sensorReading.deviceId = deviceId.ToString();
                sensorReading.temp = lastTemperature;
                sensorReading.accelx = lastAccelX;
                sensorReading.accely = lastAccelY;
                sensorReading.accelz = lastAccelZ;
                sensorReading.time = now;
                sensorReading.Latitude = Latitude;
                sensorReading.Longitude = Longitude;
            }
            var payload = JsonConvert.SerializeObject(sensorReading);
            var message = new Message(System.Text.UTF8Encoding.UTF8.GetBytes(payload));
            try
            {
                await deviceClient.SendEventAsync(message);
                Debug.WriteLine("Send[" + counter++ + "]@" + now.Ticks);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Event Hub Send Failed:" + ex.Message);
            }
#endif
        }