Simulating Connected Truck

Easily simulate a connected vehicle driving on real roads with traffic conditions, thanks to IoTIFY's network simulator.


Urban mobility has become one of the key challenges for humans as more and more vehicles are daily added on the roads. It is imperative that we make our vehicle infrastructure smarter, to tackle dynamic demand and response. 

Also as factories become smarter and locate further away from the city, they want to produce goods on demand. Getting things in the hands of consumer right on time when they need it, becomes a key priority. 

In this short tutorial we will show you how you could simulate a smart connected vehicle - the basic step in doing fleet management. You could then extend your solution to the entire fleet simulation and create a real life demonstration of smart transport solution with IoTIFY. In this case, the vehicle will have following parameters tracked:-

A) GPS location: latitude and longitude with the given accuracy
B) Current speed: in meter / seconds
C) Cargo temperature: a temperature gauge connected in cargo hold.
D) Time: the current timestamp

For the sake of simplicity, we will avoid any other parameter for now, but it will be very trivial to add anything else to this simulation.

How will we track the vehicle?

The vehicle will emit the monitored parameters to an IoT platform over MQTT. In this case, we will use Losant to build a connected dashboard. However, you are free to choose any cloud platform provider of your choice and showcase your application in our slack channel. 

Overall the tutorial should not take more than 30 minutes to setup. So let’s get started.

1. Sign up with Losant

If you haven’t yet, sign up for free with Losant 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:

Note that the names of parameters (location, temperature, speed) should exactly match as in above picture. 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, which looks as follows:

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)

Alright, we are finished with losant for the moment. Let’s get to IoTIFY.

2. Get started with IoTIFY Network simulator

If you haven’t signed up yet, please get a free account with  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 Losant.

Change the MQTT Parameters to following:

The MQTT parameters should look like following:

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.

Here is how these parameters will look in Network Simulator template.

The next part is where most of the magic will happen.

MQTT Topic

Provide following value: losant/[Device ID]/state
E.g. The topic string will look like following:-

MQTT Message

In the MQTT Message, change the radio button to Function Mode and copy paste following value as it is.

state.path = drive({start:'Geneva,CH',end:'Hamburg,DE',accuracy:5});
var retval = {};
retval.time = { "$date" :}; = {}; = state.path.latitude + ","+ state.path.longitude; = state.path.speed ; = chance.integer({min:10, max:45});
//return a string value which will be sent as the message payload
return JSON.stringify(retval, null, 2);

You could save the template now. 

What did we just do? We just called drive() function with a start and end address. Learn more about our powerful syntax for templates in our guide on how to simulate location.

3. Start Simulation

Go to simulation tab in the network simulator and provide following values:-

Choose the recently created template. Provide a unique name to simulation.

Set Number of Clients to 1
(!!! Important )
More than one client will cause Losant MQTT broker to drop connections to previous one.
Repeat Message
: As long as you like. We will set to 100.
Interval: every 60 seconds.

Here is how simulation screen looks like after adding values. 

That’s it. Hit the start simulation button and you are ready to go. 

4. Build a beautiful Dashboard

Wait, simulation has started but how could you visualize it? It’s pretty easy to do that with Losant. Go to Losant Application once again and choose 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. Here’s how final simulation will look like after a while. 

The next steps

Want to simulate driving from your home to office in real time? No worries, just provide the address in the start and end field in the drive() function and it will automatically calculate the address.

You could even adjust the accuracy of GPS Simulator, just like in real life. Play with the parameter a little. 

We are looking forward to seeing what you’ll build with IOTIFY Network Simulator. Join our Slack channel from IOTIFY application to showcase other’s what you’ve built.