Maker Pro
Ubidots

DIY Sigfox GPS asset tracking with Ubidots

March 15, 2018 by Agustin Pelaez
 
Share
banner

Connect your Sigfox GPS asset tracking device to Ubidots and deploy your IoT asset tracking applications in no time

Read tue full tutorial here. Connect your Sigfox GPS asset tracking device to Ubidots cloud and deploy your IoT asset tracking applications in no time.

Section Header

Sigfox wide-area, low power devices, and Ubidots are a simple to integrate IoT solution from device to application. Track cars, buses, containers, trashcan, or even your golf-bag. Keep track of cattle or take your Sigfox device to go and explore the great outdoors.

In this tutorial, we will be using UbiParsers, a feature of Ubidots IoT application development platform.

Requirements

  • Any Sigfox device. We use a Suntech ST730
  • Sigfox Backend subscription
  • Ubidots account with the UbiParsers add-on enabled

Setup:

  • About setting up Suntech ST730
  • Ubidots Parser Configuration
  • Sigfox Callback Configuration

I. About setting up the Suntech ST730

The Suntech ST730 is a portable device equipped with Sigfox technology, the GNSS location, Wi-Fi, and a set of sensors — making it a nice option for out-of-the-box asset tracking. This module lets users manage data when needed, preventing excess energy consumption with efficient time-outs.

This guide does address the set up of the Suntech ST730 nor its possible configurations; instead, we will be showing a few good set-up practices for building a highly accurate GPS application.

Note: Ubidots is committed to helping you connect your ST730 to our IoT and cloud application platform the easiest way possible. With more guides arriving all the time, see Ubiparse for more data analytics parsers to pair or enhance your applications.

Suntech ST730 GPS Set-up Tip:

Data format for GPS in this tutorial is:

  • 4 bytes for latitude
  • 4 bytes for longitude

Both latitude and longitude are coded using the IEEE- Standard 754 floating point format. If a GPS reading doesn't follow this format, no data reading will be sent. Here's an example of a GPS reading properly done:

Example: 02c1b6c81cc23c5514 

0x02   – data type
0xC1B6C81C   – latitude -> -22.84771
0xC23C5514   – longitude -> -47.083084

See the SuntechST730 User Manual for additional instructions or troubleshooting to your hardware's setup.

Once you have setup the module to send data —as shown above—, we will now configure the Ubiparser.

2. Ubidots Parser set up

Note: a parser is a Node.js cloud function executed when a GET, POST, or HTTPS request is made in the Parser URL as illustrated below. 

See the SuntechST730 User Manual for additional instructions or troubleshooting to your hardware's setup.

Once you have setup the module to send data —as shown above—, we will now configure the Ubiparser.

2. Ubidots Parser set up

Note: a parser is a Node.js cloud function executed when a GET, POST, or HTTPS request is made in the Parser URL as illustrated below. 

For creating a Parser go to your Ubidots account -> Device Management -> Parsers. NOTE: If you cannot see the Parsers module in your account, you will need to enable the add-on for $30/month in the billing section of your account. 

2. Click the blue plus icon in the upper-right corner to create parsers: 

3. Assign a name to the Parser, e.g. "suntech-ubidots", to identify it in the Sigfox backend later. 

4. Assign the POST as the HTTP method from the scrollbar.

5. Click on "Make it live" to generate an API endpoint URL containing the name of your parser. The URL should look like this:

6. Now, just copy and paste the code located below into the Ubiparsers Editor. When pasted, assign your Ubidots TOKEN where indicated:

6. Now, just copy and paste the code located below into the Ubiparsers Editor. When pasted, assign your Ubidots TOKEN where indicated:


var request = require('request-promise');
var token = "xxxxxxxxxxxxx"; // Assign your Ubidots TOKEN

async function main(params) {

    var device_id = params.device_id;

    var buf = new Buffer(params.data, 'hex')

    console.log(buf);

    var msg_type = buf.readInt8(0);

    if(msg_type == 2){

        var lat = buf.readFloatBE(1);

        var lng = buf.readFloatBE(5);

        console.log(lat);

        console.log(lng);

    }

    // Build payload

    var payload = {"position": {"value":"1", "context":{"lat": lat, "lng":lng}}};

    // Make POST request to Ubidots

    var post_response = await ubidotsPost(token, device_id, payload);

    // Pass Ubidots' API response to the parser' response

    return post_response;

}

async function ubidotsPost(token, device_label, data) {

    var options = {

        method: 'POST',

        url: 'https://industrial.api.ubidots.com/api/v1.6/devices/' + device_label + '?force=true',

        body: data,

        json: true,

        headers: {

            'Content-Type': 'application/json',

            'X-Auth-Token': token

        }

    }; 

    return request.post(options);

}

For running a Parser test, please paste this code in the editor that popups: 

{"device_id": "12345", "data": "02c1b6c81cc23c5514"}

3. Sigfox Callback Configuration

Click here for an intro and docs to configure a call in the Sigfox backend with your Suntech device. For this, you will need to use the parameters listed below. 

Type: DATA - UPLINK

Channel: URL

Custom payload config: Leave it in blank

Url pattern: https://parse.ubidots.com/prv/iotexpo/suntech-ubidots (this is the URL generated by the Ubidots parser in the step above)

Use HTTP method: POST

Header: X-Auth-Token - {Assign_your_ubidots_token}

Content Type: application/json

Body:

{
  "device_id": "{device}",
  "data":"{data}"
}

When the callback is executed properly, your Sigfox backend will look similar to this: 

2. Press "OK" to save all the changes and visualize your new device in Ubidots.

With this, your Sigfox callback is ready and the Ubiparser is properly transforming data received to Ubidots cloud. Now it is time to develop your application with Ubidots code-free IoT application tools.

Go to the Device section and see a newly created device with the ID of Suntech Device as name: 


Ubidots is an Internet of Things (IoT) Application Development Platform that empowers system integrators and innovators to launch control, monitoring, and automation applications that turn sensor data into actionable insights. Hiring an engineering team to merge the physical world with a digital world and create an IoT application that both functions and looks great are costly in both time and money, so we did it for you. Ubidots exists as an efficient and economical resource to develop private cloud-based IoT applications and integrate data-driven solutions into enterprises and research.

Related Content

Comments


You May Also Like