Web Services

The web services used by the DrivingApp are: DrivingApp Service and Notifications Service, which are described below.

DrivingApp Service

DrivingApp Service is a web service that manipulates the public and private data models of the mobile application and the query services. This service is a REST API implementation created with the NodeJS environment, and allows managing the information provided by three data sources: the FIWARE Orion ContextBroker, which is used to manage the context information; the DBMS MariaDB, which is used to store the information of data models; and finally CrateDB which is used by the FIWARE QuantumLeap API to store time series information. The repository of DrivingApp Service is on this [link][https://github.com/smartsdkCenidet/DrivingApp-service).

DrivingApp Service is composed of 1 root endpoint and 3 APIs with specific routes. These routes define the following.

Root endpoint
  • /: This is the main route of the DrivingApp Service. The request to this root route verifies that the service has been successfully deployed. The web service responds to this request with the following JSON message:
{ message: 'Welcome to Smart Security Web Service' }
APIs
  • /api: This is the RESTFul API that manages the public and private data entities used by the DrivingApp application. The REST API manages the CRUD operations of the data entities: zone, parking, road, road segment deviceTokens and user; and this information is stored in the smartsecurity database through the MariaDB manager. DrivingApp Service responds to this request with the following JSON message:
{ message: 'Welcome to DataModels API REST' }
  • /service: This API manages the services of special queries for the Alert and Device data models, implementing the services of FIWARE Orion ContextBroker. The web service responds to this request with the following JSON message:
{ message: 'Welcome to Special Services API' }
  • /crate: This API manages the route to consult the location of user devices at specific date and time, using the data stored in CrateDB through the FIWARE QuantumLeap API. The response to this request is the following JSON message:
{ message: 'Welcome to CrateDB-QuantumLeap API' }

In this link you can check the specification of the data models used in * DrivingApp Service*.

Notifications Service

Notifications Service is a web service that manipulates the information of the Alert entities, obtained through the notification of a subscription created in the Orion ContextBroker. When Notifications Service receives an alert entity sent by the Orion, replicates the alert to the DrivingApp users, using the services of Firebase Cloud Messaging. The Notifications Service repository is on this link

Notifications Service has two routes described below.

Root endpoint

/: This is the default path of Notifications Service. The request to this route verifies if the service has been successfully deployed. The web service responds to this request with the following message.

SmartSecurity Notifications is running.... © Cenidet 2018

Notification endpoint

/notify: This route is used to generate alert notifications that are sent to mobile devices. The service performs the following functions in this route:

  1. Receive the alert entity
  2. Get the location of the alert
  3. Get the zones registered in DrivingApp Service
  4. Determine the area where the alert happened
  5. Obtain from DrivingApp Service the devices within the alert area
  6. Get DrivingApp Service devices near the alert
  7. Verify that nearby devices and those in the area are not repeated
  8. Create the list of end devices
  9. Obtain from DrivingApp Service the tokens of the end devices
  10. Send the notification to each of the devices

The /notify endpoint receives the data from the alert entities sent by the Orion ContextBroker through a POST request. The service receives the alert and extracts the relevant information to send the notification of the alert to the DrivingApp users devices. The alert entity that receives the service must be a JSON object with the following format:

{
    "data" : [
        {
            "id": "Alert:Device_Smartphone_f2751c243d2b4295_1540484159603",
            "type": "Alert",
            "alertSource": "Device_Smartphone_f2751c243d2b4295",
            "category": "security",
            "dateCreated": "2018-10-25T16:15:59.00Z",
            "dateObserved": "2018-10-23T16:15:59.999Z",
            "description": "Alert generated by Simulator",
            "location": "19.599157972898347,-99.22552046196473",
            "severity": "high",
            "subCategory": "speeding",
            "validFrom": "2018-10-23T16:15:59.999Z",
            "validTo": "2018-10-23T16:15:59.999Z",  
        }
    ]
} 

Notifications Service uses the query services of DrivingApp Service to obtain the data of the zone entities, and compute the area in which the alert was issued. Also for obtaining the devices list that are in the area in wich the alert ocurred and devices that are 100 meters around of the alert.