Exemplo n.º 1
0
        /*
         * Process road sensor data
         * Outside temperature <= 0 then show informational notification with snowy icon (priority 0)
         * Humidity level between 40 and 60 then show informational notification with cloudy icon (priority 0)
         * Humidity level > 60 then show informational notification with rainy icon (priority 0)
         * In other case show an informational notification with sunny icon (priority 0)
         */
        void ProcessRoadSensor(Model.RoadSensor sensor, LocationEventArgs args)
        {
            //Displays the outside temperature
            string content = string.Format("The outdoor temperature is {0} degres. ", sensor.currentEnviromentTemperature);

            string imagePath = null;

            var notification = new Model.Notification(Model.Notification.Type.Weather, "Weather", content, imagePath, 0);

            if (sensor.currentEnviromentTemperature <= 0)
            {
                notification.imagePath = "snow4";
            }
            else if (sensor.humidityLevel >= 40 && sensor.humidityLevel <= 60)
            {
                notification.imagePath = "cloudy2";
            }
            else if (sensor.humidityLevel > 60)
            {
                notification.imagePath = "shower3";
            }
            else
            {
                notification.imagePath = "sunny";
            }

            //Show notification
            DependencyService.Get <INotification>().SendCollapsedNotification(notification);
        }
Exemplo n.º 2
0
 /*
  * Process traffic lane sensor data
  * Displays a warning (priority 2) when high traffic and average speed < 40 km/h
  */
 void ProcessTraficLaneSensor(Model.TrafficLaneSensor sensor, LocationEventArgs args)
 {
     if (sensor.crossingsCounter5Minutes < 20 && sensor.averageSpeed < 40)
     {
         DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.TrafficJam, "Traffic jam", "There is a traffic jam ahead.", 2));
     }
 }
Exemplo n.º 3
0
 /*
  * Retrieves sensor data from the backend for every supported sensor type
  */
 void GetSensorData(LocationEventArgs args)
 {
     GetRoadSensorData(args);
     GetLaneSensorData(args);
     GetLightSensorData(args);
     GetEnvSensorData(args);
 }
Exemplo n.º 4
0
 /*
  * Process traffic light sensor data
  * Displays a warning (priority 1) with the current traffic light state (red or green)
  */
 void ProcessTrafficLightSensor(Model.TrafficLightSensor sensor, LocationEventArgs args)
 {
     if (sensor.trafficLightState.Equals("red"))
     {
         DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.TrafficLight, "Traffic light", "Traffic light is red.", 1));
     }
     else if (sensor.trafficLightState.Equals("green"))
     {
         DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.TrafficLight, "Traffic light", "Traffic light is green.", 1));
     }
 }
Exemplo n.º 5
0
 /*
  * Process environmental sensor data
  * Active oxygen > 200ppm then warning (priority 1)
  * Carbon monoxide > 200 ppm then alert (priority 3)
  * Carbon dioxide > 200 ppm then warning (priority 2)
  */
 void ProcessEnvirontmentalSensor(Model.EnviromentalSensor sensor, LocationEventArgs args)
 {
     if (sensor.activeOxygen > 200)
     {
         DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.OxygenPollution, "Pollution warning", "Oxygen has exceeded the threshold of 200 ppm", 1));
     }
     if (sensor.carbonMonoxidePPM > 200)
     {
         DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.OxygenPollution, "Pollution warning", "Carbon monoxide has exceeded the threshold of 200 ppm", 3));
     }
     if (sensor.carbonDioxidePPM > 200)
     {
         DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.OxygenPollution, "Pollution warning", "Carbon dioxide has exceeded the threshold of 200 ppm", 2));
     }
 }
Exemplo n.º 6
0
        /*
         * Retrieves the environmental sensor data from the backend
         * Radius: 1000m
         * Parameter: gps position
         */
        async void GetEnvSensorData(LocationEventArgs args)
        {
            //Enabled in settings?
            if (!EnabledNotifications.pollution)
            {
                return;
            }

            //Backend script location
            string uri = "http://mobiheaven.de/digital-city/index.php?lat=" + args.Latitude.ToString().Replace(",", ".")
                         + "&long=" + args.Longitude.ToString().Replace(",", ".") + "&radius=";

            uri += "1000";

            uri += "&type=envSensor";

            var response = await client.GetAsync(new Uri(uri));

            if (response.IsSuccessStatusCode)
            {
                string body = await response.Content.ReadAsStringAsync();

                //Converts the json object to a c# representation
                var collection = JsonConvert.DeserializeObject <Model.SensorCollection>(body);

                Random random = new Random();

                //If any results then process a random sensor data
                if (collection.envSensors.Length > 0)
                {
                    ProcessEnvirontmentalSensor(collection.envSensors[random.Next(collection.envSensors.Length)], args);
                }
            }
            //Error handling
            else
            {
                DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.Issue, "Warning", "There is an issue with the connection", 3));
            }
        }
Exemplo n.º 7
0
        /*
         * This function is called every gps position update
         */
        void LocationUpdateHandler(object sender, LocationEventArgs e)
        {
            //Error handling
            if (e == null)
            {
                DependencyService.Get <INotification>().SendDefaultNotification(new Model.Notification(Model.Notification.Type.Issue, "Warning", "There is an issue with the location service", 3));
                return;
            }

            //Android: Stops location service, retrieves sensor data form backend and starts the location service again
            if (Device.RuntimePlatform == Device.Android)
            {
                DependencyService.Get <ILocationManager>().StopLocationUpdates();
                GetSensorData(e);
                DependencyService.Get <ILocationManager>().StartLocationUpdates();
            }
            //iOS: Retrieves sensord data from backend
            else if (Device.RuntimePlatform == Device.iOS)
            {
                GetSensorData(e);
            }
        }