Webhook demo

This is an interactive tutorial that shows how to use Particle.publish to send data from a Particle device to a cloud service by a webhook. You'd use a technique like this for sending sensor or location data from your Particle device to the Particle cloud and then to your servers via a webhook.

  • If you're interesting in controlling devices and the differences between publish and functions, see the function and publish demo.

In order to use this tutorial, you must be logged into your Particle account:

Cloud setup

In this section we'll set up a product, add your device, and create a webhook.

Select a product

You should typically start with a product. You'll eventually need one to scale, and it makes it easier to group devices.

This demo requires a product, and each product can only have a single device platform, so you must select that first.

Device platform:

You can find all of your sandbox products in the productsTab in the Particle console.

There is no charge for creating products in your free developer sandbox and there is no limit on the number of products, though there is a limit to the number of devices in the free plan.

Start demo

Starting the demo will start the webhook server and start monitoring events.

Add devices to product

Whenever you have a product, you must add devices to it. When you scale, you will typically add all of the devices in your order at once, as you will be emailed a list of the Device IDs in your order. In the basic and enterprise plans, just adding the Device ID to the product does not affect billing; billing only starts the first time the device connects to the Particle cloud.

For this demo, you can just select existing devices from your developer sandbox to use in this tutorial. If you do not have a device yet, you can skip this step and use the Test feature to show how the webhook works without a device.

Start Demo to add devices to your product.

You will normally use the Add Devices button in the devices tab in the console to do this in your real products.

Create a product webhook

Normally you'll create a webhook in your product from the console. Because the server URL changes every time you start the demo, the tutorial will just create it for you automatically.

Parameter Value
Event WebhookDemo01
URL
Method POST

You can open the webhook in the console once it has been created.

Start Demo to start up the webhook service, as the server URL changes each time you run the demo.

Tell me more about creating a webhook

Your device fleet

This control shows the status of devices in your product fleet. It's similar to the devices tab in your product in the console.

Once you've added a device to your product, it will show up here. Use the Flash link to flash the product firmware to your device.

Start Demo to see the devices in your product.

  • The online column shows a green checkbox if the device is online and connected to the Particle cloud.

  • The firmware column shows a green checkbox if the device has product firmware and has come online at least once. When you onboard your first device, you have to manually request the firmware be flashed to it. Click the Flash link to do this.

  • The development column checkbox shows if the device has the Mark as Development device flag set. You can also change the state using this checkbox. You normally should leave this turned off.

Product firmware setup


Start Demo to set up the product configuration.

Setting up product firmware involves several steps:

  • Compiling the firmware, typically using Particle Workbench.
  • Uploading to the console from the firmware tab of your product.
  • Flashing the firmware to at least one device manually.
  • Releasing the firmware as the default firmware for the product.

Once you've set the default firmware, and newly added device will automatically be flashed with this firmware when it connects to the cloud.

Test webhook

Start Demo to interact with it, then complete the steps to set up your webhook.

Tell me more about testing a webhook

Explainer

Once you start the demo and events start flowing, either by using the Test button above, or from a device, the section below will explain what is happening.

Start Demo to begin listening for events in your product.

Webhook server data

The table below is the decoded data that was received by the webhook server. This is the kind of data that you'd be able to use in a custom web or mobile app, but you'd probably use something fancier than just a table.

Start Demo to interact with it.

Tell me more about server data

Event log

This control shows the same information that is shown in the events tab in your product so you don't need to switch between multiple windows.

Start Demo to begin listening for events in your product.

Device firmware

   

     

Tell me more the device firmware

Open in Workbench

The recommended development environment for Particle firmware is Particle Workbench. To open this project in Workbench:

  • Use the Download Full Project (*.zip) option in Device Firmware, above.
  • Extract the zip file on your computer.
  • Open Visual Studio Code
  • Use the File - Open option to open the directory you just extracted. Make sure you open the directory, not a single file in it.

Most operations are in the command palette (Ctrl-Shift-P on Windows and Linux, Command-Shift-P on Mac). Some useful commands:

  • Particle: Login Log into your Particle account.
  • Particle: Configure Project for Device Set the type of device and the version of Device OS you want to use.
  • Particle: Cloud flash Compile the project and flash it to a device OTA.
  • Particle: Cloud compile Compile the project and download the .bin file.

Device logs

If you have your Particle device connected by USB to your computer (Windows, Linux, Mac, or Chromebook), and you are using the Chrome web browser, you can monitor your device's USB serial debug log from this interactive control. You can also use particle serial monitor from the Particle CLI if you prefer. Both are optional, but are good for troubleshooting.

           

          

More things to try

Expand your device fleet

Use the Add Devices button in the devices tab in the console to add another device to your project.

You can monitor both devices from this page!

Upload product firmware

Use Workbench to build a firmware binary, then upload the binary to firmware tab in your product in the console.

You can use this to flash all devices in your product fleet with new firmware in just a few clicks.

Also, once you set default product firmware and add a device, it will be immediately flashed with your product firmware if online, or automatically when it next comes online.

Add more data fields

Try adding additional data fields to your product firmware using the JSONWriter. You can add integer, floating point, and string variables easily. These will automatically be included via the webhook and will show up in the data table.

Add a real sensor

Instead of just using random data, try connecting a real temperature sensor and hooking it up into the readTemperatureC() function.

Clean up

If you are done using this tutorial, you can clean up the things that were created during this tutorial.

You must Start Demo to retrieve product information before it can be cleaned up.

You should flash Tinker using the option above or turn the device off after completing the tutorial so it doesn't continue to publish events, which will consume data operations even if you're not actively using the tutorial.