Location
tracking

Command and control center for your fleet of vehicles.

SIGN UP FOR FREE

Scenario

Build delivery service, with fleet location tracking and route allocation. Each vehicle has a tablet mounted to the dashboard. Each vehicle is added to your backend with an unique ID.

Outcome:
  • Monitor a fleet of cars
  • Get the location of a single vehicle
  • by state or country
  • Assign route to fleet vehicles
  • Notify client of vehicle location in real-time
  • You have a backend with a list of fleet vehicles

Getting started

For a visual reference refer to the diagram above.

Create the Topic

NoLag works a little differently to other Pub/Sub solutions out there. For better security and at the same time more flexibility, we can not create Topics on the fly. We have to create them in the NoLag Portal.

Let's create a Topic called "VehicleLocation" we will track the location of the vehicle with this Topic. We will also create a Topic called "VehicleRoute". We will use this Topic to send new delivery pickup and drop-off locations to drivers.

Get the access token

All devices that connect to the NoLag infrastructure require an Access Token.

There are 2 ways to create an access token:

For this app we will create a new Access Token for each vehicle. This access token can be associated with each vehicle in your own backend.

Vehicle publish location (Refer to yellow line in illustration)

The tablet inside the vehicle will constantly publish its location to Topic "VehicleLocation" with NQL identifier "location_vehicle_vehicle001".

We can also attach four more identifiers:
  • "location_vehicle_city_of_yarra"
  • "location_vehicle_richmond"
  • "location_vehicle_victoria"
  • "location_vehicle_australia"
These will help us narrow down the search when HQ Dashboard and backend-booking is looking for a Vehicle.
// TypeScript - Publish Vehicle location const deviceAccessToken = "2695b73a33eaba77031b522635939d60"; const vehicleNolagInstance = await WebSocketClient(deviceAccessToken); const payload = { vihicleId: "location_vehicle_vehicle001" lat: "-37.82359954226292", lng: "144.9901344848444" } const topicName = "VehicleLocation"; let vehicleNqlIdentifiers = [ "location_vehicle_vehicle001", "location_vehicle_city_of_yarra", "location_vehicle_richmond", "location_vehicle_victoria", "location_vehicle_australia", ] // publish vehicle lication vehicleNolagInstance.publish( topicName, stringToArrayBuffer(JSON.stringify(payload)), nqlIdentifiers );

Vehicle subscribe to routes (Refer to orange line in illustration)

At the same time, the vehicle app will also subscribe to Topic "VehicleRoute", but this time we set the NQL identifier of "route_vehicle_vehicle001".

The vehicle can now receive real-time delivery changes.

// TypeScript - Subscribe to HQ route change const topicRouteName = "VehicleRoute"; const nqlIdentifiers = [ "route_vehicle_vehicle001", ] // vihicle receive real-time route updates const vehicleRoute = vehicleNolagInstance.subscribe(topicRouteName, { OR: nqlIdentifiers, });

HQ dashboard

To manage your fleet you will need a portal showing vehicle location in real-time. We might also need the ability to manually assign a delivery to a vehicle.

Now the fun starts. The HQ dashboard will subscribe to Topic "VehicleLocation", but will dynamically set NQL identifiers depending on the data the user wants to see.

Example:
  1. If we want to see the location of all vehicles in the county

    Set NQL identifiers attached to "VehicleLocation" to "location_vehicle_australia"

  2. If we want to see the location of all vehicles in the state

    Remove identifier "location_vehicle_australia" and set NQL identifier to "location_vehicle_victoria"

  3. If we want to see the location of all vehicles in the suburb

    Remove identifier "location_vehicle_victoria" and set NQL identifier to "location_vehicle_richmond"

  4. If we want to see the location of a single vehicle

    Remove identifier "location_vehicle_richmond" and set NQL identifier to "location_vehicle_vehicle001"

// TypeScript - Subscribe Vehicle location const deviceAccessToken = "b281b5d14df735f9f368bd6721d71faf"; const hqNolagInstance = await WebSocketClient(deviceAccessToken); const topicName = "VehicleLocation"; const vehicleRoute: ITopic = hqNolagInstance.subscribe(topicName); // receive data from Topic name vehicleRoute.onReceive((received) => { // received data }); // example 1 vehicleRoute.addIdentifiers({ OR: [ "location_vehicle_australia" ] }); // example 2 vehicleRoute.removeIdentifiers({ OR: [ "location_vehicle_australia" ] }); vehicleRoute.addIdentifiers({ OR: [ "location_vehicle_victoria" ] }); // example 3 vehicleRoute.removeIdentifiers({ OR: [ "location_vehicle_victoria" ] }); vehicleRoute.addIdentifiers({ OR: [ "location_vehicle_richmond" ] }); // example 4 vehicleRoute.removeIdentifiers({ OR: [ "location_vehicle_richmond" ] }); vehicleRoute.addIdentifiers({ OR: [ "location_vehicle_vehicle001" ] });

