Top 10 tips to become a Particle power user


#1

Originally published at: https://blog.particle.io/2019/05/31/top-10-tips-to-become-a-particle-power-user/

One of the most satisfying feelings in the hardware world is getting that first project to run. Whether something simple like blinking an LED (the “Hello World” or hardware apps) or bringing a new creation to life, there’s power in seeing something that you created, working.

And once you get that project working, you want to repeat that feeling, even as you add more features and functionality to your project. Having that first success feels great, but hardware can be hard, and it’s easy to get mired in the mud as our projects become more complex. With the right tools in your IoT toolbox, its possible to turn those moments into mere detours and get back on track quickly.

In this post, I’ll share my top ten tools for becoming a power user of the Particle platform. From tools to APIs to SDKs, each of these will help you build IoT apps faster, and keep those apps on track as you bring them closer to reality.

  1. Use Particle Workbench for firmware development
  2. Become a Particle Command-Line master
  3. Master Particle Primitives to get the Internet into your IoT devices
  4. Use the System Thread to run your firmware faster
  5. Understand system modes to control your connection to the Device Cloud
  6. Put your devices to sleep to save battery
  7. Explore the device event stream to see what your devices are saying
  8. Create products to manage device fleets
  9. Leverage webhooks and integrations to connect your devices anywhere
  10. Use the Particle SDKs for web and mobile apps

1. Use Particle Workbench for firmware development

One of my favorite parts of the Particle platform is the Web IDE, a full-featured, browser-based firmware authoring environment. When paired with Over-the-air (OTA) firmware updates, the Web IDE makes it possible to quickly create and flash apps built for Particle devices, all without needing to locally install a compiler toolchain, or device drivers.

However, if you’re building a serious prototype or starting to work on a production-class app, chances are you’re looking for a professional editor, with features like Intellisense, local compilation, and debugging. Particle Workbench provides all of these features, and more, and is powered by Visual Studio Code, the world’s most popular cross-platform code editor.

To get started with Particle Workbench, click here for installation instructions. The docs provide a great overview of the major features of Workbench. If you’re more of a visual learner, we also have an extended deep-dive on our YouTube channel.

2. Become a Particle Command-Line master

Being a power-user often means having the ability to quickly and easily access the features you need, when you want, and where you want. As developers, that “where” is often via a terminal or console session. Whether your primary development work is web, mobile, or embedded applications, chances are you have a set of command-line tools you use on a regular basis.

If you’re a terminal jockey, you’ll love the Particle CLI, a Node.js-based tool that’s supported on Windows, macOS, and Linux. It’s easy to install, and it provides quick access to nearly all the capabilities of the Particle platform. Need to get a list of your devices? Check out particle list. Need to create a webhook to pipe device data into another service? The particle webhook create is your ticket. Want to signal a device to have it “shout rainbows” at you? Just type and run particle nyan.

Nyan all the things!

To get started with the Particle CLI, visit the docs for installation and setup instructions. For a complete list of available commands, you can run the particle --help command, or visit the reference guide in the docs.

3. Master Particle Primitives to get the Internet into your IoT devices

Most connected, embedded apps need the cloud in order to do what they set out to do. Sensors need to publish their readings, or actuators need to be remotely monitored or controlled. No matter the specifics, cloud-enabling your project is about putting the I in the IoT. The Particle platform makes this connectivity simple through a number of “primitives,” or simple API calls for exposing sensor data, making device functionality cloud-callable, and passing messages between devices or to apps.

The Particle.variable() API makes it straightforward to take some local state on the device, like a temperature sensor reading, and allow other apps or devices to read that value. Similarly, Particle.function() allows you to define a piece of local firmware, for instance a method to turn on a motor, and allow other apps or devices to trigger that function. For a brief overview and demonstration of these primitives, check out the video below.

For passing messages between devices, or to web and mobile apps, the Particle.publish() and `Particle.subscribe()` API calls are two key ones to learn. For a brief overview and demonstration of these primitives, check out the video below.

4. Use the System Thread to run your firmware faster

By default, every Particle device shares a thread between the Particle Device OS firmware and the custom firmware you’ve written for the device. For many applications, this default configuration works fine. It ensures that your Particle primitives are properly registered, and that you’re connected to the Device Cloud in order to receive cloud-to-device communications.

There may be times, however, when you want to run your firmware in parallel to the Device OS thread, especially if you need to start running your local firmware to read from or control devices before the cloud connection is established. For these cases, Particle provides a simple configuration that you can include at the top of your application code:

SYSTEM_THREAD(ENABLED);

 

When flashed with this command, your user firmware and application loop will not be blocked by any network management or background processing done by the Device OS, so you can start sensing and actuating right away! What’s more, the Device OS knows how to manage threads separately and still ensure that Particle variables, functions and pub/sub work as-needed, so this opt-in change is a no brainer! To learn more about the System Thread, click here.

