Dispatching Optimized Routes to Samsara Telematics

Using Samsara Telematics and NextBillion.ai's Route Optimization API to dispatch and manage optimized routes can revolutionize fleet management. This guide outlines the easy integration steps for pushing optimized routes from NextBillion.ai to Samsara, alerting drivers, executing routes, and tracking data transmission to improve operational excellence.

Step 1: Push Optimized Routes to Samsara

Utilize the Optimization API to initiate route optimization based on the imported data and configured settings. Observe how NextBillion.ai's Route Optimization API intelligently optimizes routes for your fleet's specific needs.

The following API endpoint dispatches optimized routes to Samsara.

1POST https://api.samsara.com/fleet/routes?

The following code serves the purpose of interacting with data and APIs to optimize routes and perform tasks within the Samsara fleet management system.

1// For each route in NB.ai solution
2 let theRoutes = [];
3 let errors = "";
4 function runRouteCreateQuery(i) {
5 // ..
6 }
7 nbaiOptimizationStatus.data.result.routes.forEach( rte => {
8 // ...
9 });
10 runRouteCreateQuery(0);

Code Breakdown and Explanation

  • Parsing and Extracting Routes: The code begins by parsing the response from NextBillion.ai (NB.ai) and extracting optimized routes from it.

  • HTTP POST Request: The code includes a POST request to the https://api.samsara.com/fleet/routes? endpoint. This request is used to create routes within the Samsara system.

  • Route Creation Process: The subsequent steps outline the creation of routes in Samsara for each route obtained from NB.ai's solution. The code iterates through each step of the route to extract relevant information.

  • Iterating Through Steps: The code iterates through each step of a route provided by NB.ai. It processes each stop on a route and prepares the necessary data.

  • Handling Different Types of Stops: Depending on the type of stop (start, end, or regular), the code prepares the data accordingly. It creates a list of stops, including their locations and arrival times.

  • Defining Settings and Route Information: The code defines route settings, including conditions for route starting and completion. It also assembles all the extracted information to create a complete route object.

  • Running Route Creation Queries: The runRouteCreateQuery function is used to trigger the creation of routes in the Samsara system. It uses the prepared route data and sends requests to Samsara's API.

  • Tracking Progress and Handling Errors: The code tracks the progress of route creation and handles errors that might occur during the process. It updates error messages and continues with the route creation process.

In essence, this code demonstrates the creation of routes in the Samsara fleet management system based on the optimized routes obtained from the NextBillion.ai solution. It leverages APIs and data processing to streamline and automate the route creation process, enhancing efficiency within the fleet management workflow.

Upon sending the optimized routes to Samsara, the Samsara dashboard will assume the appearance showcased in the images depicted below.

docs-image docs-image

Step 2: Samsara Driver App Alerts Driver

  • Use Samsara's Driver App to notify drivers about newly optimized routes.

  • Trigger notifications that highlight route updates, stop sequences, and estimated arrival time.


Step 3: Driver Executes Route in Samsara

  • Drivers use the Samsara Driver App to access the optimized route details after receiving alerts.

  • To execute the route efficiently, follow Samsara's intuitive navigation guidance.

Step 4: Upload Tracking Information to NextBillion.ai

  • Samsara's telematics devices collect and transmit real-time tracking data as the driver travels along the route.

  • Implement data retrieval mechanisms to gain access to Samsara's tracking data.

GET API Request

The following API request shows the interaction and exchange of data between Samsara and NextBillion.ai’s platforms.

2 "request": {
3 "url": "https://api.nextbillion.io/skynet/config?key=<your_api_key>",
4 "method": "GET",
5 "body": null,
6 "headers": "{..}"
7 },
8 "response": "{...}"

GET Webhook Response

2 "status": "Ok",
3 "data": {
4 "config": {
5 "webhook": []
6 }
7 }

Example tracking response by webhook

The following webhook data structure provides a detailed snapshot of an alert event, including its type, timestamp, details, associated device and more. It's used to capture and convey significant occurrences within the system for further analysis or action.

2 "id": "...",
3 "msg": {
4 "eventId": "...",
5 "eventMs": "...",
6 "eventType": "...",
7 "orgId": "...",
8 "webhookId": "...",
9 "event": "{...}"
10 },
11 "vehicle_id": "..."

Step 5: Sending data to NextBillion.ai

  • Retrieve tracking data from Samsara's telematics platform on a regular basis.

  • Push tracking data to the NextBillion.ai platform via designated API endpoints.

You can seamlessly integrate NextBillion.ai's route optimization with Samsara Telematics by meticulously following these integration steps. This integration allows you to improve fleet operations by optimizing routes, providing real-time driver alerts, routing in Samsara, and transmitting comprehensive tracking data. Take advantage of the collaboration between these two powerful platforms to achieve maximum efficiency, cost-saving and operational excellence in your fleet management efforts.