Connected Truck

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

Introduction

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 consumers right on time when they need them, 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 meters / second 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 (when asked to choose between create from recipe and create from scratch, click on Create Blank Device).

Choose device type as Standalone. It is important to specify 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 the Access Keys menu and create an Access Key. The key should be restricted 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-1111-2222-8480-16710b46908d An Access 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 IoTIFY.io. Once signed up, please go to Network simulator tab and create a new template.

Select MQTT(S) as connection protocol, and give a unique name to the template. We’ll call it Losant.

For the newly created template, in the MQTT Parameters section change the endpoint URL to following: broker.losant.com:1883.

The MQTT parameters should look like following:

Further in the MQTT parameters:

In MQTT Topic, provide following value: losant/[Device ID]/state, where [Device ID] is the identifier of the device we previously created in Losant. E.g. The topic string will look like following:- losant/5d149f0c34fdb20009a7791f/state In the Client ID field, provide the Device ID as above

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

In the Credentials section: in the Username field, provide the Access Key as obtained from Losant; in the Password field, providethe Access Secret as obtained from Losant:

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

Message Contents

In the Message Contents tab, copy and paste the following text.

{ 
    state.path = drive({start:'Geneva,CH',end:'Hamburg,DE',accuracy:5});
    var retval = {};
    retval.time = { "$date" : moment.now()};
    retval.data = {};
    retval.data.location = state.path.latitude + ","+ state.path.longitude;
    retval.data.speed = state.path.speed ;
    retval.data.temperature = chance.integer({min:10, max:45});    
    
    return JSON.stringify(retval, null, 2);
}

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.

To check that the template configuration is OK, click the PREVIEW button and check the result. If successful, you can save the template and start a simulation.

3. Start Simulation

Go to the SIMULATE tab in the network simulator, then choose the recently created template. The simulation ia automatically assigned a unique name, which can be changed if needed.

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. Gap between Iterations: 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, then click on Add Dashboard. Then click on Add Block and 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. For each gadget that you choose, you will have to specify the truck device and one of its attributes to be displayed. 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.

Last updated