Beispiel #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);
            }
        }
Beispiel #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            HttpClientModel     httpClientModel = new HttpClientModel();
            MovementSensorModel sensore         = new MovementSensorModel();

            sensore.SensorType = "Movement_Sensor";
            sensore.ScooterId  = 1;
            sensore.SensorId   = 2;

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

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

                httpClientModel.InsertDetection(sensore);

                /* INSERIMENTO DATI NELLA CODA AZURE
                 * var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(json);
                 * var jsonBase64 = System.Convert.ToBase64String(plainTextBytes);
                 * queue.InsertMessage("collarini-vendrame-queue", jsonBase64);
                 */
                await Task.Delay(5000, stoppingToken);
            }
        }