Beispiel #1
0
        private static void SetTimer(int intervalMs)
        {
            _logger.Information($"Timer Set [{intervalMs}]ms");
            if (_sampleTimer != null)
            {
                _sampleTimer.Stop();
                _sampleTimer.Dispose();
            }

            _sampleTimer = new Timer()
            {
                AutoReset = true,
                Enabled   = true,
                Interval  = intervalMs
            };
            _sampleTimer.Elapsed += (a, b) =>
            {
                _logger.Verbose("Timer Elapsed...");
                try
                {
                    var d = _device.ReadData();

                    _publisher.Publish(d);
                }
                catch (DHTException)
                {
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Error reading from device");
                }
                _sampleTimer.Interval = ConfigurationHandler.Get <int>("SampleIntervalSec") * 1000;
            };
        }
        protected override async Task OnInitializedAsync()
        {
            var configurationHandler = new ConfigurationHandler();
            var configuration        = configurationHandler.Get();
            var url = $"{configuration.Backend}/api/Weather";

            _forecasts = await Http.GetJsonAsync <WeatherForecast[]>(url);
        }
        protected override async Task OnInitializedAsync()
        {
            var configurationHandler = new ConfigurationHandler();
            var configuration        = configurationHandler.Get();
            var url = $"{configuration.Backend}/api/";

            _hubConnection = new HubConnectionBuilder()
                             .WithUrl(url)
                             .Build();

            _hubConnection.On <SelectRectangle>("select", (selectRectangle) =>
            {
                StateHasChanged();
            });

            await _hubConnection.StartAsync();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            ConfigurationHandler.Initialise();
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .MinimumLevel.Debug()
                         .CreateLogger();
            _logger = Log.Logger.ForContext <Program>();


            if (ConfigurationHandler.Get <bool>("SamplingEnabled"))
            {
                Pi.Init <BootstrapWiringPi>();
                _device = new DHT(
                    Pi.Gpio[ConfigurationHandler.Get <int>("GpioPin")],
                    ConfigurationHandler.Get <DHTSensorTypes>("DhtDevice"));
            }
            else
            {
                _device = new DummyDevice();
            }
            var publishKey       = ConfigurationHandler.Get <string>("PublishKey");
            var connectionString = ConfigurationHandler.Get <string>("PublishAddress");

            if (ConfigurationHandler.Get <bool>("UseEventHub"))
            {
                _publisher = new EventHubPublisher(connectionString, publishKey);
            }
            else if (ConfigurationHandler.Get <bool>("UseInfluxDb"))
            {
                _publisher = new InfluxDbPublisher(connectionString, publishKey);
            }
            else
            {
                _publisher = new DummyPublisher();
            }
            _logger.Information("Sensor setup complete");
            SetTimer(ConfigurationHandler.Get <int>("SampleIntervalSec") * 1000);

            while (true)
            {
                System.Threading.Thread.Sleep(100);
            }
        }