public static Random ( string deviceId ) : string | ||
deviceId | string | |
return | string |
private static async void SendDeviceToCloudMessagesAsync() { int i = 0; DateTime start = DateTime.Now; while (run) { i++; //string telemetry = GenerateMessage(i, $"message:{i}"); string telemetry = IOTSuiteTelemetryData.Random(deviceId); DeviceClient deviceClient = CreateDeviceClient(deviceId, deviceKey); if (i == 1) { Log("Sending init data..."); var initData = IOTSuiteClientHelper.GetInitiateDeviceData(deviceId); Log(initData); await deviceClient.SendEventAsync(new Microsoft.Azure.Devices.Client.Message(Encoding.UTF8.GetBytes(initData))); Thread.Sleep(1000); continue; } await deviceClient.SendEventAsync(new Microsoft.Azure.Devices.Client.Message(Encoding.UTF8.GetBytes(telemetry))); //await deviceClient.CloseAsync(); Console.WriteLine("{0} ==> Sending message: {1}", DateTime.Now, telemetry); Thread.Sleep(1000); var time = DateTime.Now - start; if (time.Seconds >= duration) { Success($"Sent {i} messages, druation {time.Seconds} seconds"); run = false; } } Log("Exit SendMessage()..."); }
static string GenerateMessage(int seq, string message) { var msg = IOTSuiteTelemetryData.Random(deviceId); return(JsonConvert.SerializeObject(msg)); }