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.
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.
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.
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.
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(""); } }

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.
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.
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.
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 createdContent-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" } } ] }
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.
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.