To FSM or not to FSM (Finite State Machines discussion)

Continuing the discussion from Electron Carrier Board:

Let's talk about Finite State Machines (FSM's) here!

Some interesting reads:

FSM Particle library - ported from Arduino:

5 Likes

@gusgonnet and @peekay123

OK, thank you both of all the help on Finite State Machines, my plan is to start rewriting the software for my trail counters using this approach. My next project is to rewrite the software to enable solar power. I am using some of the ideas provided by @RWB and I am sure I will end up making a lot of mistakes (I mean learning a lot) in the process. I will start by creating a state diagram for what I want to get accomplished. The words that go with this diagram are:

  • The device is initialized and connects to the Particle service
  • If It fails in initialization or connection, it will reset
  • Once connected it goes to an idle state and waits for an event
  • It will take a “nap” if nothing happens for a timeout period waking once there is a hardware interrupt from the sensor
  • It will also, “sleep” while the park is closed waking only when the park reopens
  • When it wakes from either a nap or sleep, it will report using a Webhook
  • The webhook will need to be successfully received for it to go back to the idle state.

Here is what it looks like:

Now, I can start to rewrite and test my code for each state and build a main loop to handle the transitions. I will post progress as this seems like a general use case for many Electron projects. Comments and suggestions always welcome.

Thanks,

Chip

2 Likes

Hey Chip, I'd like to mention your observations on this hackster prj, would it be ok with you?
thanks

@gusgonnet

Sure, no problem. BTW, this device has performed very well over the past 30 days. Very happy

Chip

2 Likes

The Hackster project is live now:

thanks
Gustavo.

3 Likes