Smart City Asset Positioning With LoRaWAN and WiFi


Use The Things Network LoRaWAN smart city low-power wide area network (LPWAN) technology, COLLOS Collaborative Location Service Portal, and MyDevices Cayenne IoT platform to implement a next generation IoT positioning solution that uses only WiFi signals.
This solution does not use GPS. Instead, WiFi signals are scanned with the press of a button and submitted to the cloud via your local LoRaWAN network for lookup by a COLLOS location service provider. With COLLOS, you have the option of using sniffed WiFi data with Skyhook to generate position lattitude and longitude (as is demonstrated in this project), or you can use the LoRaWAN network built-in position capability with TDoA/RSSI techniques. The LoRaWAN network positioning methods works best with high gateway density which may not be available in your area.
Using sniffed WiFi data, the returned location coordinates are usually quite comparable to GPS. However unlike GPS, the system works indoors!
Here's what you're going to need to do to get this up and running:
1. Assemble STMicro Nucleo-64, X-NUCLEO-ID1M01 WiFi module, Semtech LoRa shield.
2. Program the ready-to-go application firmware.
3. Create your The Things Network account and application (create device and application, then get the AppEUI and AppKey). Configure the TTN application with DevEUI, and the application firmware with AppEUI and AppKey.
4. Create your MyDevices Cayenne account, create device, and optionally install the mobile app.
5. Configure the COLLOS and Cayenne integrations in your The Things Network console.
All of this can be done for no fee, except for the hardware cost.
Step 1 - Assemble the Hardware

Asset Tracker Hardware Stackup
Attach the X-NUCLEO-IDW01M1 to the NUCLEO-L152RE as shown. Then attach the Semtech LoRa Shield. No other configuration is required. Connect to your PC with a USB mini cable and proceed to step 2.
Step 2 - Program the Firmware
Download the 'WPS Firmware Image' file
to your PC, available from the attachments section of this project. With STM32-NUCLEO, you can drag and drop this file to the 'NODE_L152RE' mass storage device that appears in your file system. Open a terminal to 115200 on the available STLINK virtual COM port. Press the reset button. Observe confirmation of operating firmware (see below expected output) and record the DevEUI. The DevEUI is unique to each and every device. Think of it as a GUID. For ST MCU devices, it is based on the factory programmed unique ID. In this example DevEUI is 2e4d7910848b2cc9.

Starting Intelligent Asset Tracker for LoRaWAN version 1 Configuration: DevEUI:2e4d7910848b2cc9 MAN_RANDOM_AP:1
Cannot start: please set your LoRaWAN AppEui and AppKey settings with 'mta set lora appeui/appkey' command then reboot.

