element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Summer of Sensors Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Summer of Sensors Design Challenge
  • More
  • Cancel
Summer of Sensors Design Challenge
Blog Smart Container Tracking - Project Demo #5
  • Blog
  • Forum
  • Documents
  • Design Challenge
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Summer of Sensors Design Challenge to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: rahulkhanna
  • Date Created: 16 Nov 2022 10:40 PM Date Created
  • Views 794 views
  • Likes 6 likes
  • Comments 0 comments
  • stmicrocontroller
  • smartag
  • Summer of Sensors Design Challenge
  • nfc
  • summer of sensors
  • sensor
  • TAG You’re it
Related
Recommended

Smart Container Tracking - Project Demo #5

rahulkhanna
rahulkhanna
16 Nov 2022
Smart Container Tracking - Project Demo #5

Welcome to my #5th blog of the Summer of Sensors Design Challenge. I shared my approach to making Smart Container Tracker and the unboxing for TAG You’re it, Challenger. We had configured the STEVAL-SMARTAG1 and connected it to the ST asset tracking app in the previous blog & DST-tracking dashboard. In this post, I recorded my project step by step with the images & videos wherever required. Without any delay, let's get started. 

Smart Container Tracking - Idea #1
Smart Container Tracking - Unboxing #2
Smart Container Tracking - Interfacing the STEVAL-SMARTAG1 #3
Smart Container Tracking - DSH-asset tracking dashboard #4
Smart Container Tracking - Project Demo #5

Workflow Diagram

Many community members recommended using the GPS sensor to track the item while it is in transit during the Idea blog discussion. I was inspired by that and decided to utilize Sony's spresense board. Most importantly, this board features GNSS compatibility for GPS, QZSS, and GLONASS, enabling us to track the delivery seamlessly. It is extremely small and user-friendly. The GPS and sensor data will be sent to the cloud server using a GSM module.

image

Setting up Sony Spresense Board

Spresense is a compact development board based on Sony’s power-efficient multicore microcontroller CXD5602. It allows developers to create IoT applications in a concise time and is supported by the Arduino IDE as well as the more advanced NuttX based SDK.

image image

Features:

  • Integrated GPS - The embedded GNSS with support for GPS, QZSS and GLONASS enables applications where tracking is required.
  • Hi-res audio output and multi mic inputs - Advanced 192kHz/24 bit audio codec and amplifier for audio output, and support for up to 8 mic input channels.
  • Multicore microcontroller - Spresense is powered by Sony's CXD5602 microcontroller (ARM® Cortex®-M4F × 6 cores), with a clock speed of 156 MHz.

Interfacing with STEVAL-SMARTAG1 & GSM Module

You can find the pinout of the Spresense board below. 

image   image

Connect the GSM TX and RX pins to D3& D4. Connect the SMARTAG Tx pin to D0. The NFC reader triggers are sent on UART. Once the trigger

Detected NFC FIELD_RISING OR Detected NFC FIELD_FALLING is received, and the sensor data is fetched from the DSH-web dashboard using the API. The GPS coordinates and the sensor data are sent to the Thingspeak Dashboard for visualization. 

Fetching GPS Coordinates

GPS Data:

NMEA Message Structure

To understand the NMEA message structure, let’s examine the popular $GPGGA message. This particular message was output from an RTK GPS receiver:

$GPGGA,181908.00,3404.7041778,N,07044.3966270,W,4,13,1.00,495.144,M,29.200,M,0.10,0000*40

All NMEA messages start with the $ character, and each data field is separated by a comma. The $GPGGA is a basic GPS NMEA message. There are alternative and companion NMEA messages that provide similar or additional information. Here are a couple of popular NMEA messages similar to the $GPGGA message with GPS coordinates in them (these can possibly be used as an alternative to the $GPGGA message): $GPGLL, $GPRMC 

Now, Run the GPS code to print the GPS data in lat & long format. The Following output is computed using the Spresense inbuilt GPS sensor

#include <GNSS.h>
static SpGnss Gnss;

void setup() {
    /* Setup serial output for printing. */
    Serial.begin(115200);

    /* Initialize GNSS. */
    Gnss.begin();
    Gnss.setInterval(5);    /* Update every five seconds. */
    Gnss.start();
}

void loop()
{
  /* Check for an update. */
  if (Gnss.isUpdate())
  {
    /* Get navigation data. */
    SpNavData NavData;
    Gnss.getNavData(&NavData);

    /* Print position and satellite count. */
    Serial.print("Lat=");
    Serial.print(NavData.latitude, 6);
    Serial.print(", Lon=");
    Serial.print(NavData.longitude, 6);
    Serial.print(", Satellites=");
    Serial.print(NavData.numSatellites);
    Serial.println("");
  }
}
   image