Assigning a new route to vehicle is as easy as publishing to “VehicleRoute” and setting the NQL identifier to “route_vehicle_vehicle001”. Now only one Vehicle will receive a new route update.

You could publish the route for a big delivery to multiple drivers. Just add more to your OR identifier list “route_vehicle_vehicle001” or “route_vehicle_vehicle002” or “route_vehicle_vehicle003”.

// TypeScript - Publish Vehicle route const topicRouteName = "VehicleRoute"; const payload = { orderId: "location_vehicle_order_inv_001" startLat: "-37.820777331492586", startLng: "144.99406125118148", endLat: "-37.82475834707238", endLng: "145.00737842391288" } const nqlIdentifiers = [ "route_vehicle_vehicle001", "route_vehicle_vehicle002", "route_vehicle_vehicle003", ] // publish vehicle route nolag.publish( topicRouteName, stringToArrayBuffer(JSON.stringify(payload)), nqlIdentifiers );

Automated vehicle route assignment

No fleet management company will sit around waiting for deliveries to come in. They would automate the process.

Auto vehicle route assignment sequence:
  • Fleet booking system will receive a delivery request.
  • Client selects a specific GPS location for pickup and drop-off.
  • Pickup GPS location is equal to a specific suburb.
  • Fleet booking system will connect to NoLag, and subscribe to Topic “VehicleLocation” with NQL “location_vehicle_richmond” selected, this will give the backend a real-time list of all active vehicles in a selected suburb, if no vehicles found, then expand the search to state
  • Backend will select the vehicle, and publish the new route the vehicle via Topic “VehicleRoute” with NQL identifier “route_vehicle_vehicle001”
  • The payload will contain the unique order ID, this bit is very important

Vehicle will add a new NQL identifier “location_vehicle_order_inv_001” to publishing Topic “VehicleLocation”.

// TypeScript - Publish Vehicle route const deviceAccessToken = "53170dc899421b15997a3d586175f628"; const autoRouteNolagInstance = await WebSocketClient(deviceAccessToken); const topicRouteName = "VehicleRoute" const payload = { orderId: "location_vehicle_order_inv_001" startLat: "-37.820777331492586", startLng: "144.99406125118148", endLat: "-37.82475834707238", endLng: "145.00737842391288" } const nqlIdentifiers = [ "route_vehicle_vehicle001", ] // publish vehicle route nolag.publish( topicRouteName, stringToArrayBuffer(JSON.stringify(payload)), nqlIdentifiers );
// TypeScript - Vehicle Publish Vehicle location to invoice number const deviceAccessToken = "53170dc899421b15997a3d586175f628"; const autoRouteNolagInstance = await WebSocketClient(deviceAccessToken); const topicRouteName = "VehicleRoute" vehicleNqlIdentifiers = [ ...vehicleNqlIdentifiers, "location_vehicle_order_inv_001", ] // publish vehicle lication vehicleNolagInstance.publish( topicName, stringToArrayBuffer(JSON.stringify(payload)), vehicleNqlIdentifiers );

Client track their delivery (Refer to green line in illustration)

The client portal can track their driver location by subscribing to Topic “VehicleLocation” and NQL identifier “location_vehicle_order_inv_001”.

// TypeScript - Subscribe Vehicle location const deviceAccessToken = "c87806133e9ca4eb1d0f74ac9c683860"; const clientNolagInstance = await WebSocketClient(deviceAccessToken); const topicName = "VehicleLocation"; const vehicleRoute: ITopic = clientNolagInstance.subscribe(topicName); // receive data from Topic name vehicleRoute.onReceive((received) => { // received data });

Summery

  • We created a Fleet tracking app,
  • We only used two Topics.
  • All data traveling between allowed devices are secure and isolated using NQL identifiers
  • We greatly simplified the real-time infrastructure.

Read more

For more details, explore our developer documentation.