To realise the use case "Detect and Locate", this sample application consumes "Device Location Update" Event of the Cisco Spaces Firehose API. This can be used as a starting point and reference for consuming the Cisco Spaces Firehose API events.

Sample Application consists of the below components

  1. API Server
  2. Proxy Server
  3. Client
  4. Kafka Consumer Application

Clone the Repository and follow below instructions to run the application.

1) API Server

The API Server consumes "DEVICE_LOCATION_UPDATE" event and keeps updating RocksDB or Redis Cache (based on which one is enabled, by default uses RocksDB) for each Device MAC address. Server also exposes an HTTP GET API which can be invoked with a MAC address param(mac), to get recent location update for the given mac.
API server also writes every event into given corresponding Kafka topic(only if Kafka configuration is enabled) which can be used by a Kafka client for further processing.

NOTE: Regarding RocksDB & Redis Cache, enable any one of them, in case of both are enabled then RocksDB will be considered for pulling data for the HTTP GET API.

Steps to run the API Server application

  1. Navigate to /server/ folder in the cloned repository.
  2. Rename or copy /server/src/main/resources/app.default.properties file to /server/src/main/resources/app.properties and Update app.properties file (/server/src/main/resources/app.properties) with appropriate values. All the below mentioned properties are mandatory.
api.key={{Firehose API Key}}
api.url={{Firehose API URL}}

http.port={{http server port}}

redis.feeder.enabled=false
rocksdb.feeder.enabled=true
  1. Build the project by using mvn install.
  2. Set the classes folder path in the classspath and execute com.cisco.dnaspaces.APIConsumer class to run the application.

2) Proxy Server

Proxy Server is used to avoid CORS restriction while using the partners api for retrieving map information and image from client application. This takes the request and communicates with API and serves response to client application without any CORS Restriction

Steps to run the Proxy Server application

  1. Navigate to /client/ folder in the cloned repository.
  2. Rename or copy /proxy-server/proxy-server.default.properties file to /proxy-server/proxy-server.properties and update below mentioned properties with appropriate Partners API details
apiserver.host={{Partners API Host}}
apiserver.apikey={{Partners API Key}}
  1. In console move to /client directory of project
  2. Run command npm install
  3. Start the node server using command node server

3) Client

The client application provides an UI to enter MAC address of client and when user clicks on "start polling", Ajax polling starts with a certain time interval to server. On each location update, co-ordinates are stacked to the screen.

Steps to run the Client application

  1. Navigate to /client/ folder in the cloned repository.
  2. Rename or copy /client/src/environments/environment.default.ts file to /client/src/environments/environment.ts and update below mentioned properties with appropriate Partners API details
  {
  "apiUrl":"{{API Server url}}",
  "serverUrl":"{{Proxy Server url}}"
  }
  1. In console move to /client directory of project
  2. Start the Angular application by using command ng serve

4) Kafka Consumer Application

This is a standalone sample application which subscribes to the provided Kafka Topic into which API server pushes the event data. Kafka Consumer Application subscribes to given Kafka Topic and writes every received events to console.

Steps to run the Consumer application

  1. Navigate to /kafka client folder in the cloned repository
  2. Execute com.cisco.dnaspaces.clients.kafka.Application class to run the application.
  3. Application will prompt you Kafka specific configurations which you need to enter optionally. Leaving it blank will take default value.

DEMO

Once all the applications are started,

  1. Client UI can be accessed by opening http://localhost:4200 in the browser.
  2. By providing the Device MAC Address, Device can be detected and located.
  3. Given user current location is plotted in the map using small red dot icon.
  4. Given user locatoin updates starting from the time of request are listed below the map

published

View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.