static void DoSends(CancellationToken ct, string iotHubConnectionString)
{
// Was cancellation already requested?
if (ct.IsCancellationRequested == true)
{
Console.WriteLine("DoSends was cancelled before it got started.");
ct.ThrowIfCancellationRequested();
}
long msgTime = 1473956534640;
var deviceClient = DeviceClient.CreateFromConnectionString(iotHubConnectionString, TransportType.Amqp);
while (true)
{
//send device to cloud telemetry
var deviceToCloudMessage = new DeviceTelemetryMessage
{
datestamp = DateTime.UtcNow,
response = "environment",
temperature = lastTemp,
humidity = 28.7,
pressure = 100912
};
var messageString = JsonConvert.SerializeObject(deviceToCloudMessage);
var sendTask = AzureIoTHub.SendDeviceToCloudMessageAsync(deviceClient, messageString);
sendTask.Wait(ct);
Console.WriteLine("Sent Message to Cloud: {0}", messageString);
ct.WaitHandle.WaitOne(TimeSpan.FromSeconds(5));//wait before sending so we are not in a tight loop
++msgTime;
}
}