Particle Argon: Your Gateway to Simple Location Tracking Projects

Location tracking opens up a world of possibilities for IoT projects. Whether you want to keep tabs on valuable equipment, monitor the whereabouts of a pet, or get notified when an important package arrives, having real-time location data can enable some powerful applications.

Building a location tracking system from scratch though can seem daunting. Traditionally it required a deep understanding of GPS protocols, cellular triangulation, or deploying a fleet of Bluetooth beacons. Thankfully, with the rise of IoT platforms like Particle, much of that complexity can be abstracted away, making location-aware projects more accessible than ever.

In this tutorial, we‘ll walk through how to use the Particle Argon development board to build a simple location tracker using an off-the-shelf Bluetooth device. By the end, you‘ll have a system that can detect the presence of a tracking fob and send notifications when it arrives or leaves. Let‘s get started!

What You‘ll Need

Before we dive in, let‘s go over the key components our location tracker will use:

Particle Argon: The Argon is a powerful IoT development board that packs in a Wi-Fi module, mesh networking capabilities, and an ARM Cortex M4 processor. Most importantly for this project, it has an onboard Bluetooth 5 radio that we‘ll use to scan for Bluetooth devices. If you‘re new to Particle, I highly recommend picking up an Argon kit which includes the board, breadboard, and accessories.

Bluetooth Tracker: To keep things simple, we‘ll use an off-the-shelf Bluetooth tracking device like a Tile. These small fobs are designed to attach to keys, bags, and other important items you want to keep track of. They regularly broadcast Bluetooth signals that our Argon can detect. You can find them online or at many electronics retailers.

Particle Cloud: Particle‘s cloud platform will act as the "brains" of our location tracker. The Argon will publish Bluetooth signal data to the cloud where we can process it to determine if the tracker has arrived or left.

Pushover: Pushover is a simple API for sending push notifications to smartphones. We‘ll use it to alert us when the tracker is detected or goes out of range. A free trial account will work fine for testing.

Got all that? Great! Let‘s start building.

Step 1: Setting Up the Argon

First things first, we need to get the Argon connected to Particle Cloud. If this is your first time using an Argon, I recommend going through Particle‘s quick start guide which covers installing the Particle CLI, connecting over USB, and claiming your device to your Particle account.

With the Argon online, open up the Web IDE at build.particle.io. We‘ll start by creating a new app. I called mine ArgonTracker but feel free to use whatever name you like.

Step 2: Scanning for Bluetooth Devices

Now the real fun begins! Let‘s write some code to have the Argon continuously scan for Bluetooth devices.

In the setup() function, add the following to enable the Bluetooth module:

BLE.on();

Then in the loop(), we‘ll use the BLE.scan() function to look for advertising devices:

void loop() {
  BLE.scan(scanResultCallback, NULL);
}

The first argument is a callback function that will be triggered whenever a device is found. Let‘s define that now above the loop:

void scanResultCallback(const BleScanResult *scanResult, void *context) {
  Log.info("MAC: %02X:%02X:%02X:%02X:%02X:%02X | RSSI: %dBm", 
    scanResult->address[0], scanResult->address[1], scanResult->address[2], 
    scanResult->address[3], scanResult->address[4], scanResult->address[5], 
    scanResult->rssi);

  BLE.stopScanning();
}

This will print out the MAC address and signal strength (RSSI) of each device found, then stop the scan. We‘ll add more logic here later to filter for our tracking fob.

Go ahead and flash this code to your Argon and open up a serial monitor. You should see output like:

0000000047 [app] INFO: MAC: D7:E7:FE:0C:A5:C0 | RSSI: -87Bm
0000000049 [app] INFO: MAC: 4F:78:2E:C3:D2:E9 | RSSI: -92Bm

Those hex strings are the unique identifiers of the Bluetooth devices. The RSSI is a measure of signal strength in dBm, where more negative numbers indicate a weaker signal.

If you see a steady stream of devices, congrats! Everything is working so far. If no results are appearing, double check that you have Bluetooth devices nearby with their Bluetooth settings turned on.

Step 3: Identifying the Tracker

