如何设置遥测频率以使用C#将消息发送到物联网设备

时间:2018-10-16 17:46:10

标签: c# .net azure azure-iot-hub

我有以下代码将数据成功发送到物联网设备。 现在我想设置遥测时间跨度以连续发送数据如何配置任何指导?

  private static async void SendDeviceToCloudMessagesAsync(string deviceid , string deviceKey)
            {
                deviceClient = DeviceClient.Create("hostname", new DeviceAuthenticationWithRegistrySymmetricKey(deviceid, deviceKey), Microsoft.Azure.Devices.Client.TransportType.Mqtt);

                double minTemperature = 20;
                double minHumidity = 60;
                int messageId = 1;
                Random rand = new Random();
                while (true)
                {
                    double currentTemperature = minTemperature + rand.NextDouble() * 15;
                    double currentHumidity = minHumidity + rand.NextDouble() * 20;
                    var telemetryDataPoint = new
                    {
                        messageId = messageId++,
                        deviceId = deviceid,
                        temperature = currentTemperature,
                        humidity = currentHumidity
                    };
                    var messageString = JsonConvert.SerializeObject(telemetryDataPoint);
                    var message = new Microsoft.Azure.Devices.Client.Message(Encoding.ASCII.GetBytes(messageString));
                    message.Properties.Add("temperatureAlert", (currentTemperature > 30) ? "true" : "false");
                    await deviceClient.SendEventAsync(message);
                    Console.WriteLine("{0} > Sending message: {1}", DateTime.Now, messageString);
                    await Task.Delay(1000);
                }
            }
  

基本上,这里我使用while (true)而不是我想要的   设置

     
    

1。从每种设备输入格式发送遥测的频率为HH MM SS

         

2。模拟将以outout格式运行多长时间是HH MM SS     UI screen

  

0 个答案:

没有答案