protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            JsonSensorModel     sensorModel     = new JsonSensorModel();
            MqttClientModel     mqttClientModel = new MqttClientModel();
            PositionSensorModel sensore         = new PositionSensorModel();

            sensore.SensorType = "Position_Sensor";
            sensore.ScooterId  = 1;
            sensore.SensorId   = 3;
            string topic = "scooter/" + sensore.ScooterId + "/" + sensore.SensorId + "/" + sensore.SensorType;

            while (!stoppingToken.IsCancellationRequested)
            {
                var info = virtualPositionSensor.toJson();
                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(30000, stoppingToken);
            }
        }
예제 #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            HttpClientModel     httpClientModel = new HttpClientModel();
            PositionSensorModel sensore         = new PositionSensorModel();

            sensore.SensorType = "Position_Sensor";
            sensore.ScooterId  = 1;
            sensore.SensorId   = 3;

            while (!stoppingToken.IsCancellationRequested)
            {
                var info = virtualPositionSensor.GetPosition();
                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);
            }
        }