public static string Random(string deviceId)
        {
            IOTSuiteTelemetryData data = new IOTSuiteTelemetryData();
            var random = new Random((int)DateTime.Now.Ticks);

            data.DeviceId = deviceId;
            data._0101    = random.Next(0, 4);   //1
            data._0102    = random.Next(0, 4);   //2;
            data._0103    = random.Next(23, 33); //32;
            data._0104    = random.Next(36, 46); //45;
            data._0104    = random.Next(78, 88); //87;

            return(JsonConvert.SerializeObject(data));
        }
Пример #2
0
        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()...");
        }
Пример #3
0
        public static string Random(string deviceId)
        {
            IOTSuiteTelemetryData data = new IOTSuiteTelemetryData();
            var random = new Random((int)DateTime.Now.Ticks);

            data.DeviceId  = deviceId;
            data._0        = random.Next(300, 400); //1
            data._100      = random.Next(300, 400); //2;
            data._101      = random.Next(300, 400); //32;
            data._102      = random.Next(300, 400); //45;
            data._0106     = (_106_Changed % _106_Change_Interval == 0 ? GetErrorCode(): _106_LastValue);
            _106_LastValue = data._0106;
            if (data._0106 == 1001 || data._0106 == 1002)
            {
                data._104 = 0;
            }
            else if (data._0106 == 0)
            {
                data._104 = random.Next(1, 4);
            }
            return(JsonConvert.SerializeObject(data));
        }
 public static string Random(string deviceId)
 {
     IOTSuiteTelemetryData data = new IOTSuiteTelemetryData();
     var random = new Random((int)DateTime.Now.Ticks);
     data.DeviceId = deviceId;
     data._0 = random.Next(300, 400);//1
     data._100 = random.Next(300, 400);//2;
     data._101 = random.Next(300, 400);//32;
     data._102 = random.Next(300, 400);//45;
     data._0106 = (_106_Changed % _106_Change_Interval == 0 ? GetErrorCode(): _106_LastValue);
     _106_LastValue = data._0106;
     if (data._0106 == 1001 || data._0106 == 1002)
     {
         data._104 = 0;
     }
     else if(data._0106 == 0)
     {
         data._104 = random.Next(1, 4);
     }
     return JsonConvert.SerializeObject(data);
 }
Пример #5
0
        static string GenerateMessage(int seq, string message)
        {
            var msg = IOTSuiteTelemetryData.Random(deviceId);

            return(JsonConvert.SerializeObject(msg));
        }
        public static string Random(string deviceId)
        {
            IOTSuiteTelemetryData data = new IOTSuiteTelemetryData();
            var random = new Random((int)DateTime.Now.Ticks);
            data.DeviceId = deviceId;
            data._0101 = random.Next(0, 4);//1
            data._0102 = random.Next(0, 4);//2;
            data._0103 = random.Next(23, 33);//32;
            data._0104 = random.Next(36, 46);//45;
            data._0104 = random.Next(78, 88);//87;

            return JsonConvert.SerializeObject(data);
        }