So, implementing the Node Red flows for this project is completed! See the flows.json file for importing them yourself. Here's the dashboard!
Keep reading for how it's all done...
First, some prerequisites: You have to have Node Red installed and some kind of MQTT broker (I use Mosquitto). You'll also need the "node-red-dashboard" and "node-red-contrib-ui-led" packages for Node Red.
Fair warning, you should probably be fairly familiar with Node Red before diving into how this all works. If you're not: Good luck! Here be dragons!
This project is comprised of four separate flows that join together in this one magical tiny flow: The MQTT sender.
So tiny! It takes in all the stuff from every other flow that must be sent via MQTT to the ESP32 in the Dryer. From now on, I'll be referring to this ESP32 as just the Dryer.
The second flow is shown here. This one is responsible for starting up and initializing the Dryer.
We also create a Dashboard notification to notify the user when the Dryer initially connects.
Next, we have the Heartbeat processing flow:
This is a bit more complicated, but here's how it works:
- Every 20 seconds, the Heartbeat Injector fires.
- This sends a "hash" (a random number) to the Dryer via MQTT, sets a "Heartbeat Response" value to false, and starts a delay timer.
- The delay timer runs for 250ms and once it expires, uses the "Heartbeat Response" value to change a Connection Status LED on the dashboard.
- If the Dryer responds to the Heartbeat request, it sets the "Heartbeat Response" value to true.
Effectively, this creates a setup where we ask for a response, wait 250ms and if we don't get a response, we're pretty sure the device isn't connected. We also force the dashboard LED to show that the device is connected when it initially connects.
The next flow is for the various switch controls on the dashboard.
This one's also quite complicated. First, here's what happens when you flip a switch:
- The switch sends an MQTT message to the Dryer telling it what switch was switched, and what its state is.
- The Dryer performs the requested action (aka, turns on/off the heater/dryer).
- The dryer sends a "success" message after completing the action.
- This "success" message resets a trigger timer. If it weren't reset, the switch would reset to show that the action was not completed successfully.
- This success message also allows the Dryer itself to control the switch states. For instance, when the Dryer reboots, its outputs are both off and once it turns them off, it sends the corresponding messages which update the switches on the Dashboard.
The "Schedule Switch" is simpler - it's for enabling/disabling the schedule functionality. It simply sends a message to the Dryer telling it if scheduling is enabled or not, and then stores the state in the Global context so that we can initialize the Dryer when it starts up.
Finally, the last flow. The start/stop time setting controls:
These are just "Text Input" Dashboard widgets which are configured as time entry widgets. It's simple: These just send off the chosen time to the Dryer and also store it in the Global context for initializing the Dryer on boot.
Whew. That was a lot. Thanks for reading if you made it this far, and good luck implementing it yourself if you choose to give it a shot!
I'll be posting the ESP32 Microcontroller code soon enough once I get it cleaned up and make sure I haven't left any passwords lying around in the code!