Build a GPS live tracking system

  • 0

Build a GPS live tracking system

Category : IoT

GPS tracking systems are widely utilized in a multitude of applications such as fleet management, security, personal or merchandise remote monitoring.
In this tutorial we will show how to build and program a mobile GPS Tracking device that is capable of streaming location coordinates to an IoT cloud and enable a real-time map view from any location/device with a simple web-browser.

1. Hardware components

 

IMG_20170711_134936090 IMG_20170707_163651165 IMG_20170707_163658928_HDR IMG_20170711_191437023
<
>

For building the prototype we choose the following off-the-shelf components:

  • Raspberry Pi or any Linux embedded device
  • GPS Module or Dongle using standard NMEA protocol
  • 3G/4G Mobile broadband modem
  • Sim Card with data plan

 

2. Software components

The full code and build instructions are available on github.

2.1 IoT Cloud

PubNub cloud provides a realtime messaging API for building Mobile, Web, and IoT Applications. It has SDKs supporting a large set of platforms languages and Operating Systems.

To use PubNub, you should first register for an account, create an application and add a new Key set for our GPS data streaming. For more information you can consult the Quick Start guide.

After that you will get a pair of Keys one for publishing data to a channel and other one for subscribing to it.

2.2 Embedded Software

 

2.2.1 Broadband connection

Follow our previous guide on how to use Ofono to enable cellular modem connection.

2.2.2 GPS interfacing

GPS modules put out typically on the serial interface a series of strings of information called the National Marine Electronics Association (NMEA) protocol.

For our use case all we need is to fetch the position, speed and time. For that parsing the $GPRMC sentences is  enough. As parsing library we use minmea, a lightweight C library:

Parsing is restricted to only RMC sentences:

If input line is not empty pack it into a rmc frame :

Get time, speed (m/s) and coordinates (latitude, longitude) :

Those parameters are then packed into a json array :

Here is an output example:

 

2.2.3 Location publishing

PubNub C-SDK is used to used to publish the data on the cloud:

The connection initialization is done using the Publish/Subscribe keys:

Publishing the json GPS data:

*In our code, we choose to send data only if the target is moving (speed > Threshold)

Finally verify if data was correctly sent:

 

2.3 Live View Web Interface

 

 

For tracking the device and display the position in real-time on a map, we will use Mapbox and Javascript powered EON Dashboard.

The full code can be found here.

To start you will need to create a MapBox account. Once this is done, you can either create a new map design or use an existing one for example Mapbox streets.

You will also get a Mapbox authentication token to be used to connect with your account.

The Javascript code will subscribe to the PuBNub corresponding channel, fetch the position and show it on the Map in real-time.

Initialize connection to PubNub:

Define the EON map function by providing the API access token (mbToken), map ID (mbId) and the channel used to get GPS data from:

Function setView is added to set the initial position from the last know value:

Zoom option is set a focus on the position:

Finally a following position marker parses the latlng coordinates and show them on the map:

 

Conclusion

In this tutorial we have implemented a real-time GPS tracking system using a Raspberrypi connected to the Cloud. In future articles we will show how to extend this setup using OBD2 adapter and a Bluetooth connection to stream more data from the car to the cloud.


  • 0

Add mobile broadband connectivity to Embedded Linux

In this article we will show how to extend an IoT Embedded Linux System with a broadband connection using 3G/4G networks.

Poky/Yocto is used as Linux distribution in combination with the mobile telephony application oFono.

As hardware example we have a raspberrypi, nevertheless the same setup was applied and verified on other standard development kits and custom boards.

For the broadband connectivity Huawei E173  3G USB stick is used:

If using a different modem, check first if it’s supported with oFono. Here is a list of supported hardware.

Kernel configuration

In order to support 3G USB modems, the following kernel configuration options
need to be enabled :

If those options are used, you should see the following in dmesg:

 

Yocto recipes

To support oFono, the image recipe should include the following packages:

To allow ofono integration with network manager connman, the following packages can be added:

Connman shall be then enabled with 3g support:

 

Ofono setup

oFono provides a mobile telephony (GSM/UMTS) application framework that includes consistent, minimal, and easy to use complete APIs. It offers a high-level D-Bus API for use and integrate with other applications.

The advantage of using oFono is that very simple to configure and you will not have to deal with any kind of AT commands.

Plug in your 3G modem and check if recognized by oFono:

Enable modem:

If SIM card is protected with pin, enter the code:

Depending on the country and Network provider, APN setting is to be configured:

Now the modem can be set online and activated:

Here is an example script of modem initialization:

That’s it! the modem is up and the broadband connection is enabled:

The cellular connection is also available in connman:

we can for example enable cellular connection tethering over wifi:

If having problem to connect with cellular network, you can use list-modem to check the connection status: