Tips and tricks Wiki

Table of contents

Firmware tricks

Webhook tricks

This is a list created by the community. Some will remember the Awesome Particle list


Firmware tricks

1. Always enable the SYSTEM_THREAD

You almost never ever want to run your code without this statement in it:

SYSTEM_THREAD(ENABLED);

Still on the fence? Read this post.

2. Always include a reset cloud function

In case you want the device to pick up a certain firmware, and you forget to check the Flash now box, you can always reset the device and it will upgrade immediatly after resetting.


This tip becomes relevant when you are writing firmware for a product.

3. Delay running your code at setup

When you are developing code and OTA flashing a remote device, you may want to include a delay() long enough that will give you the chance to flash another version of your firmware.
This comes handy when you made a mistake in the code, and initiates a cyclic reset. This delay can help you regain control of your device.
Of course, never make a mistake in the first place.

4. Enter safe mode in case of PANIC

This is a safe alternative to the previous tip:

void setup() {
   System.enableFeature(FEATURE_RESET_INFO);
   if (System.resetReason() == RESET_REASON_PANIC) {
       System.enterSafeMode();
   }
}

Docs are here. Why not protect yourself?

5. Use Finite State Machines (FSMs)

You want to code with FSMs. Finite state machines docs are here.
Anyway, you are already using one if you have variables called isOn or status.

6. Use coding patterns

One very useful is the Singleton pattern. It can help you organize your code and increase the maintanability.
Your future self will thank you.

7. Use an out of memory handler

Unless you are using a Photon 2 (with so much memory), you might want to watch out for when your code run out of memory and reset.
Check it out here.

8. write next tip here


Webhook tricks

1. Use pipedream to test your webhooks

If you want to know EXACTLY what a webhook is sending, you can create a webhook/receiving end on https://pipedream.com/ (for free).

2. write next tip here


This post is a wiki, please edit it if you like.

Wiki posts do not support concurrent editions, so be quick since last save wins.
If your user does not have the required trust level, post your tip below.

4 Likes