Nature is the most beautiful thing on the Earth. As a parent of young kids and pets we should let them explore the nature. But often we don't feel safe. We fear if they are lost in the woods or if they fell while riding bikes on a remote trail. We should not worry if kids fall from bike but we should worry if they are insured and left unnoticed. These injuries can be fatal if treatment is delayed.
Does below picture look familiar to you? I see them every week on different social media that someone's pet went missing, lost in the woods or ran away from backyard.
These furry cuties are curious, keen to explore unknowns and often lost in the woods. They can't find the way back home.
We are living in a world surrounded by many smart IoT devices. GPS tracker is one of them which can solve this modern day's problem. There are some products already in the market to track your pets or GPS trackers to track your kids with some critical limitations
Limitation of today's tracking devices- [Low Range] Most of the pet trackers reports location via bluetooth or wifi which works within few yards. If your pet is away from your yard, those devices can't track your pet's location anymore.
- [Expensive] There are few GPS trackers which uses GSM ( SIM card ) to send coordinates. These devices have long range but they are expensive. You need to subscribe to monthly plans which are often more than $10/mo
- [Geo Fencing] Most of the GPS tracker are very trivial. They only track the location and show on the map on your smart phone app. But often we feel the need to setup virtual fence and get notified if our kids or furry friends go beyond the fence.
- [Shock Collars] Some people use shock collars and create physical boundaries for pets using wires come with the product. Collar gives sock to our pets whenever they cross the boundary. In my opinion this is so inhumane ! If owners had a better choice, I am sure they will say NO to the shock collars without thinking twice.
VFence is my solution to all of the above limitations along with GPS tracking and fall detection.
VFence is GPS tracking device backed by Helium LongFi network ( Long Range ) with an accompanying mobile app. I built 2 devices - one to track kids and one to track pets.
Features of VFence- GPS Location - Of course basic is covered. Like other GPS trackers these devices will send coordinates to your app real time. You will visualize them on map as below picture.
- Geo Fencing - Forget about those physical wires and setting up fence for your pets. You create it virtually on VFence app and whenever your kid or pet cross the fence you will get notified. Not only that, pet tracker will vibrate to let your pet know she is doing naughty! And for your kids, it will turn on RED light indicating she has crossed the fence.
- Fall Detection - Bike tracker has in-built 6 axis accelerometer which can detect the angle of a device and determine if it has fallen. If any fall is detected and device does not regain position in 5 minutes, a push notification and SMS is sent to the phone. If the device does not regain position in 10 minutes it sends a voice call to the phone.
- Analytics - When we have all the sensor data why not plot them on some graph and help parents visualize of the information more efficiently?
- LowCost - Yes, primary goal of this devices are to keep the monthly cost as low as possible. Mobile carriers charge us at least $5/mo for 512MB data. After adding operational cost etc, customers pay at least $10/mo for each devices. So what's the alternate without compromising coverage area? Yes, the answer is Helium.
Helium the world's first peer-to-peer wireless network that provides a secure and cost-effective way for low-power Internet of Things devices to send data to and from the Internet. The network enables companies to focus on applications and use cases, not worry about cellular plans for devices or managing network infrastructure.
Helium LongFi combines the LoRaWAN wireless protocol with Helium Blockchain so any LoRaWAN device can transfer data on the Helium Network.
LongFi delivers roaming capabilities and supports micropayment transactions so customers only pay based on network usage without needing to deploy gateways or network servers.
So what's the cost?
To send GPS coordinates every minute would cost you only 43centsper month! Yes, only 43 cents compared to > $5 using GSM.
Check it out yourself https://www.helium.com/business
DemoThough all the screen shots I provided in this article are from running app and real 3d printed devices but still no Hackster project is complete without a working demo video :)
Architecture DiagramTo keep the cost further down, I designed entire system on server less cloud computing. There is no need to run and pay for servers 24x7 where there is a choice to pay by usage. We can dynamically scale up or scale down the infrastructure as needed. You don't need to provision low or high when you are unsure about the load your system would receive.
Talking about Serverless cloud computing, AWS is my first choice for many reasons [ Not going to talk about AWS Awesomeness here :) but would talk about AWS resources I have utilized ]
Here is the tech stack with their roles in above diagram
Swift - VFence mobile app is written in Swift
Amplify - This is the SDK used to connect various AWS resources from swift app
Cognito - This is a server less solution for user authentication. New user sign up, sign in, user session tracking, password recovery, MFA, OTP - everything is handled by AWS Cognito
PinPoint - AWS Pinpoint is used to send push notification, SMS and Voice message.
Amazon MQ/IoT Core - Another bliss! No need to deploy your own MQTT server and pay large bills. Amazon MQ is a server less MQTT server. You pay by usage like any other server less resources.
DynamoDB - All data is stored in NoSQL DynamoDB. This is highly scalable server less datastore.
API Gateway + Lambda - This is the meat of your backend. Instead of deploying microservice ( or Monolith, don't be ashamed :) ) to EC2 containers, I deployed it to lambda and integrated with API Gateway to expose REST endpoints.
Now as you understood the architecture, let's take a deep dive into Helium. By now probably you have realized that the backbone of entire architecture is built on top of 2 pillars - AWS and Helium. I have explained AWS part of it above briefly.
Deep dive into HeliumHelium is based on LoRaWan protocol which naturally provides Long Range (LoRa) coverage compared to Wifi or Bluetooth.
Above is a high level architecture diagram of helium network. Each devices ( known as Nodes ) connect to a nearest helium hotspot to send data packets (known as UPLINK) to helium network.
Once data is received by the network, it sends the data to integration endpoints ( called channels ) such as AWS IoT, MQTT, Cayenne, HTTP, Cargo.
On the other hand, if there is any data sent to channels for Nodes, it's delegated to the nearest hotspots and transmitted to the end device ( known as DOWNLINK ). Any LoRa compatible devices can communicate with Helium network as long as there is a hotspot within few miles.
The device comes with a QR code which has encrypted EUI ( unique device ID ). When you register a device through VFence app by scanning the QR code, a new device is created in helium through API. Once you turn on the device after registration, it will connect to helium network though nearest hotspot and start sending UPLINK packets.
If you are following so far, you have realized helium hotspot is basically the gateway your devices need to send UPLINK packets. Hotspots are are providing network coverage. You can purchase a hotspot from helium storer [buy] or build your own DIY hotspot and participate in the network. By providing coverage you can earn helium crypto tokens (HTN). At the time of creating this project DIY hotspots don't participate in PoC ( Proof of Coverage), as a result don't earn any HTN but this is in helium's roadmap to bring DIY hotspots in the chain.
I have built my own hotspot running on Raspberry Pi 4 using RAK2245 HAT.
Building your hotspot is super simple. You can either follow the official helium document or follow my github tutorial below. I am using Balena Cloud which is free up to 10 devices. Using my repo you can setup your gateway within few minutes provided you are all the softwares and hardwares listed there.
https://github.com/just4give/helium-dyi-hotspot-balena-pi4
AntennaThe antenna comes with your RAK2245 is OK but not great. If you want to provide better coverage and eventually earn more tokens you should consider upgrading your antenna. I have purchased Altelix 900 MHz 5dBi Gain LoRa Omni Antenna but have not tested the coverage yet. Some folks already tested and confirmed it provides better coverage and their earnings boosted up. You need to purchase some more connectors as RAK2245 is iPex based. I have purchased iPex to SMA Female and SMA Male to N-Type Female.
For the trackers or anything which needs to send UPLINK packets to helium network must be LoRa compatible. When you are choosing your device make sure to buy one with right frequency. Each country has a designated frequency range, for example US is 915 MHz, EU is 868 MHz.
I have tried few LoRa devices such as CubeCell, CubeCell GPS, Wireless Stick Lite, TTGO. Finally decided to go with CubeCell GPS because of the build-in GPS module, OLED display and battery connector.
Checkout this website for Arduino IDE setup -> https://heltec.org/project/htcc-ab02s/
There are two programs - one for Bike and one for Pet. You will find them in the code section. Select the right board and other parameters as below screen shot and upload the program.
Data Encoding and Decoding
When you are working with LoRa devices, data encoding and decoding is a very important part of the system. You need to send data as byte array. In my program I am creating a JSON object and converting JSON to byte array using messagepack. I have used ArduinoJSON library for create JSON object.
Now if you notice helium debug console, you will notice payload data is coming as base64 encoded string such as below
g6FswKF0wKFzwA==
This represent a JSON object as below but you need to decode it to get that JSON.
{ l: 41.2511, t: -72.6783, s: 1 }
I am using AWS IoT integration, so base64 encoded string is passed to AWS IoT topic which triggers a lambda function. Inside lambda, I am decoding encoded string to get the JSON object.
exports.handler = async (event) => {
let payloadJson = decode(Buffer.from(event.payload, 'base64'));
decode function is written inside msgpack.js file.
Device Registration through QR CodeI feel the pain when it comes to register a device. Do this, do that and then do that..blah blah blah... I kept it simple. Just scan the QR code comes with your device, put a friendly name of your device. That's it.
When user taps "Add" button, it calls VFence backend API with device EUI. VFence backend API calls helium API to register the device with helium and integrate with AWS IoT channel.
app.post('/device', async function(req, res) {
// Add your code here
let name = "bike-tracker";
let data = {
"name":name,
"app_eui":HELIUM_APP_EUI,
"app_key":HELIUM_APP_KEY,
"dev_eui":req.body.deviceId
}
let r = await axios({method:'POST',url: HELIUM_HOST+"/devices", headers:{'key': HELIUM_KEY}, data: data});
let uuid = r.data.id;
let username = req.apiGateway.event.requestContext.authorizer.claims['cognito:username'];
r = await axios({method:'POST',url: HELIUM_HOST+"/devices/"+uuid+"/labels", headers:{'key': HELIUM_KEY}, data: {label:DEVICE_LABEL }});
let item = {
uuid: uuid,
username: username,
dName: req.body.dName,
deviceId :req.body.deviceId,
lat:0.0,
lon:0.0,
dType: req.body.dType
}
var params = {
TableName : 'bikemate_device',
Item: item
};
let device = await dynamodb.put(params).promise()
res.json(item)
});
app.post('/device/*', function(req, res) {
// Add your code here
res.json({success: 'post call succeed!', url: req.url, body: req.body})
});
- Bike Tracker
- PetTracker
This is fully working dog collar. It's equipped with rechargeable LiPo battery, charging module and vibration device. Case is 3D printed.
Schematichttps://resource.heltec.cn/download/CubeCell/HTCC-AB02S/HTCC-AB02S_PinoutDiagram.pdf
Circuit for the bike tracker is very simple. The board has in-built GPS module, OLED module and battery connector. Only additional sensor you need to solder is MPU6050. Connect MPU as below
MPU GND -> Board GND ( 2nd pin on right rail )
MPU VCC -> Board VDD ( 3rd pin on right rail )
MPU SLC -> Board SLC ( 9th pin on left rail )
MPU SDA -> Board SDA ( 10th pin on left rail )
I also connected TP4045 charging module and a switch.
Comments