Skip to content

Group A project for Samsung Innovation Campus 2021, Palermo

Notifications You must be signed in to change notification settings

emanuelemessina/atmoeyes-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AtmoEyes Demo


What is this?

This repo contains all the code used for the demo presented by Group A of UNIPA (Università degli Studi di Palermo) for "Samsung Innovation Campus 2021 Smart Things Edition" in Palermo. Eventually 3 of the 4 members of Group A (atmoeyes) won the edition.


Below are developement notes.




Routes


/frontend

URI Method Description
/ GET Live Map page

/backend

URI Method Description
/data/aqi GET Returns GeoJSON aqi data layer
/data/aqi/send POST Send sensor data to aqi data layer (CURRENTLY UNPROTECTED)

Data


AQI Data - Post Body

Value Lon Lat
Int Float Float

GeoJSON Structure


{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {
                "aqi": 7
            },
            "geometry": {
                "type": "Point",
                "coordinates": [-30, 10]
            }
        }, 
    ...
}

Frontend code maintenance


Specify project specific parameters in .atmoeyes

{
    "backendUrl": "https://emanuelemessina.altervista.org/uni/ssmic2021/atmoeyes/backend"
}

Backend code maintenance


Routing Flow

  1. Calls to /backend are redirected to kernel.php via .htaccess RewriteRule.
  2. kernel.php - calls db, calls router.
  3. /db.php - initializes db connection, declares db methods.
  4. /router/router.php - declares route matching methods, calls routes.php.
  5. /router/routes.php - sets application/json response header, calls declared routes, which are then parsed by the router. If no match is found, 404 is thrown.
  6. When a match is found, execution is passed to the matched route controller.

Examples


Update a record with QuickQuery

$input_schema = [
    "id" => "int",
    "value" => "int"
];

$qq = new QuickQuery('json-input', $input_schema);
$validated_data = $qq->getValidatedData();
$response = $qq->update(
    'data', // table
    ['value'], // fields to update
    [ // where clause
        'id' => $validated_data['id'] 
    ]);

echo json_encode($response);

Validation is automatically done and all errors are reported in the response.
Table names are already prefixed with 'atmoeyes_'.


Declaring routes in routes.php

get('/data/aqi/$optional_get_param', 'aqi-data.php'); 
  • Controller files are placed under /controllers.
  • Optional GET parameters are accessible in the controller via $parameters array.

Docs



Info

CAQI

Mapbox

Heatmap

Live Data Updates

PHP

PHP Router

Medoo

Firebase

Get Started