Configuring ThinkSpeak Cloud

Go to https://thingspeak.com and register there. And carry out the following steps: Make two fields "latitude" & "longitude" on a new channel on Thingspeak.

image

Copy the credentials below and paste them into a text file by clicking Save Channel on the page's bottom-left corner. We'll continue to use it for our code.

image

Copy the Arduino code that is included with these instructions. Ensure that the default credentials (myWriteAPIKey) in the C code are substituted with yours.

#include <MKRGSM.h>
#include "secrets.h"
#include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros
#include <GNSS.h>
static SpGnss Gnss;

// PIN Number
const char PINNUMBER[]     = SECRET_PIN;
// APN data
const char GPRS_APN[]      = SECRET_GPRS_APN;
const char GPRS_LOGIN[]    = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASS;

GSMClient client;
GPRS gprs;
GSM gsmAccess;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

String myStatus = "";

void setup() {
  Serial.begin(115200);  //Initialize serial
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo native USB port only
  }

  Serial.println("Starting Arduino web client.");
  boolean connected = false;

  // wait 10 seconds for connection:
  delay(10000);

  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connected");

  /* Initialize GNSS. */
  Gnss.begin();
  Gnss.setInterval(5);    /* Update every five seconds. */
  Gnss.start();

  ThingSpeak.begin(client);  // Initialize ThingSpeak
}

void loop() {

  if (Gnss.isUpdate())
  {
    /* Get navigation data. */
    SpNavData NavData;
    Gnss.getNavData(&NavData);

    /* Print position and satellite count. */
    Serial.print("Lat=");
    Serial.print(NavData.latitude, 6);
    Serial.print(", Lon=");
    Serial.print(NavData.longitude, 6);
    Serial.print(", Satellites=");
    Serial.print(NavData.numSatellites);
    Serial.println("");

    // set the fields with the values
    ThingSpeak.setField(1, NavData.latitude);
    ThingSpeak.setField(2, NavData.longitude);

    // set the status
    ThingSpeak.setStatus(myStatus);

    // write to the ThingSpeak channel
    int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    if (x == 200) {
      Serial.println("Channel update successful.");
    }
    else {
      Serial.println("Problem updating channel. HTTP error code " + String(x));
    }
  }

  delay(10000); // Wait 10 seconds to update the channel again
}

This will be sending the GPS coordinates to the thingspeak server. 

image

API integration from DST- Web Dashboard

Send HTTP request with telemetry data:

  • URL: https://jim3rgi6d3.execute-api.eu-central-1.amazonaws.com/v1/telemetry
  • Headers:
    • Authorization header set equal to asset-tracking api-key previously created
    • Content-type: application/json
  • Body
  {
    "device_id":"<device ID>",
    "values":[
      {"ts":<epoch milliseconds>,"t": "tem", "v": 25.52},
      {"ts":<epoch milliseconds>,"t": "hum", "v": 80.1},
      {"ts":<epoch milliseconds>,"t": "pre", "v": 1000},
      {"ts":<epoch milliseconds>,"t": "acc", "v": { "x": 0.1, "y": 0.1, "z": 0.1 }},
      {"ts":<epoch milliseconds>,"t": "gyr", "v": { "x": 0.1, "y": 0.1, "z": 0.1 }},
      {"ts":<epoch milliseconds>,"t": "mag", "v": { "x": 0.1, "y": 0.1, "z": 0.1 }},
      {"ts":<epoch milliseconds>,"t": "gnss", "v": { "lat": 0.1, "lon": 0.1, "ele": 0.1 }},
      {"ts":<epoch milliseconds>,"t": "evt", "v": { "et": "threeshold", "m": "ORIENTATION", "l": "TOP", "msg": "Device changed its orientation" } }
    ]
  }


image
We've added a http client request to fetch the sensor data. The collected sensor data(Temp, Pressure) will be sent to the Thingspeak dashboard.

Outcome & Conclusion

The final connections is shown below. I had configured the ThingBoard Cloud. The Fleet tracking app would be the perfect visualization for this application. 

imageimage

And this is the final blog for the Summers of Sensors Design Challenge. Thanks to element14, stmicrocontroller, and the sponsors for providing me with an opportunity to work with this incredible hardware.

There is still a lot to learn from them. Thanks for your time. 

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube