Node-Red, UIBuilder and Buttons!!

Node-Red, UIBuilder and Buttons!! (Last Updated On: )

If you’ve been here before then you know I use Node-Red, if not and you don’t know what Node-Red is, you should check it out. To get a frontend UI out of Node-Red there has always been the Dashboard node for us to use and a set of Dashboard nodes to go with it. I have never been a huge fan of the Dashboard, but it was what we had and it did the job. The Dashboard nodes allowed you place UI nodes and connect them to your data and it would do the rest, no HTML code required on your behalf. But that was one of the limitations, was that you did not have control over the code. Enter UIBuilder.

The UIBuilder node is amazing. It is a Node-Red interface builder that gives you complete control, over everything. The downside (if it is one) is that you must know how to code HTML and JavaScript. UIBuilder lets you use any frontend framework you want to build your interface to Node-Red. JQuery, VueJS, MoonJS, Angular, etc.. So far I have dropped in a Bootstrap-Vue admin template and I have been going to work on that. It has taken me a minute to get used to how UIB all works, and I am not really all that great with JavaScript but I seem to be figuring things out. Hey, I have shit working.

The UIBuilder Wiki and the Github for the author have a ton of information and examples of how to get a few basic things done. Just expect most of them to be done with VueJS. It appears (at least to me, I could be wrong) that UIBuilder was originally VueJS heavy/dependent and as it matures it is more open to other frameworks. As of v3.1.3 it no longer installs Bootstrap-Vue and VueJS by default, as it had done it all prior versions. So just be aware that you can use any framework you want, but all of the examples (so far) are all written in VueJS. There is also the Node-Red forums if you get stuck, the author also happens to frequent the group.

The basic default UIBuilder file is pretty decent and is a good place to start off from. While digging around the Node-Red forums for UIB information I stumbled upon a post by Squirrelbd and his flow had a form and some buttons. I took his flow and modified it, so now it has multiple buttons that all send their own payload, separately, and their status is reported back. I am not currently interested in using forms for data collection, I don’t need it at this time so that was removed from the flow. I currently have a basic page working with four buttons that fire off a 4-channel relay connected to the Raspberry Pi, and the data is cached so it persists over browser refreshes and multiple devices.

One of the issue I came across while trying to get my buttons to work was Bootstrap-Vue/VueJS does not do native hidden form fields. WTF guys really? It took an hour of Googling and hitting up StackOverflow but I found the answer eventually in the Github issues for VueJS. You cant use a <b-form>  tag with a hidden field, it wont work. So you just use the default HTML form tag for a hidden field,  <input type="hidden" :value="someData" >. What I found on the web was to add the semi-colon in front of “value”, that is probably for passing data, which I am not so I can not vouch for if it works or not. It seemed to be hit and miss for some people. I did need the form fields to pass information, but my information is static. I set the data for my fields in the index.js file. I am just using it for my buttons to send clicks. I then set up Node-Red to handle the web button clicks and ran them into a toggle node which is connected to GPIO output nodes and wired to a 4-channel relay.

During programming the flow for the relays and the UIB buttons I had to learn how to use a function node with multiple outputs. Some basic Node-Red stuff I just happen to not use it much. If you are unfamiliar with multiple outputs on a function node you should take a look. Here’s a great example flow for multiple outputs for a function node.

The Flow

The example flow below uses all basic nodes except for two, it requires node-red-contrib-uibuilder and node-red-contrib-toggle to be installed. On my Raspberry Pi install the link nodes in the flow connect to another link node on a separate flow to fire off the relays. In this example they wont be connected to anything. The four buttons on the web page send the same payload when clicked. I have them connected to a toggle node and the tied to the relays. I don’t expect the flow to be useful as something that cant be loaded and used right off the bat, but I hope it is a good stating point to help you out. I wish I would have found this flow in the very beginning!

Links

https://github.com/TotallyInformation/node-red-contrib-uibuilder

https://github.com/TotallyInformation/node-red-contrib-uibuilder/wiki

https://flows.nodered.org/node/node-red-contrib-toggle

https://discourse.nodered.org/t/uibuilder-multiple-button-button-only-work-once/16955


Discover more from Its_All.Lost

Subscribe to get the latest posts to your email.

Leave a Reply