Simulating a package delivery van
How to build a logistic application via simulating a delivery van
As e-commerce proliferates, logistic companies are under an immense pressure to deliver packages faster to more customers. Tracking the real time location and delivery performance of the vehicle in the fleet is vital to save cost and improve logistic efficiency. There are many fleet tracking solutions in the market, many of them rely on a GPS+UMTS based OBD2 dongle.
However, only monitoring these vehicles is not enough. One of the key objective of IoT systems today is to optimize the delivery based on feedback and provide a real time insights to end customer while improving the system efficiency. Imagine if your delivery company could accurately predict when the courier is going to arrive, within a 5 minute time slot. Wouldn’t that solve a big pain point in today’s system?
Modelling with such accuracy needs a lot of data to be captured from existing systems. For this purpose, accurately simulating vehicle movement under real traffic conditions is a major challenge. In this simulation exercise, we will model a package delivery van delivering parcels to various location in Zurich, Switzerland in real time.
We will model a situation where a delivery van driver needs to deliver 10 packets around central Zurich area.
The van will start from one address to another and deliver a packet at each location. We wouldn’t tackle the route optimization problem at the moment. The destination address is randomly choosen, upon start of each trip, with 1 km radius of current location.
The waiting time once vehicle reaches the target location is currently fixed, implying it takes equal time to deliver packet for the driver to the door steps.
The delivery vehicle will report its GPS location to a cloud platform every 10 seconds. We will track and monitor the vehicle’s postion live as well as number of pending delivery counts. Here’s how our dashboard is going to look like.
In this case, we are publishing the data to Losant as a cloud platform, but the simulation is generic and can be easily adapted to fit any other cloud platform.
If you haven’t yet, sign up for free with Losant.com and create a new Application. Let’s call it Connected truck.
Within the application create a new device named Truck. (use blank device when asked about recipe)
Choose device type as Standalone. It is important to specifiy following attributes for the device Truck:
- GPS String : location
- Number - speed
- Number - contents
Note that the names of parameters (location, contents, speed) should exactly match as in above. As you might have correctly imagined, we will report above 3 parameters to the losant platform.
Make sure you copy your Device ID from the top right corner of your device tab.
Next, Go to Tab Security and create a Device Access Key. The key should be tied to the device type Truck we just created. Make sure you download the access key and secret to your local computer. We will need it later.
At the end of this step you should have following:
A Device ID which looks like: 58a6c6e6217f8521311f28cd
An Access key which looks like: e4fc60fe-11111-22222-8480-16710b46908d
An Application Secret: XXXXXX… (A really long string)
Now go to the Dashboard Menu, create New Dashboard. Then you will see a list of gadgets to add. Simply pick GPS History, Gauge and Indicator Gadgets. There are plenty of gadgets in Losant so feel free to experiment.
Alright, we are finished with Losant for the moment. Let’s get to IoTIFY.
If you haven’t signed up yet, please request a free account with [IoTIFY.io] Once signed up, please go to Network simulator tab and create a new template.
Give a unique name to the template. We’ll call it logistics.
Set the protocol to MQTT. Change the MQTT Address to following: broker.losant.com:1883
Further in the MQTT parameters:
In the Client ID: Provide Device ID as obtained from Losant
In the Username: Provide Access Key as obtained from Losant
In the Password: Provide Access secret as obtained from Losant.
Provide following value: losant/[Device ID]/state
E.g. The topic string will look like following:-
Copy and paste following template to model a delivery van for this scenario.
The template may look like complex at a first glance but it’s quite simple actually. In the very first iteration, we will setup our state variables. The drive function will generate the GPS coordinates for vehicle. Once the drive is finished (the function will return a value with finished set to true), we will simply pick another trip after a slight wait. We will continue to drive untill we have delivered all the parcels. Once all the delivery is completed, the vehicle will simply wait at the last known location.
That’s it. Hit the preview button and you should see sample message along with Success result in the preview window. If there is any error, please check you have correctly followed the above steps.
Once the template is ready, hit Save and go to the generate tab. Specify the number of client to be 1 and number of iteration to be 100. You could reduce or increase the number of iterations if you want, usually it depends upon how many contents are to be delivered and how big is the radius of the delivery.
Make sure to click Collect extended results with state information per client checkbox so that you could monitor all the state variables in the simulation detailed result tab.
That’s it. If everything works well, after a while, the delivery vehicle will be visible in the Losant Application dashboard.
Once the simulation is finished, here is how your dashboard will look like.
Once you have played around with how the simulation works, you could add some real world conditions and add intelligence to your cloud platform to create more value for the solution. E.g.
- Analyze the route taken and suggest an optimized route.
- Slow down or accelerate the simulated vehicle speed (ask us how in the slack channel) and generate alerts when driver is driving too fast.
- Create an app which predicts to estimated arrival of delivery van to the customer.
- Change wait times at delivery stop to random values and flag excessive wait times at any stop.
- Get a delivery confirmation and put it on blockchain (moonshot, but who knows:-))
We will be happy to hear your thoughts about what application ideas you could build on top of this simulation! Please keep your comments coming.