public MainPage()
        {
            this.InitializeComponent();

            _eventHubIngest = new EventHubIngest();

            _gpioController = GpioController.GetDefault();
            if (_gpioController == null)
            {
                return;
            }

            _gpioSuccessPin = _gpioController.OpenPin(_ledSuccessPin);
            _gpioSuccessPin.SetDriveMode(GpioPinDriveMode.Output);
            _gpioSuccessPin.Write(GpioPinValue.Low);

            _gpioErrorPin = _gpioController.OpenPin(_ledErrorPin);
            _gpioErrorPin.SetDriveMode(GpioPinDriveMode.Output);
            _gpioErrorPin.Write(GpioPinValue.Low);

            _dispatcherTimer          = new DispatcherTimer();
            _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1000);
            _dispatcherTimer.Tick    += (sender, e) => {
                _gpioSuccessPin.Write(GpioPinValue.High);
                _gpioErrorPin.Write(GpioPinValue.High);

                bool ingestTask = _eventHubIngest.TelemetryIngest(new Telemetry()
                {
                    DeviceId    = "Device-78",
                    Humidity    = 10,   //Read from Sensors
                    Pollution   = 100,  //Read from Sensors
                    Temperature = 35,   //Read from Sensors
                });


                //Check if pins are available
                if (_gpioController == null || _gpioSuccessPin == null)
                {
                    return;
                }

                _gpioSuccessPin.Write(ingestTask ? GpioPinValue.Low : GpioPinValue.High);
                _gpioErrorPin.Write(ingestTask ? GpioPinValue.High : GpioPinValue.Low);
            };
            _dispatcherTimer.Start();
        }
Пример #2
0
        public MainPage()
        {
            this.InitializeComponent();

            _eventHubIngest = new EventHubIngest();

            _gpioController = GpioController.GetDefault();
            if (_gpioController == null)
                return;

            _gpioSuccessPin = _gpioController.OpenPin(_ledSuccessPin);
            _gpioSuccessPin.SetDriveMode(GpioPinDriveMode.Output);
            _gpioSuccessPin.Write(GpioPinValue.Low);

            _gpioErrorPin = _gpioController.OpenPin(_ledErrorPin);
            _gpioErrorPin.SetDriveMode(GpioPinDriveMode.Output);
            _gpioErrorPin.Write(GpioPinValue.Low);

            _dispatcherTimer = new DispatcherTimer();
            _dispatcherTimer.Interval = TimeSpan.FromMilliseconds(1000);
            _dispatcherTimer.Tick += (sender, e) => {

                _gpioSuccessPin.Write(GpioPinValue.High);
                _gpioErrorPin.Write(GpioPinValue.High);

                bool ingestTask = _eventHubIngest.TelemetryIngest(new Telemetry()
                {
                    DeviceId = "Device-78",
                    Humidity = 10,      //Read from Sensors
                    Pollution = 100,    //Read from Sensors
                    Temperature = 35,   //Read from Sensors
                });

                //Check if pins are available
                if (_gpioController == null || _gpioSuccessPin == null)
                    return;

                _gpioSuccessPin.Write(ingestTask ? GpioPinValue.Low : GpioPinValue.High);
                _gpioErrorPin.Write(ingestTask ? GpioPinValue.High : GpioPinValue.Low);

            };
            _dispatcherTimer.Start();
        }