Exemple #1
0
        static void Main(string[] args)
        {
            // check for device key
            if (args.Length == 0)
            {
                System.Console.WriteLine("Please pass a device key as arg[0]");
                return;
            }
            deviceKey = args[0];

            Console.WriteLine("Simulate Band device {0} with device key {1} pushing data to IoT hub {2}\n", deviceName, deviceKey, iotHubUri);

            // connect to IoT Hub

            deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(deviceName, deviceKey));

            // set up simulated msband data

            Random rnd = new Random();

            if (_randomSeed > 0)
            {
                rnd = new Random(_randomSeed);
            }

            DeviceTelemetry telemetry = new DeviceTelemetry();

            telemetry.DeviceId  = deviceName;
            telemetry.Room      = room;
            telemetry.UVIndex   = 0;
            telemetry.SkinTemp  = 0;
            telemetry.HeartRate = 70;

            // send data to IoT Hub

            for (int i = 0; i < _interations; i++)
            {
                // update random telemetry
                int step = rnd.Next(0 - _stepSize, _stepSize + 1);
                telemetry.HeartRate += step;
                telemetry.Timestamp  = DateTime.Now.ToString();

                // transmit telemetry
                Console.WriteLine("{3}> sending data #{0} for band {2} = '{1}'", i, JsonConvert.SerializeObject(telemetry), deviceName, DateTime.Now);
                SendTelemetryAsync(telemetry);

                // wait
                Thread.Sleep(_sendIntervalms);
            }

            Console.WriteLine("Press <enter> to exit");
            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Simulate Band device {0}\n", deviceName);

            // connect to IoT Hub

            deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(deviceName, deviceKey));

            // set up simulated msband data

            Random rnd = new Random();

            if (_randomSeed > 0)
            {
                rnd = new Random(_randomSeed);
            }

            DeviceTelemetry telemetry = new DeviceTelemetry();

            telemetry.DeviceId  = deviceName;
            telemetry.UVIndex   = 0;
            telemetry.SkinTemp  = 0;
            telemetry.HeartRate = 70;

            // send data to IoT Hub

            for (int i = 0; i < _interations; i++)
            {
                // update random telemetry
                int step = rnd.Next(0 - _stepSize, _stepSize + 1);
                telemetry.HeartRate += step;
                telemetry.Timestamp  = DateTime.Now.ToString();

                // transmit telemetry
                Console.WriteLine("{3}> sending data #{0} for band {2} = '{1}'", i, JsonConvert.SerializeObject(telemetry), deviceName, DateTime.Now);
                SendTelemetryAsync(telemetry);

                // wait
                Thread.Sleep(_sendIntervalms);
            }

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Simulate Band device {0}\n", deviceName);

            // connect to IoT Hub

            deviceClient = DeviceClient.Create(iotHubUri, new DeviceAuthenticationWithRegistrySymmetricKey(deviceName, deviceKey));

            // set up simulated msband data

            Random rnd = new Random();
            if (_randomSeed > 0)
                rnd = new Random(_randomSeed);

            DeviceTelemetry telemetry = new DeviceTelemetry();
            telemetry.DeviceId = deviceName;
            telemetry.UVIndex = 0;
            telemetry.SkinTemp = 0;
            telemetry.HeartRate = 70;

            // send data to IoT Hub 

            for (int i = 0; i < _interations; i++)
            {
                // update random telemetry
                int step = rnd.Next(0 - _stepSize, _stepSize + 1);
                telemetry.HeartRate += step;
                telemetry.Timestamp = DateTime.Now.ToString();

                // transmit telemetry 
                Console.WriteLine("{3}> sending data #{0} for band {2} = '{1}'", i, JsonConvert.SerializeObject(telemetry), deviceName, DateTime.Now);
                SendTelemetryAsync(telemetry);

                // wait
                Thread.Sleep(_sendIntervalms);
            }

            Console.ReadLine();
        }
Exemple #4
0
 // send telemetry to IoTHub
 private static async void SendTelemetryAsync(DeviceTelemetry telemetry)
 {
     var messageString = JsonConvert.SerializeObject(telemetry);
     var message       = new Message(Encoding.ASCII.GetBytes(messageString));
     await deviceClient.SendEventAsync(message);
 }
 // send telemetry to IoTHub
 private static async void SendTelemetryAsync(DeviceTelemetry telemetry)
 {
     var messageString = JsonConvert.SerializeObject(telemetry);
     var message = new Message(Encoding.ASCII.GetBytes(messageString));
     await deviceClient.SendEventAsync(message);
 }