Пример #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            JsonSensorModel     sensorModel     = new JsonSensorModel();
            MqttClientModel     mqttClientModel = new MqttClientModel();
            MovementSensorModel sensore         = new MovementSensorModel();

            sensore.SensorType = "Movement_Sensor";
            sensore.ScooterId  = 1;
            sensore.SensorId   = 2;
            string topic = "scooter/" + sensore.ScooterId + "/" + sensore.SensorId + "/" + sensore.SensorType;

            while (!stoppingToken.IsCancellationRequested)
            {
                var info = virtualMovementSensor.GetMovement();
                sensorModel.SensorValue         = info.ToString();
                sensorModel.SensorDetectionDate = DateTime.Now;

                var json = JsonSerializer.Serialize(sensorModel);
                Console.WriteLine("Json file sent: " + json);

                MqttJsonSensorModel sensorData = new MqttJsonSensorModel
                {
                    Topic               = topic,
                    SensorValue         = sensorModel.SensorValue,
                    SensorDetectionDate = sensorModel.SensorDetectionDate
                };

                _queueController.InsertIntoList(sensorData);

                await Task.Delay(10000, stoppingToken);
            }
        }
Пример #2
0
        public void InsertIntoList(MqttJsonSensorModel jsonSensorModel)
        {
            // queue.Push(jsonSensorModel);
            RedisValue redisValue = new RedisValue(JsonSerializer.Serialize(jsonSensorModel));

            conn.ListRightPush(redisKey, redisValue);
        }