Among all the Bluetooth noise, we need to be able to uniquely identify the signal from our Tile tracker. Fortunately, Tile uses a custom UUID in its advertising data that we can filter on.

Flip your Tile tracker over and look for a 4 character code printed on the back. For example, mine is fe0c.

Back in the scanResultCallback function, let‘s add a check for that UUID:

void scanResultCallback(const BleScanResult *scanResult, void *context) {
  BleUuid trackerUUID("fe0c");

  if(scanResult->advertisingData().serviceUUID(trackerUUID)) {
    Log.info("Tracker found! RSSI: %dBm", scanResult->rssi);
  }

  BLE.stopScanning();
}

Here we create a BleUUID object with the code from the Tile tracker. The advertisingData() function returns all the service UUIDs being advertised by the device. If our tracker UUID is found, we print a message and the RSSI.

Flash this new code and you should start seeing the "Tracker found!" message when your Tile is near the Argon.

Step 4: Publishing to Particle Cloud

Now that we can detect the presence of the tracker, let‘s publish an event to Particle Cloud whenever it arrives or leaves.

First, we‘ll declare a global variable to keep track of the tracker state:

bool isTrackerPresent = false;

Then modify the scanResultCallback to set this variable and publish an event:

void scanResultCallback(const BleScanResult *scanResult, void *context) {
  BleUuid trackerUUID("fe0c");

  if(scanResult->advertisingData().serviceUUID(trackerUUID)) {
    if(!isTrackerPresent) {
      isTrackerPresent = true;
      Particle.publish("tracker", "arrived", PRIVATE);
      Log.info("Tracker arrived");
    }
  }
  else {
    if(isTrackerPresent) {
      isTrackerPresent = false;
      Particle.publish("tracker", "left", PRIVATE); 
      Log.info("Tracker left");
    }
  }

  BLE.stopScanning();
}

Now when the tracker first appears, we publish a "tracker" event with data set to "arrived". When it disappears, we publish "left". We also use the isTrackerPresent flag to avoid spamming the same event repeatedly.

Open up the Particle event console at console.particle.io/events and deploy this code. As you bring your tracker in and out of range of the Argon, you should see events come through like:

tracker
arrived
Ranger

tracker
left
Ranger

The PRIVATE flag means these events are only visible to your devices and not publicly. The Ranger text indicates which of your devices published the event.

Step 5: Setting Up Notifications

We‘re almost done! The final piece is triggering push notifications based on the events being published by the Argon.

For this we‘ll use Particle‘s integration with the Pushover API. If you don‘t have a Pushover account, head over to pushover.net and register for a free trial.

In the Particle console, click on Integrations in the left menu. Click New Integration and select Webhook.

Fill out the dialog as follows:

The {{{data}}} tag will be replaced by either "arrived" or "left" depending on the event. For bonus points, I‘m also passing the Argon‘s current latitude and longitude so the notification includes a maps link showing the tracker‘s last known location.

Click Create Webhook and you‘re all set! Whenever a tracker event occurs, you‘ll get an immediate push notification on your phone.

Futher Enhancements

We‘ve built a functional Bluetooth location tracker, but there‘s always room for improvement. Here are some ideas to take this project even further:

  • Add a small OLED screen to the Argon to display the tracker status without needing to check your phone.
  • Store the tracker‘s last known location in the Particle Cloud so you can access it from anywhere.
  • Expand the system to track multiple Tiles or other Bluetooth devices.
  • Use the Argon‘s onboard battery connector to make the whole device portable.

I‘d love to see what you come up with! Feel free to share your modifications (or totally new projects) with me via email or on Twitter at @jaredwolff.

Wrapping Up

In this tutorial, we covered:

  • Using Particle Argon to scan for Bluetooth devices
  • Filtering for a specific Tile tracker using its UUID
  • Publishing location events to Particle Cloud
  • Triggering smartphone notifications using the Pushover API

I hope this gives you a taste of how easy it can be to build location-aware projects using the Particle platform. Whether you‘re tracking tools on a construction site, monitoring the comings and goings of office equipment, or just making sure you don‘t lose track of your keys, the Argon is a powerful and flexible foundation to build on.

Let me know what other location tracking projects you‘d like to see, and happy building!

Similar Posts