Skip to content

Real-time asset tracking, geofence implementation

Notifications You must be signed in to change notification settings

rreinold/real-time-asset-tracking-template

Repository files navigation

Overview

Drawing

This System Template provides geospatial computation and spatial data interpretation.

It is functional out-of-the-box and is highly extensible.

This is an ipm package, which contains one or more reusable assets within the ipm Community. The 'package.json' in this repo is a ipm spec's package.json, here, which is a superset of npm's package.json spec, here.

Browse ipm Packages

Setup

  • Connect your devices to ClearBlade Platform
  • Publish to /location MQTT Topic using configurable Message JSON Schema
  • Configure your geofence in RTAssetConfiguration

Note: Updates to Message schema requires changes to the location_logs and tags Collection schemas

Usage

1. Device Publishes to /location topic

  • Devices publishes to /location topic:

{"id":"<TAG_ID>","lat":<LATITUDE>,"long":"<LONGITUDE>}

  • Geofence When a position is within a geofence, a response message is published on the geofence topic:

Point with ID: 2b is within geofence

Development

How to Update Graph

npm i
npm run buildGraph

Assets

Portals

  • RTAssetTrackingPortal - Holistic view of your Real-Time Asset Tracking System, with a 3D Map of Tags
  1. Interactive 3D Map of New York City's Manhattan
  2. Pie Chart of Anomalies Detected
  3. Bar Chart of Zone Activity
  4. Time-Series Multi-Line Graph of activity
  5. Message Logs
  6. Monitoring Enable Switch
  7. Edge Selection

Code Services

  • RTAssetLogLocation - creates row in location_logs collection
  • RTAssetUpdateTagLocation - updates tags collection with latest position
  • RTAssetCheckGeofence - checks if tag is within configured geofence
  • RTAssetRESTIntegration- Sends a configurable HTTP POST request

Code Libraries

  • RTAssetConfiguration - Configuration for the System
  • RTAssetUtil - Reusable utility methods for System

Mesaging Topics

  • /location - Tags publish their position using configurable Message structure
  • /geofence - Publishes status whether a tag is inside the geofence

Collections

  1. location_logs - History of all MQTT Messages received
  2. tags - Latest location of all tags

Triggers

  1. RTAssetCheckGeofence_location - Runs RTAssetUpdateTagLocation upon publish to /location topic
  2. RTAssetLogLocation_location - Runs RTAssetLogLocation upon publish to /location topic
  3. RTAssetUpdateTagLocation_location - Runs RTAssetUpdateTagLocation upon publish to /location topic

API

Functions

RTAssetCheckGeofence()

Performs real-time geofence functionalities

Triggered by /location topic

Status of a tag (inside or outside) is published the GEOFENCE_ALERT_TOPIC

RTAssetHTTPIntegration()

Opportunity to integrate with a REST endpoint using location data

Triggered by /location topic

RTAssetLogLocation()

Insert a row into COLLECTION_NAME upon a publish message to /location

Triggered by /location topic

RTAssetRESTIntegration()

Opportunity to implement a REST-based integration to your Real-Time IoT Solution

A placeholder URL is used as an example

Triggered by /location topic

RTAssetUpdateTagLocation()

Keeps track of a tag's most recent location

Triggered by /location topic

If a Tag with the corresponding ID is not found in the COLLECTION_NAME, a new row is created

Typedefs

Message
GeofenceBounds
Point
CoordinateSystem
RTAssetConfiguration
RTAssetUtil

RTAssetCheckGeofence()

Performs real-time geofence functionalities

Triggered by /location topic

Status of a tag (inside or outside) is published the GEOFENCE_ALERT_TOPIC

Kind: global function

RTAssetHTTPIntegration()

Opportunity to integrate with a REST endpoint using location data

Triggered by /location topic

Kind: global function

RTAssetLogLocation()

Insert a row into COLLECTION_NAME upon a publish message to /location

Triggered by /location topic

Kind: global function

RTAssetRESTIntegration()

Opportunity to implement a REST-based integration to your Real-Time IoT Solution

A placeholder URL is used as an example

Triggered by /location topic

Kind: global function

RTAssetUpdateTagLocation()

Keeps track of a tag's most recent location

Triggered by /location topic

If a Tag with the corresponding ID is not found in the COLLECTION_NAME, a new row is created

Kind: global function

Message

Kind: global typedef
Properties

Name Type Description
id string ID for a tag
lat number Latitude in decimal degrees, ex. 30.266822
long number Longitude in decimal degrees, ex -97.742462

GeofenceBounds

Kind: global typedef
Properties

Name Type Description
NWCorner Point Northwest Corner
NECorner Point Northeast Corner
SECorner Point Southeast Corner
SWCorner Point Southwest Corner

Point

Kind: global typedef
Link: geo library Point Object

CoordinateSystem

Kind: global typedef
Link: geo library Coordinate System

RTAssetConfiguration

Kind: global typedef
Properties

Name Type Description
messageSchema Message Schema for MQTT JSON Message
geofenceBounds GeofenceBounds Bounds for the geofence
Polar CoordinateSystem coordinate system, can be changed to Cartesian

RTAssetUtil

Kind: global typedef

RTAssetUtil.verifyMessageSchema(unparsed) ⇒ Message | false

Kind: static method of RTAssetUtil
Returns: Message | false - parsed message, false if failed

Param Type Description
unparsed string message body, needs to be JSON format