This presents one possible solution to the project description described in the previous topic. The code for this project can be found in the GitHub repository for this course, found in lesson8/nrf91_simple_tracker of whichever version directory you are using (v2.2.0-v2.3.0 or v2.4.0).
In this project, CoAP/DTLS is used as a transport layer to carry the GPS coordinates to a CoAP server.
The data sent to the server is shown in the table below:
Permitted CoAP methods (nRF9160)
Permitted CoAP methods (client)
Latitude and longitude in degrees
Position accuracy (2D 1-sigma) in meters.
Last seen time
Date and time of last satellite fix (in UTC time)
[Latitude, longitude]: 59.919568,10.686956
[Accuracy]: 10.1 m
[Last seen time]: 2022-09-15 12:45:00
The nRF9160 device acts as a CoAP client that sends POST requests with GPS data at regular intervals to a CoAP server. A user can use any web browser on any device to access the data. Alternatively, a CoAP client running on a PC, smartphone, or tablet can send a GET request for the data posted by the nRF9160 SiP.
By default, the project uses the public CoAP sandbox server californium.eclipseprojects.io, which is the same one used on the exercises in Lesson 5. However, the project works on any other CoAP server of your choosing as long as you update its address and PSK information in the application configuration file through Kconfig.
Your device will create its own resource on the CoAP server. The name of the resource created by your board is set by the Kconfig CONFIG_COAP_DEVICE_NAME. Set your own device name in Kconfig or prj.conf and make sure that your device name starts with cali. as this is a requirement from the CoAP sandbox server californium.eclipseprojects.io (for example the device name: cali.Ali.nrf9160)
How it works
The application starts by activating the GNSS receiver and searching for GPS satellites in the sky. As we covered in Lesson 6, your board needs to have visible access to the sky in order to get a fix. Once a GPS fix is obtained (enough satellites were found to generate valid GPS coordinates), the LTE modem is activated and data is sent over CoAP to the CoAP server. After that, the LTE modem is deactivated and the device goes to sleep for the interval set by CONFIG_TRACKER_PERIODIC_INTERVAL (default to 120 seconds). Once that interval time has passed, the cycle will repeat itself as shown in this flowchart:
Since we are manually switching the LTE modem on and off, this provided solution is an implementation that works regardless of whether your SIM card and/or network provider supports power-saving techniques (PSM and eDRX).
Pressing button 1 on your device will show you the status of the tracker device through the LEDs. Pressing button 1 twice switches off the LEDs to save power.
The table below shows what the different LEDs on the device indicate:
No LTE (error)
Searching for GPS signal
GPS fix found
How to get the data
Your development kit will create its own resource on the CoAP server. The name of this resource is set by the Kconfig CONFIG_COAP_DEVICE_NAME. Again, make sure that your device name starts with cali. as this is a requirement from the CoAP server.
nRF91 simple tracker web app
We also have an open-source web app to parse the coordinates sent over CoAP and visualize it live on a map.
Go to this website: https://developer.nordicsemi.com/.pc-tools/nrf91-simple-tracker/ and enter the full URL (coap:// or coaps://) of your nRF91 simple tracker CoAP resource. Then click Connect and you will see your location visualized on the map. Please note that it is case sensitive, so make sure to match whatever you set CONFIG_COAP_DEVICE_NAME to.
The web app is configured to draw the last 10 coordinates received (20 minutes time window assuming a CONFIG_TRACKER_PERIODIC_INTERVAL= 120), and the old ones will automatically be removed from the map.
Clicking on a pin will give you details of the coordinates with the time when it was captured and converted from UTC format to your browser time zone.
The web app expects valid data to be available on the resource. If there are none, the web app will throw an error message and ask you to reconnect.
You can use a browser on any device to obtain the GPS data, by using a CoAP crawler hosted by coap.me, found at this address: https://coap.me/crawl/coap://californium.eclipseprojects.io.
Scroll down to locate your own device name, in our case cali.Ali.nRF9160, with the /echo/ prefix. Then click on this link to access the data.
There are other options to receive the raw data as well. If you are using a PC, you can download the desktop program cf-browser (you need Java Runtime Environment installed on your machine), like we did when testing Lesson 5 Exercise 1 and 2. Then connect to the CoAP server californium.eclipseprojects.io and locate your resource name as shown in the illustration below:
Another option is to use the chrome extension Copper for Chrome (Cu4Cr) CoAP. Then connect to the CoAP server californium.eclipseprojects.io and locate your resource name as shown in the illustration below:
If you are using an Android device, there are several CoAP clients that you can download from the Play Store, for example CoAP Client. There are also CoAP iOS apps available in the App Store.