Exemplo n.º 1
0
        static void Main(string[] args)
        {
            SensorManager sensorManager = new SensorManager();

            sensorManager.AddSensor(SensorFactory.CreateSensor(EDataType.Temp, EUnit.Kelvin));

            while (true)
            {
                sensorManager.UpdateSensors();
                Thread.Sleep(5000);
            }
        }
        public WorkerABN03(string deviceId, ILogger <WorkerABN03> logger, IOptions <WorkersConfiguration> workersConfiguration, IOptions <MqttConfiguration> mqttConfiguration, IMqttClientForMultipleSubscribers mqttClient)
            : base(deviceId, logger, workersConfiguration, mqttConfiguration, mqttClient)
        {
            var sensorFactory = new SensorFactory();
            var device        = new Device
            {
                Name         = "ABN03",
                Model        = "ABSensor N03",
                Manufacturer = "April Brother",
                ViaDevice    = WorkersConfiguration.ServiceName,
                Identifiers  = new() { DeviceId },
                Connections  = new() { new() { "mac", DeviceId } }
            };

            ComponentList.AddRange(new List <Sensor>
            {
                sensorFactory.CreateSensor(DeviceClassDescription.Temperature, device: device),
                sensorFactory.CreateSensor(DeviceClassDescription.Humidity, device: device),
                sensorFactory.CreateSensor(DeviceClassDescription.IlluminanceLux, device: device),
                sensorFactory.CreateSensor(DeviceClassDescription.Battery, device: device)
            });
        }
Exemplo n.º 3
0
        private void SendData(object value)
        {
            while (!_disposing.WaitOne(TimeSpan.FromSeconds(1)))
            {
                ArduinoCollect collectedData = new ArduinoCollect();
                if (_processingQueue.TryDequeue(out collectedData))
                {
                    ISensor sensor = SensorFactory.CreateSensor((SensorType)collectedData.SensorType);
                    sensor.ECUValue = (float)(double)collectedData.Value;

                    _dataAccess.Send(new CollectedData(sensor));

                    Console.WriteLine($"Enviando para o Elastic: {sensor.Type.ToString()} - {collectedData.Value}");
                }
            }
        }