Ejemplo n.º 1
0
        public void SendMessage(Sensor sensor)
        {
            LoriotDTO msg = new LoriotDTO();

            msg.cmd       = "tx";
            msg.EUI       = sensor.sensorEUID;
            msg.data      = sensor.servoSetting;
            msg.port      = 3;
            msg.confirmed = false;
            clientWS.Send(JsonConvert.SerializeObject(msg));
            Console.WriteLine("Message sent");


            var log = new SensorLog();

            sensor = _context.Sensor.AsQueryable().First(s => s.sensorEUID == sensor.sensorEUID);

            log.servoSetting = sensor.servoSetting;
            log.timestamp    = DateTime.Now;

            log.sensorID = sensor.sensorID;

            slc.PostSensorLog(log).Wait();
            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutSensorLog(int id, SensorLog sensorLog)
        {
            if (id != sensorLog.sensorID)
            {
                return(BadRequest());
            }

            _context.Entry(sensorLog).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SensorLogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("sensorID,timestamp,servoSetting")] SensorLog sensorLog)
        {
            if (id != sensorLog.sensorID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sensorLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SensorLogExists(sensorLog.sensorID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["sensorID"] = new SelectList(_context.Sensor, "sensorID", "sensorID", sensorLog.sensorID);
            return(View(sensorLog));
        }
Ejemplo n.º 4
0
        public List <SensorLog> GetSensorLog(string logFilePath)
        {
            List <SensorLog> logRecords = new List <SensorLog>();

            List <Sensor> sensors = GetSensors();
            var           frl     = (from sensor in sensors
                                     where sensor.Id == 1
                                     select sensor).FirstOrDefault();
            var fll = (from sensor in sensors
                       where sensor.Id == 2
                       select sensor).FirstOrDefault();
            var rl = (from sensor in sensors
                      where sensor.Id == 3
                      select sensor).FirstOrDefault();

            string line;

            using (StreamReader file = new System.IO.StreamReader(logFilePath))
            {
                while ((line = file.ReadLine()) != null)
                {
                    string[] row = line.Split(',');

                    int millisecond = int.Parse(row[0]);
                    int pot1        = int.Parse(row[1]);
                    int pot2        = int.Parse(row[2]);
                    int pot3        = int.Parse(row[3]);

                    SensorLog logRecord = new SensorLog();
                    logRecord.SensorId    = frl.Id;
                    logRecord.SensorName  = frl.Name;
                    logRecord.Millisecond = millisecond;
                    logRecord.Value       = pot1;
                    logRecords.Add(logRecord);

                    SensorLog logRecord2 = new SensorLog();
                    logRecord2.SensorId    = fll.Id;
                    logRecord2.SensorName  = fll.Name;
                    logRecord2.Millisecond = millisecond;
                    logRecord2.Value       = pot2;
                    logRecords.Add(logRecord2);

                    SensorLog logRecord3 = new SensorLog();
                    logRecord3.SensorId    = rl.Id;
                    logRecord3.SensorName  = rl.Name;
                    logRecord3.Millisecond = millisecond;
                    logRecord3.Value       = pot3;
                    logRecords.Add(logRecord3);
                }
                file.Close();
            }

            return(logRecords);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("sensorID,timestamp,servoSetting")] SensorLog sensorLog)
        {
            if (ModelState.IsValid)
            {
                _context.Add(sensorLog);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["sensorID"] = new SelectList(_context.Sensor, "sensorID", "sensorID", sensorLog.sensorID);
            return(View(sensorLog));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <SensorLog> > Log(string input)
        {
            // The post-request simulates a sensor-trigger and the paramater "input" consists of which section was entered and which section was exited, separated by ".".
            // Example: "Electronics.Kitchen" says a visitor entered the section "Electronics" and exited the section "Kitchen".
            // This was my way to handle the fact that if a visitor enters a section, they had to exit another.
            var enterName = input.Split(".")[0];
            var exitName  = input.Split(".")[1];

            var enterSection = await _context.StoreSections
                               .FirstOrDefaultAsync(ss => ss.Name == enterName);

            if (enterSection == default)
            {
                return(BadRequest(new { Error = $"Section '{enterSection}' does not exists" }));
            }
            var exitSection = await _context.StoreSections
                              .FirstOrDefaultAsync(ss => ss.Name == exitName);

            if (exitSection == default)
            {
                return(BadRequest(new { Error = $"Section '{exitSection}' does not exists" }));
            }

            // TODO: The visitor count can be less than zero.

            enterSection.VisitorCount++;
            exitSection.VisitorCount--;

            var log = new SensorLog()
            {
                TimeStamp         = DateTime.Now,
                EnterStoreSection = enterSection,
                ExitStoreSection  = exitSection,
                Direction         = Direction.Enter
            };
            await _context.AddAsync(log);

            await _context.SaveChangesAsync();

            string warning = "";

            if (exitSection.VisitorCount < 0)
            {
                warning = $"Warning, section '{exitSection.Name}' has less then 0 visitors. Something is wrong with the sensors, not the code ;)";
            }

            return(Created(Request.HttpContext.Request.Path, new
            {
                Log = $"Enter : {enterSection.Name}, Exit : {exitSection.Name}, Time Stamp : {DateTime.Now}",
                Warning = String.IsNullOrEmpty(warning) ? "No warnings, all good" : warning
            }));
        }
Ejemplo n.º 7
0
 public RepositoryActionResult <SensorLog> AddSensorValue(SensorLog sensorlog)
 {
     try
     {
         context.SensorLog.Add(sensorlog);
         context.SaveChanges();
         return(new RepositoryActionResult <SensorLog>(sensorlog, RepositoryActionStatus.Created));
     }
     catch (Exception ex)
     {
         return(new RepositoryActionResult <SensorLog>(null, RepositoryActionStatus.Error, ex));
     }
 }
Ejemplo n.º 8
0
        public IActionResult Post([FromBody] SensorLog sensorlog)
        {
            var newSensorLog = repo.AddSensorValue(sensorlog);

            if (newSensorLog.Status == RepositoryActionStatus.Created)
            {
                PushNotifications.DataChangeNotification(sensorlog, "Sensor data logged");
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 9
0
        public List <SensorLog> GenerateData(int maxDataPoints)
        {
            Random           random  = new Random();
            List <SensorLog> logData = new List <SensorLog>();

            for (int i = 0; i < maxDataPoints; i++)
            {
                SensorLog log = new SensorLog();
                log.Millisecond = i;
                log.SensorId    = 1;
                log.Value       = random.Next(0, 255);
                logData.Add(log);
            }

            return(logData);
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <SensorLog> > PostSensorLog(SensorLog sensorLog)
        {
            _context.SensorLog.Add(sensorLog);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (SensorLogExists(sensorLog.sensorID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetSensorLog", new { id = sensorLog.sensorID }, sensorLog));
        }
Ejemplo n.º 11
0
        internal void RunGPX(DEMDataSet largeDataSet, DEMDataSet localDataset)
        {
            try
            {
                string outputDir     = Path.GetFullPath(".");
                string _gpxFile      = Path.Combine("SampleData", "20191022-Puch-Pöllau.gpx");
                string sensorLogFile = Path.Combine("SampleData", "20191023-Puch-Pöllau-sensorlog.json");
                var    sensorLog     = SensorLog.FromJson(sensorLogFile);
                //sensorLog.Plot("sensorLog.png");
                string balloonModel     = Path.Combine("SampleData", "OE-SOE.glb");
                float  Z_FACTOR         = 2f;
                float  trailWidthMeters = 5f;


                ModelRoot balloon = ModelRoot.Load(balloonModel);

                //=======================
                /// Line strip from GPX
                ///
                // Get GPX points
                var segments  = GpxImport.ReadGPX_Segments <GpxTrackPoint>(_gpxFile, p => p);
                var pointsGpx = segments.SelectMany(seg => seg);
                var geoPoints = pointsGpx.ToGeoPoints();

                var model = _sharpGltfService.CreateNewModel();
                //var largeMesh = GetMeshFromGpxTrack(outputDir, largeDataSet, geoPoints
                //                                , bboxScale: 5
                //                                , zFactor: Z_FACTOR
                //                                , generateTIN: false
                //                                , tinPrecision: 500d
                //                                , drawGpxOnTexture: false
                //                                , ImageryProvider.OpenTopoMap);
                //meshes.Add(largeMesh);

                model = GetMeshFromGpxTrack(model, outputDir, localDataset, geoPoints
                                            , bboxScale: (1.3, 1.5)
                                            , zFactor: Z_FACTOR
                                            , generateTIN: false
                                            , tinPrecision: 50d
                                            , drawGpxOnTexture: true
                                            , ImageryProvider.EsriWorldImagery);


                var gpxPoints = geoPoints.ReprojectGeodeticToCartesian().ZScale(Z_FACTOR);

                model = _sharpGltfService.AddLine(model, gpxPoints, new Vector4(0, 1, 0, 0.5f), trailWidthMeters);

                // model export
                Console.WriteLine("GenerateModel...");

                var node = model.LogicalNodes.First();
                pointsGpx = pointsGpx.ReprojectGeodeticToCartesian().ZScale(Z_FACTOR);
                // animations
                node = CreateAnimationFromGpx("GPX", node, pointsGpx, 1f);
                node = CreateAnimationFromGpx("GPX x500", node, pointsGpx, 500f);


                var sceneBuilderBalloon = balloon.DefaultScene.ToSceneBuilder();

                var sceneBuilderTerrain = model.DefaultScene.ToSceneBuilder();
                //sceneBuilderBalloon.



                model.SaveGLB(Path.Combine(Directory.GetCurrentDirectory(), $"{GetType().Name}.glb"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
            }
        }
Ejemplo n.º 12
0
        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            //List<SensorLog> log = _sensorService.GetSensorLog(1);
            //List<SensorLog> log2 = _sensorService.GetSensorLog(2);

            List <SensorLog> log      = new List <SensorLog>();
            List <SensorLog> log2     = new List <SensorLog>();
            string           dataFile = Server.MapPath("~/Data/datalog.txt");
            // Read the file and display it line by line.
            string line;

            System.IO.StreamReader file = new System.IO.StreamReader(dataFile);
            while ((line = file.ReadLine()) != null)
            {
                string[] row = line.Split(':');

                int      microSecond = int.Parse(row[0]);
                string[] values      = row[1].Split(';');

                int pot1 = int.Parse(values[0]);
                int pot2 = int.Parse(values[1]);
                int pot3 = int.Parse(values[2]);

                SensorLog logRecord = new SensorLog();
                logRecord.SensorId    = 1;
                logRecord.MicroSecond = microSecond;
                logRecord.Value       = pot1;
                log.Add(logRecord);

                SensorLog logRecord2 = new SensorLog();
                logRecord2.SensorId    = 2;
                logRecord2.MicroSecond = microSecond;
                logRecord2.Value       = pot2;
                log2.Add(logRecord2);
            }

            file.Close();

            SensorChart  chart = new SensorChart();
            SensorSeries fl    = new SensorSeries();

            fl.SensorData         = log;
            fl.XField             = "MicroSecond";
            fl.YField             = "Value";
            fl.LineColor          = "Red";
            chart.FrontLeftSensor = fl;

            SensorSeries fr = new SensorSeries();

            fr.SensorData          = log2;
            fr.XField              = "MicroSecond";
            fr.YField              = "Value";
            fr.LineColor           = "Blue";
            chart.FrontRightSensor = fr;

            ChartGenerator chartGenerator = new ChartGenerator();
            string         imagePath      = Server.MapPath("~/images/charts/sensorLog.png");

            chartGenerator.GenerateChart(imagePath, chart, "Milli Seconds", "Sensor Value");

            return(View());
        }