Exemple #1
0
        static void Main(string[] args)
        {
            string jsonMessage;

            EventSinkSetup();

            //Build a collection of device emulators
            List <IotDevice> _devices = new List <IotDevice>();

            for (int i = 1; i <= _deviceCount; i++)
            {
                _devices.Add(new IotDevice(i));
            }

            //Run until someone presses the escape key
            Console.WriteLine("Press ESC to stop");
            do
            {
                while (!Console.KeyAvailable)
                {
                    //Iterate the devices to get a reading.
                    foreach (IotDevice device in _devices)
                    {
                        //Get the reading object and send it to event hub.
                        IotDeviceReading reading = device.GetNextReading();
                        SendPayload(reading);
                        Console.WriteLine(JsonConvert.SerializeObject(reading));
                    }
                    Thread.Sleep(_timeToSleep);
                }
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
Exemple #2
0
        private static void SendPayload(IotDeviceReading reading)
        {
            string jsonMessage;

            if (useCosmos != "true")
            {
                jsonMessage = JsonConvert.SerializeObject(reading);
                _eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(jsonMessage)));
            }
            else
            {
                _cosmosClient.CreateDocumentAsync(_cosmosCollection.DocumentsLink, reading).Wait();
            }
        }
Exemple #3
0
        public IotDevice(int DeviceID)
        {
            SampleDoubleGenerator startingVolume = new SampleDoubleGenerator(.2, .9);

            _reading          = new IotDeviceReading();
            _reading.DeviceID = DeviceID;
            _flowRate         = .0001;

            //My random generator does peaks not floors. So inverting these numbers 1 - value will be the sent value
            _pulseOximetry   = new SampleDoubleGenerator(0.01, 0.05); //, .01, 1000);
            _pulse           = new SampleDoubleGenerator(60, 100);
            _systolic        = new SampleDoubleGenerator(120, 140);   //, 200, 100);
            _diastolic       = new SampleDoubleGenerator(60, 80);     //, 100, 100);
            _bodyTemperature = new SampleDoubleGenerator(95, 101);    //, 105, 100);
            _respirationRate = new SampleDoubleGenerator(10, 30);     //, 60, 100);
            _remainingVolume = startingVolume.GetNextValue();
        }