Close

Node Red Complete!

A project log for Internet Connected Boot Dryer

Modifying a Boot Dryer to be controllable via the internet!

markmark 05/29/2019 at 00:580 Comments

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...

---------- more ----------

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.

When the Dryer boots up, it is a blank slate with no idea as to what the schedule start/end times are, if the schedule is enabled, and what the current timezone is. When the scheduling values are changed (start/stop time, scheduling enabled), they are stored in the Node Red Global context. Here they are retrieved from that Global context and sent to the Dryer. Similarly, the timezone is found with Javascript and used so that our Node Red dashboard and our Dryer are on the same page in terms of what time it is. Again, all these MQTT messages are routed to a Link to the main MQTT sender flow (above).

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:

  1. Every 20 seconds, the Heartbeat Injector fires.
  2. This sends a "hash" (a random number) to the Dryer via MQTT, sets a "Heartbeat Response" value to false, and starts a delay timer.
  3. The delay timer runs for 250ms and once it expires, uses the "Heartbeat Response" value to change a Connection Status LED on the dashboard.
  4. 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:

  1. The switch sends an MQTT message to the Dryer telling it what switch was switched, and what its state is.
  2. The Dryer performs the requested action (aka, turns on/off the heater/dryer).
  3. The dryer sends a "success" message after completing the action.
  4. 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.
  5. 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!

Discussions