Step 3 - Create and Configure The Things Network Account, Register Device, and Get Application Keys, Configure Firmware
Here you need to have ready the Device's unique identifier called DevEUI - an 8 hex-digit string - so that you can register a new device for it in The Things Network console after creating a new Application. Then you will get the two important hex-string numbers from the Application - the 8 byte AppEUI and the 16-byte AppKey - needed for the application firmware to enable a secure end-to-end connection to your Things Network Application.
Head over to The Things Network and sign up or log in. Add an application with this quick tutorial. Set the Application ID to anything you like. Next, register a new device.
Under the Devices section select "register device". Enter a name (Device ID) for it. Anything will do, e.g. MyAssetTracker. Then paste the DevEUI string obtained in Step 2 into the Device EUI field. Click the Register button. Once that is done, go to the Device Overview for your new device and scroll to the bottom to find "Example Code". This is the easiest way to find the AppEUI and APPKey needed for your firmware. From the example below:
AppEUI is 76B3D57EDABC9574
AppKey is DAC1F3E9EBAC12345678913994C58A4B
const char *appEui = "76B3D57EDABC9574";
const char *appKey = "DAC1F3E9EBAC12345678913994C58A4B";
In the terminal enter the AppEUI and AppKey into the firmware like this:
0000: Contiki> mta set lora appeui 76B3D57EDABC9574
0000: Contiki> mta set lora appkey DAC1F3E9EBAC12345678913994C58A4B
0000: Contiki> mta save
0000: Contiki> mta get
AppKey: [DAC1F3E9EBAC12345678913994C58A4B]
AppEui: [76B3D57EDABC9574]
DevEui: 2e4d7910848b2cc9
0000: Contiki>
Step 4 - Create MyDevices Cayenne Account and Device
Follow the The Things Network guide on how to setup Cayenne, create a suitable device, and add it as an integration. Note! We are not actually sending any payload data to Cayenne, so please ignore payload type (CayenneLPP) field and configuration as it will eventually be changed to custom. It is the COLLOS integration that will funnel position coordinate data to your Cayenne integration.
Step 5 - Configure the COLLOS and Cayenne integrations in your The Things Network console.
This is the final critical step to getting your The Things Network Application ready to receive and process your device's WiFi position data!
It is best described by The Things Networkhere. Register for a membership (free). You may have to wait a day or two to receive access. Then follow the Quick Start. For the Collos API endpoint URL, you may use the 'loraSkyhook' one:
Important! To enable WiFi localization, follow the instructions here to setup a custom payload decoder function. This is essential to having your device's sniffed WiFi data (access point MAC and RSSI) sent to the COLLOS system and forwarded to Skyhook.
Reboot the device and observe to terminal. You should see the following
Starting Intelligent Asset Tracker for LoRaWAN version 1
>> Trial start: 19
Press button to trigger position reading.
Looking for accelerometer...
LSM6DSL not present.
Starting LoRaWAN stack.. wait for join complete
LoRa stack init
SXX1272 radio version: 22
Set ADR ON: 0
Set public network: 0
Device join method=OTAA
DevEui: 2e4d7910848b2cc9
AppEui: 76B3D57EDABC9574
AppKey: DAC1F3E9EBAC12345678913994C58A4B
Send JOIN request... 0
Device state: SLEEP
Device JOIN success
Starting wifi module attempt=1.
Device state: SLEEP
Airtime added: 289 ms
TX power: 5 Datarate: 0
Successful transmission
Wifi module started.
Press the blue button on the nucleo to trigger a WiFi sniffer reading. It will try to get 6 unique station IDs into the list with up to 3 scan attempts. Since the WiFi module does not need to associate with any access point, it can be powered down into very deep sleep modes (microamp range) in between readings. The readings themselves only take a few seconds, including module restart from sleep.
(button) scan event 1
>> Running WiFi Scan (0)...
>> Got 6 scan results
--- Sorted results after scan:
[0]: SSID: TELUS1234 MAC: 9c:1e:95:7c:b5:f2 RSSI: -40
[1]: SSID: TELUS4567 MAC: 72:1e:95:7c:b5:f0 RSSI: -41
[2]: SSID: TELUS9876-2.4G MAC: 70:f1:96:9b:f2:2 RSSI: -74
[3]: SSID: SpaceAce MAC: 0:1e:c0:3a:ed:58 RSSI: -80
[4]: SSID: TELUS6671 MAC: 20:76:0:75:d:b4 RSSI: -81
[5]: SSID: MonkeyMan MAC: 10:9f:a9:37:5d:13 RSSI: -90
scanning complete - filled result list (6).
LoRa_sendBuffer: sending 42 bytes
Time: 155393, Battery: 3330 mV Temp: 29 C
Sending mac tx uncnf port=2 0r=42 len=0... OK
Device state: SLEEP
Airtime added: 113 ms
TX power: 5 Datarate: 3
Successful transmission
A WiFi sniffer device is constructed with a STM32L152 MCU, ST WiFi module and the Semtech SX1272 LoRa transceiver. Firmware is developed and based on the open source Contiki operating system (GitHub link) and LoRaMac-Node reference implementation (GitHub link).
Through a collaboration of 3rd party infrastructure, network and service providers, an end-to-end location-based IoT application is demonstrated. With a MyDevices Cayenne app installed on your mobile device, you would have the ability to demonstrate a complete end-to-end, any-where-in-the-city, device-to-phone tracking solution. This is the bleeding edge of IoT.