The production of ultra-low-cost anti-theft system based on Blues wireless note card
Source: InternetPublisher:拿铁三分糖 Keywords: Anti-theft system SMS Updated: 2024/12/13
Sound a (silent) alarm with the Blues Wireless Notecard: Theft Alarm and Asset Recovery.
Project Background
When people think of asset trackers, they usually think about tracking things that are supposed to move: planes, trains, and cars. What we don’t often think about is tracking things that are stationary and not easily moved: statues, environmental monitoring equipment, RVs or boats stored off-season, and other valuables that are unfortunately lost or stolen.
Recently at work someone shared a story about beekeepers using tracking devices to protect their hives (honey is literally liquid gold!) and suggested that Blues’ device would be a great low-cost hive tracking solution, which got my mind spinning.
Blues' mission is to make IoT connectivity simple. Does your IoT device have a stable Wi-Fi connection - or is it located in a beehive somewhere in a meadow? Blues provides low-power note cards that connect to a secure cloud (Notehub) via prepaid cellular data and pumps your device's data (in JSON format) to the cloud for easy access.
The best part is that once the data is in the Notehub cloud, it can be routed again to third-party cloud platforms, web applications, low-code dashboards, or even messaging platforms like Twilio.
Using Twilio, we can send SMS alerts when a device that is supposed to be stationary starts moving, including details like last known location coordinates. Sounds like a pretty perfect solution to me.
Today I’ll show you how to build an anti-theft device for under $100 that will use a cellular module to send its location data to the cloud and trigger an SMS alert when motion is detected, allowing you to recover your assets faster.
Hardware Components
Blues Wireless Note Card (Cellular) × 1
Blues Wireless Notepad-A×1
Adafruit Lithium Ion Polymer Battery - 3.7v 2500mAh x 1
USB-A to Micro-USB data cable × 1
Software Applications and Online Services
BluesWirelessNotehub.io
SMSMessagingAPI
Twilio SMS Messaging API
JSONataExerciser
Webhook.site
Assembling the anti-theft device
Since my project is tracking objects that shouldn't be moving but are moving anyway (reverse asset tracking if you will), things like reliable internet connectivity when the objects are moving and long-lasting battery life when they aren't are important considerations.
Fortunately, Blues Wireless has the hardware to solve both of these problems. The Blues Wireless Notecard offers prepaid global cellular access, including 500MB of data and 10 years of service. The model I chose works with both LTE-M and NB-IoT protocols, and it uses very low power at idle, only about 8uA.
In addition to my Notecard, I also used the Blues Wireless Notecarrier AL, which is a companion prototyping board for the Notecard that has onboard cellular and GPS antennas.
I specifically chose the NotecarrierAL version because it has a JST connector for a LiPo battery, but there are also versions that use AA batteries, and all Notecarrier boards also have a micro USB connector that can power the device and provide a USB interface for note cards.
The final piece of this puzzle is the power supply. As I mentioned, I chose the NotecarrierAL, which has a JST connector for a LiPo battery, so I bought an Adafruit Li-Ion Polymer Battery - 3.7v 2500mAh to power the whole shebang.
Now to put it all together: screw the Notecard into the Notecarrier, connect the cellular and GPS antennas and connectors on the board to the Notecard, and insert the LiPo battery into the JST connector port labeled "LiPo".
With the anti-theft device hardware assembled, it’s time to set up our cloud and Twilio configuration.
Note: If you would like more detailed instructions on assembling a tracker, please check out the Getting Started section of our Developer Experience site.
Set up a Notehub project for the tracker to report to
Before we can set up the Notecard itself using march commands, we need to create a new cloud project in Notehub.io to direct the Notecard’s data to.
Since Notecard is a device-to-cloud data pump that does not exist on the public internet (making it a very secure device), a proxy is needed for syncing data: Notehub.
Notehub is a thin cloud service that securely accepts data from your cellular notecard (over the public Internet, using a private VPN tunnel) and then instantly routes the data to the cloud provider of your choice (be it AWS, Azure, Google Cloud, or any IoT optimized service like Ubidots, Datacake, Losant, etc.).
1. If you don't already have one, create an account with Notehub now. The first 5,000 routing events per month are free (routing events = data transfers from Notehub to a cloud endpoint of your choice). This should be far more than you need for this anti-theft device (hopefully).
2. After registration, click the "Create Project" button in the upper right corner of the Notehub interface and fill in the project details.
Copy the project UID after creating the new project - we will need it when configuring Notecarrier itself.
Create a free TwilioStarter account
Another thing you’ll need to set up is a free starter account with Twilio, as it’s Twilio’s API that we’ll be leveraging to send SMS alerts.
When I set up my test account I followed the BluesTwilio documentation and I recommend starting there.
NOTE: If you click on the Twilio link in the "Prerequisites" section of the document, you will receive some additional Twilio onboarding credits through the BluesWireless referral link.
Once your account is set up, make sure to verify your caller ID (probably your own mobile number for testing purposes) and assign a Twilio phone number to your account (this is the number that will send SMS notifications later).
Here's how I learned from the dashboard that my account had a Twilio phone number associated with it.
Now let's set up our Notecard. After the Notecard is recording the motion data, we will reconnect Notehub and Twilio.
Programming Asset Tracking Notecards
If you haven't configured notecards before, don't worry, Blues aims to make this experience easy with simple JSON commands.
While you can download the full NotecardCLI to your local machine to interact with Notecard, I tend to use the web-based NotecardCLI built into our Developer Experience site. It’s easier in my opinion.
All you need is a micro USB to USB-A converter cable to plug into your laptop and start interacting with your notecards.
Once connected to the notecard, issue the following set of commands to it.
1. Reset your note card to factory settings.
It's always good to start a new project from scratch.
{"req":"card.restore","delete":true} |
2. Attach the tracker to the Notehub project, set its mode and sync time
{ "req":"hub.set", "product":"com.blues.paige:anti_theft_tracker", "mode":"periodic", "outbound":1440, "inbound":1440 } |
This setting will only periodically send any unsynced information to Notehub every 1440 minutes (once a day), and it will also always sync every 1440 minutes to process any new notes and environment variables from Notehub. outboundinbound
Since we don't expect much in the way of changing environment variables or general notecard activity, long intervals between syncs are fine. This will also help preserve battery life, as the most power-hungry activity this tracker will experience is acquiring a GPS location and transmitting that data to the Notehub.
3. Set the position detection mode and frequency of Notecard
{"req":"card.location.mode","mode":"periodic","seconds":60} |
In periodic mode, the Notecard's GPS module activates to take readings only when the Notecard detects motion via its onboard accelerometer. Telling the Notecard to take new GPS readings every 60 seconds drains battery more than more than a 5-minute interval, but if something is being stolen, I'd prefer to be reminded of its current whereabouts more frequently.
4. Start tracking, set a check-in heartbeat every day, and synchronize new notes to Notehub as soon as possible
{ "req":"card.location.track", "start":true, "heartbeat":true, "hours":24, "sync": true } |
card.location.track will store tracking data for the location tag, such as speed, bearing and distance, in the Notefile which will be sent to Notehub immediately after creation - this is what the "sync" true command at the end of the line does. As soon as a new event is created on a notecard it will be sent directly to Notehub without waiting until the next regularly scheduled outbound interval.
Again, this is more power hungry, but for this type of tracker we want events as close to real time as possible to increase the chances of asset recovery.
The default file is _track.qo, but you can specify your own file name using the file field.
heartbeat and hours tell Notecard to create an entry at the defined interval, regardless of motion. This is just a gut check that Notecard is still working.
Note: If you want to learn more about configuring asset trackers, check out all the information about them on the Blues Developer Experience site.
Generate some test trace events in Notehub
Now take your Notecard with you on a walk or drive and see the type of data it generates and sends to Notehub.
In your Notehub project, click the Events tab and filter in the input_track.qo to see the list of track events that your Notecard should generate.
As you can see by looking closely at the image, my notepad reports a mix of heartbeat (no motion) data and motion detection data.
However, by putting a pin in there, we will find a way to classify this data and prevent false positives from being sent to Twilio.
Send motion alerts with location data via Twilio
OK! Now it’s time to start sending some of these _track.qo events to Twilio.
This was probably the part of the project that took me the longest, mostly because I was getting familiar with the JSONata syntax - but I'm getting ahead of myself.
Let's walk through this section step by step.
Note: If you want to skip the JSONata explanation and go directly to Step 2B - this is the final version of this JSONata function.
1. Create a new Twilio route in Notehub and find the _track.qo file
The Twilio Getting Started guide on the BluesWireless Developer Experience site does an excellent job of showing exactly how to set up a new route from Notehub to Twilio, follow it until step eight where the selected note file is defined as being tagged twilio.qo - we won't, instead our project will be looking for a _track.qo file like in my screenshot.
2. Paste this JSONata code into the conversion data section of the Twilio route
If you've read most of the instructions in the Twilio Getting Started Guide, you've probably already seen the part about converting the raw Notecard payload through JSONata before sending it to Twilio.
JSONata, if you're not familiar with it (I wasn't), is a lightweight query and transformation language for JSON data. The syntax takes some getting used to, but once you have it working, it's pretty cool.
Another thing I learned about Notehub is that any notefile payload can be run through a JSONata transform function to remove most of the JSON we don’t care about, routing only the important bits to the next place to bind the information (Twilio, in our case).
So here is version 1 of JSONata to paste into the Transform Data section in Notehub:
( $from := "+190354XXXX"; $to := "+1404641XXXX"; $body := function(){ ( $join([ "Alert! ", sn ? sn : device, " is on the move!" , " Last spotted at: ", $string($round(where_lat, 6)), ",", $string($round(where_lon, 6)), " around ", $fromMillis(when * 1000, "[M01]/[D01]/[Y0001] [h#1]:[m01][P]", "-0500"), " EST." ]) ) }; "&Body =" & $body() & "&From=" & $from & "&To=" & $to & "&"; ) |
In this expression, we define three variables:
$from - the Twilio phone number,
$to - a test phone number (probably your phone number),
and - a JSONata function that concatenates the strings together, letting us know which Notecard is moving (defined by the Notecard's value - its sequence number, falling back to its ID if that value doesn't exist), its last known latitude ( ) and longitude ( ), and the last reported time ( ). $bodysndevicewhere_latwhere_lonwhen
Each variable or function is separated from the next by a semicolon, and to string together multiple variables and functions like in this example, wrap them all in parentheses.
In addition to the basic information extracted from the original _track.qoNotefile, we also use built-in functions such as $string, $round$fromMillis
Finally, on the last line where "&Body=" is defined, we call our newly created $body() function to get the string we need to send to Twilio to get their message, and add the $from and $to variables we also defined so that Twilio knows who the text should be from and who should receive it.
2A. Filter out heartbeat events_track.qo$doNotRoute()
That's a good start, but what about those heartbeat_track.qo events that also come into Notehub as events? Using the JSONata above, these will be sent to Twilio once a day and send a false positive SMS alert indicating that the Notecard is moving when in fact it is not.
Enter : A custom Blues JSONata command that will conditionally route the event outside of Notehub, which is exactly what we need. $doNotRoute()
If you examine the plain JSON_track.qo of an event with motion vs. the JSON of an event with only heartbeats detected, you'll notice that the event with motion has two properties that heartbeats don't have: motion and seconds.
Notecard events with motion data_track.qo
{ // some event specific data up here "device": "dev:86447XXXXXXXX", "sn": "Notey McNotecard", "product": "product:com.blues.paige:anti_theft_tracker", "routed": 1646683287, "req": "note.add", "when": 1646683261, "file": "_track.qo", "body": { "hdop": 1, "motion": 4, "seconds": 74, "temperature": 29.125, "time": 1646683260, "voltage": 4.21875 }, "best_location_type ": "gps", // a bunch of extra location JSON data here } |
Inside body there are motion and seconds - this means the notepad is running.
Notecard event without motion data_track.qo
{ // some event specific data up here "device": "dev:86447XXXXXXXX", "sn": "Notey McNotecard", "product": "product:com.blues.paige:anti_theft_tracker", "routed": 1646600372, "req": "note.add", "when": 1646600347, "file": "_track.qo", "updates": 1, "body": { "hdop": 1, "status": "heartbeat", "temperature": 25.5, "time": 1646341009, "voltage": 4.2734375 }, "best_location_type": "gps", // a bunch of extra location JSON data here } |
There is no motion and seconds in the body of this note card, plus its status is "heartbeat": no motion.
We can use one (or both) attributes to conditionally route a value to Twilio. Game changer.
Replace the original JSONata with this newly updated version 2 code:
( $from := "+190354XXXX"; $to := "+1404641XXXX"; $body := function(){ ( $join([ "Alert! ", sn ? sn : device, " is on the move!" , " Last spotted at: ", $string($round(where_lat, 6)), ",", $string($round(where_lon, 6)), " around ", $fromMillis(when * 1000, "[M01]/[D01]/[Y0001] [h#1]:[m01][P]", "-0500"), " EST." ]) ) }; $result := ($exists(body.motion)) ? "&Body=" & $body() & "&From=" & $from & "&To=" & $to & "&" : $doNotRoute(); ) |
The changes are in the last few lines of the "&Body=... construct.
The converted Notefile is not sent anyway, now a new variable called $result$existsbody.motion.$body()$doNotRoute() is declared and using the JSONata method we check if the original payload has a value if it does then the function runs and the data is sent to Twilio, if it doesn't it is called and the Note is not sent.
For your convenience, add a Google Maps link
OK, that should stop the false positives from coming through, but there are further improvements I'd like to make to this message. I don't know about you, but if I had something stolen, seeing a printout of the GPS coordinates wouldn't be particularly useful in the moment.
I want to be able to click on a link in the SMS and see those coordinates displayed on a map.
Contrary to what you might think, there is no generally accepted way to frame GPS coordinates in a text message so that the iPhone or Android messaging services will recognize that they are coordinates (like they do for phone numbers and addresses) and automatically hyperlink them to open the Maps app on the phone.
Instead, we have to do it ourselves. So my workaround is to provide a Google Maps hyperlink at the end of the message, which the user can choose to click or not (I assume that Google Maps is an almost universally used app regardless of phone OS, and if the user doesn't want to use it, they can just copy the GPS string from the main message body and paste it into the map app of their choice).
So one last time, replace your JSONata text with this version 3 code:
( $from := "+190354XXXX"; $to := "+1404641XXXX"; $body := function(){ ( $join([ "Alert! ", sn ? sn : device, " is on the move!" , " Last spotted at: ", $string($round(where_lat, 6)), ",", $string($round(where_lon, 6)), " around ", $fromMillis(when * 1000, "[M01]/[D01]/[Y0001] [h#1]:[m01][P]", "-0500"), " EST.", " Google maps link: http ://maps.google.com/?q=", $string(where_lat), ",", $string(where_lon) ]) ) }; $result := ($exists(body.motion)) ? "&Body=" & $body() & "&From=" & $from & "&To=" & $to & "&" : $doNotRoute(); ) |
This version modifies the end of the $body function to add an extra line that feeds the latitude and longitude coordinates into the Google Maps URL so that it can be clicked from the SMS.
Here is what the final JSONata expression looks like in the Twilio Notehub route.
Now click on the ‘Apply Changes’ button to save the route details.
Time to test this tracker!
alarm!
- Design of a drone wildlife counting system using FOMO object detection algorithm
- Design a BLE thermos cup using M5Stack
- DIY an indoor and outdoor webcam
- How to Use the Radio to Record Phone Calls Automatically
- Analysis of the circuit principle of ZX5-630 welding machine
- A simple memory reader/writer
- Electronic fly killer
- A novel resonance demonstration device
- How to use RFID to create an automatic roll call attendance system
- Discrete component laser driver circuit
- How does an optocoupler work? Introduction to the working principle and function of optocoupler
- 8050 transistor pin diagram and functions
- What is the circuit diagram of a TV power supply and how to repair it?
- Analyze common refrigerator control circuit diagrams and easily understand the working principle of refrigerators
- Hemisphere induction cooker circuit diagram, what you want is here
- Circuit design of mobile phone anti-theft alarm system using C8051F330 - alarm circuit diagram | alarm circuit diagram
- Humidity controller circuit design using NAND gate CD4011-humidity sensitive circuit
- Electronic sound-imitating mouse repellent circuit design - consumer electronics circuit diagram
- Three-digit display capacitance test meter circuit module design - photoelectric display circuit
- Advertising lantern production circuit design - signal processing electronic circuit diagram