5. Understand system modes to control your connection to the Device Cloud

Similar to the System Thread, system modes provide a simple way for you to control how your device manages its connection to the cloud. Automatic mode is the default. In this mode, a connection to the Particle Device Cloud is established immediately, prior to your user code being executed (unless you’ve enabled the System Thread), and the Device OS manages communication to and from the Device Cloud in-between each execution of your loop() firmware function.

Semi-automatic mode doesn’t establish a connection to the cloud until you tell it to via the Particle.connect() command. You can do this at the end of your setup function, or another place appropriate to your app. In this mode, once you call connect() the Device OS takes over and handles future cloud interactions.

Finally, manual mode provides complete control over when and how your device connects to the cloud. As with semi-automatic, you establish a connection with Particle.connect(). In manual mode, however, you also must call Particle.process() to handle incoming messages and keep the cloud connection alive. With great power, comes great responsibility, as they say…

Each of these modes can be declared at the top of your application code:

SYSTEM_MODE(SEMI_AUTOMATIC);

To learn more about System Modes, click here.

6. Put your devices to sleep to save battery

If your project will need to run on battery power, you’ll want to understand and use sleep modes whenever possible. Sleep modes provide a simple API for powering down your devices, and specifying conditions for them to wake up and resume processing. You can put your devices into deep sleep, which shuts down networking interfaces and puts the core MCU into standby mode, or you can put the device into a stop mode that will wake-up after an interval of time, or when a voltage change is detected on a pin. For instance, if I wanted to configure my device to wake up on either a voltage change to D2 or after 30 seconds, I can do so with a single line of code:

System.sleep(D2, CHANGE, 30);

Then, when either condition is met, my device wakes back up, reconnects to the cloud, and continues processing.

Sleep modes are easy to use, and a great way to keep your devices running longer between charges. To learn more about Sleep Modes, click here.

7. Explore the device event stream to see what your devices are saying

Did you know that the Particle Console provides a single event stream across all of your connected devices? Whether you’re using the Particle.publish() API on one or 100 devices, the event stream is your mission control for viewing, filtering and even publishing events through the Particle Device Cloud.

A view of the Console events stream

To view your event stream, head over to console.particle.io/events, or click the console icon in the left navigation from anywhere in the Particle Console. To learn more about console event logs, click here.

8. Create products to manage device fleets

Products provide a number of fleet-wide management tools.

When taking a prototype to scale, one of your first concerns is how to go from managing a single device to a fleet of devices. This includes distributing firmware updates, to viewing device logs, managing billing, and more.

Thankfully, Particle provides a suite of product management capabilities in the Console, including the ability to manage SIM usage for cellular products, and intelligently releasing firmware to your fleet when a fix or update is needed. Everything you need to go from 1 to n with your Particle powered project is at your fingertips.

To learn more about using product features of the console, click here.

9. Leverage webhooks and integrations to connect your devices anywhere

IoT solutions often extend well beyond the embedded devices they are built around, and often we want to connect those solutions to other services for monitoring, insight, and more. To help you connect your apps to 3rd party services, Particle provides built-in support for Webhooks, which listen for events published by your devices, and trigger a web request to a URL you define. For example, do you want to post temperature sensor data into a Google Sheet using IFTTT? That’s easy with a webhook.

To get started with webhooks, you can follow along with this simple, online tutorial.

In addition to webhook support, Particle provides a number of pre-built integrations for Google Cloud Platform, Google Maps, Azure IoT Hub and InfluxData. These integrations and built on top of webhook functionality, and provide some extra functionality to make it easy to connect your Particle products to these services.

10. Use the Particle SDKs for web and mobile apps

In addition to connecting to the cloud, many IoT solutions also leverage web and mobile apps to provide insight and control to users, whether its building a web-based dashboard of sensor data, or a mobile app for controlling a device. No matter your use case, the Particle SDKs for building iOS, Android mobile apps, as well as a full-featured JavaScript API for Node.js and web-based applications are invaluable — here’s a great place to get started. They’re easy to install, configure, and they rely on the same Device Cloud API used by the Particle Console!

Become a Particle-powered power user today!

One of my favorite things about the Particle Platform is how easy it is to get started. With a device in hand and an open browser tab, you can code and flash a device in minutes, and get that great feeling of making something work. That easy onboarding has been part of the Particle DNA from the start.

As you make that transition from Particle beginner to power-user, you’ll find that low barrier to entry extends beyond the getting started experience, and into the tools and services you’ll find yourself using each and every day. This list of 10 tips to become a power user is just a start, and I encourage you to open a tab on the Particle Docs and explore the myriad ways that Particle can help you build powerful IoT apps today.