A bicycle alarm system and tracker utilizing The Things Network's LoRaWAN infrastructure.
Credits: Code from the following sources has been used:
-
https://www.thethingsnetwork.org/forum/t/best-practices-when-sending-gps-location-data-howto/1242/21
-
LoRaWAN Arduino Code from Thomas Telkamp and Matthijs Kooijman
You'll have to replace the NWKSKEY[16]
, APPSKEY[16]
and DEVADDR
values in the nRF52840 source code with values from the console on The Things Network (see below).
static const u1_t PROGMEM NWKSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u1_t PROGMEM APPSKEY[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static const u4_t DEVADDR = 0x00000000;
The following hardware is required for this project:
- Feather nRF52840 Express
- FeatherWing RFM95W (LoRaWAN module)
- u-blox PAM-7Q GPS
- Grove Shield for Feather
- Breadboard
- Grove - 4 pin Male Jumper to Grove 4 pin Conversion Cable
Build:
- Attach the FeatherWing to the Grove Shield
- Attach the nRF52840 ontop of the FeatherWing
- Place the GPS module on the breadboard
- Attach the Grove Cable to the UART Port on Grove Shield and ensure that the connection has the following mapping:
- GPS (TX) <-> Grove Shield (RX)
- GPS (RX) <-> Grove Shield (TX)
- GPS (VCC) <-> Grove Shield (VCC)
- GPS (GND) <-> Grove Shield (GND)
This is a proof of concept and does not come with an enclosure. Depending on the availability of a power source and environment that the tracker is used in, a suitable enclosure may be selected.
- Show the Location of the Bike on the Google Map
- Toggle between the 2 Views which represent Philipp's or Alejandro's Bike
- See when the last message came in
- See if the bike is moving
- See if Telegram Notifcations are enabled
- Track your own coordinate to see it on the map as well
- Vue.js Frontend Framework
- Websockets to communicate with our MQTT Broker
- Vuetify Vue.js Design Framework
- Google Maps js API
yarn install
yarn serve
yarn build
Our Gateway is a simple Raspberry Pi Zero with Node Red installed on it. It connecteed to the internet and could be anywhere... :-)
The MQTT Broker from thethingsnetwork is not accessable directly trough Websockets. We have found a workaround, but this is only recomended in a Test Envirenment. Since we planned a Node Red Integrating anyway, we created a MQTT Broker bridge in it.
For testing purposes we take the public broker from Mosquitto, which now subscribes to our topics from theThingsNetwork. The Open MQTT Broker from Mosquitto supports Websockets out of the boxx and we can access all topics directly within our Web-App.
In this Nodes we configure the Telegram Bot. We have 2 commands the user can send in to the Group Chat:
- /alarmOn -> turns on the notifications for the specific Bike of the User in Telegram
- /alarmOff -> turns off the notifications for the specific Bike of the User in Telegram
The Messages arrive in a group Chat where Philip and I are part of. The /alarmOn command gets filtered by Telegram Username, so it will be distictive. So everybody can turn on and off the notifications for their bike.
If notifications are turned on for the specific bike, and a new coordinate comes in. The user gets notified directly in the Telegram Chat with the Location of the bike.
-
Create a free The Things Network account
-
Setup an Application that uses
ABP
authentication and get theNetwork Session Key
,App Session Key
andDevice Address
for replacing values in the nRF52840 source code. -
In the The Things Network Console configure the following Payload Format decoder:
function Decoder(b, port) { var lat = (b[0] | b[1]<<8 | b[2]<<16 | (b[2] & 0x80 ? 0xFF<<24 : 0)) / 10000; var lng = (b[3] | b[4]<<8 | b[5]<<16 | (b[5] & 0x80 ? 0xFF<<24 : 0)) / 10000; return { location: { lat: lat, lng: lng } }; }
Credit: This decoder is from https://www.thethingsnetwork.org/forum/t/best-practices-when-sending-gps-location-data-howto/1242/21
The tracker does not acquire location data via GPS or transmit data via LoRaWAN until the accelerometer sensor registers movement. This allows for very little power consumption during standby and only transmitting location updates when necessary. The alarm can be enabled using the web application, which triggers Telegram notification when new location updates are bing received. Since, location updates are always sent, the web application cannot only be used to retrieve a stolen bicycle but it may also be used when one has forgotten where the bike has been parked.