Best way to configure my node via messages

Hi folks,

I'm developing a new UI node that can be configured to a.o. add N LEDS on top of an image. In the following example I add 3 LEDs, each with a different color:

image

Which results in something like this:

image

Now I want to control the color of those LEDs via input messages from the Node-RED flow. But not sure what the best way is to accomplish this.

  • Should I add a field in the config screen for every widget, where the user can enter a unique name (which I have to validate). Or should I generate an ascending index myself (and show it readonly). Or should I add a Or something else.
  • The input message should contain both a LED identifier and a LED color. Should identfier be the msg.topic and the color be the msg.payload (which e.g. can be configured via two TypedInputs fields), or should both be in the payload, or something else.
  • Suppose the user wants to change the status of all 3 LEDS. Should this be possible with a single input message (then I cannot use a topic I assume), or should I oblige him to send 3 separate input messages ...

I got in the past some great feedback from @DeanC (about another node), about avoiding people having to add tons of extra nodes (like Change node) in their flows to compose the input message. So that is really something that I would like to pay attention to this time...

P.S. This discussion is not about 'why' I want to add LEDs. If some users really hate LEDs, they can just ignore them. Case closed in advance :wink:

Thanks !!
Bart

I would look at naming them so their id doesn't change if the user decides to delete one from the middle of the list. You could, of course, generate default values for the name as the user adds them, so they don't have to type anything in if they are happy with the default. It also means the user can identify which led is which in the list without having to remember which coordinates map to which light.

For the message, I'd start with the idea of msg.payload being a key/value object that maps led to desired state - allowing the user to set multiple. You could also check if msg payload is a string then use msg.topic to identify the single led to change - that's more streamlined for the single led case.

@knolleary: thanks, that makes sense and is very flexible. I like the idea that users can choose a bit, how they can control my node. Perhaps I could also check whether it is an Array of key-value pairs, to setup multiple leds at once ...

The only thing that bothers me, is that msg.payload could also contain an image (if the user specifies to push the images to my camera viewer). Then I have to detect also whether the payload contains a base64 encoded image, since there is no topic to see the difference between images and control messages. Not sure at the moment whether it is resource consuming to continiously do the base64 check. Or perhaps I need to add multiple TypedInputs:

  • One typed input for image source e.g. msg.image
  • Another typed input for control messages e.g. msg.payload

And validate that both fields need to be different. On the other hand then the users would need to use extra Change-nodes to move their images to msg.image :woozy_face:

An object can contain multiple key/value pairs... No need to also wrap it in an array.

{
   "LED1": "red",
   "LED2": "blue"
}

If you want the user to be able to set the image as well, then I would avoid overloading a single property that much. Decide which is more important feature, use msg.payload for that and pick a suitably named property for the other feature.

1 Like

@BartButenaers are these LEDs to be SVG based (e.g. are you presenting the image as part of an SVG and drawing colour filled circles?)

If this is the case, i could imagine a time where you add other shapes like a car or a person and this ends up being used as a layout with live / animated objects representing your data.

I would potentially use this as an AGV map. Send an AGV shape (SVG path or shape) to specific coordinates. Animate / update it's position on the image. Change its colour to represent things like fault, battery low, last seen etc.

Additional thoughts. Position should be a typedinput so it can be easily and flexibly animated. Widget itself could also be a typedinput. perhaps size/scale should also be available?

As for the widget itself, these could simply be a piece of SVG code in a file or folder of SVGs permitting the user to define their own? Or a config node where users can add additional SVG coded widgets?

Just a few thoughts - if they aren't relevant or go against your design or intended use then please ignore.

Sorry - just spotted this comment.

Please ignore my previous post if I've took the thread in a direction you we're interested in.

Happy coding.

Indeed, these are just SVG circles.

Have been thinking about that also, but I want to avoid users going to use it as a floorplan or whatever. Want to keep this widget focussed on video surveillance. Most probably I will add other shapes afterwards, but focussed on video surveillance.

For a floorplan that would be indeed useful, e.g. to animate where someone is walking. But to move LED's or PTZ buttons around on my camera widget seems very annoying to me.

Don't know if widgets are going to be changed dynamically? Perhaps I could make the visibility adjustable via an input message...

Have been thinking about that also. But I'm afraid that everybody is going to abuse my camera-viewer node as a general drawing node. Currently I would prefer if people contact me if they know a cool (camera related) widget to add, or that they create a pull request.

Think we need create in the near future a general SVG UI node, so you can start playing :rofl:

Thanks for sharing your ideas !!!

I wish I had the time to develop this.

Regarding your node,
Are you going to add click events to the SVG items? I could see someone wanting to operate things like lights or PTT for sending speech or audio to a camera or a network audio device (e.g. barix exstreamer).

As you are focused on surveillance, I imagine you might want to have camera widgets populating the drawing? Perhaps the ability to fire PTZ commands too? Or switch to the video stream on click?

Yes some of the widgets (like ptz control) have already clicked events, and result in output messages. Other widgets (like LED) have no clicked events.

Yes I draw the SVG shapes on top of the video footage.
As soon as I have an alpha version ready, I will start a new thread so we can focus properly on all these things. Have to stop here, because Discourse gives me a spoiler alert ...

1 Like

Presumably you could (at some point) have a text overlay also ?

Hey @dceejay,
One of my current widgets is "text" which is static text or supplied via a msg property. That allows users to show e.g. "cam living room" or an alert text or ... Is that what you mean?

1 Like

This was a very decent proposal. However (based on the question of @Steve-Mcl), now I would also like to control the visibility of every widget via the input message (invisible or invisible). However e.g. a LED widget now has two properties that I need to control via the input message: color AND visibility. I assume the only way is to do that like this:

  • put the property name ("COLOR" or "VISIBILITY") in the msg.topic field
  • put the key/value pairs (from Nick's proposal) into e.g. the msg.payload field

Perhaps a topic "IMAGE" could be used when the payload contains an image to be displayed...

Is this an acceptable way of working, or is there a better approach?

How about put the ui related things in msg.ui_control property (like most of ui_widgets do)

That might indeed be a good message field to use! Will keep it in mind.

But when I look at the documentation, I still don't know where to put the widget name. A single cam-viewer node could contain e.g. four LEDs. So I need to be able to specify LED1-Color-red or LED3-Visibility-false. I cannot put 3 fields in a single key-value pair, so I wanted to put the third property into the topic. Or am I getting nuts?

Let the user define a name for led. Then from incoming msg for led change accept only known properties where name is defined.

msg.ui_control = {'userdefined_led_name_1':{'color':'blue','visible':true,'blink':'fast'},'userdefined_led_name_2':{'visible':false}}

1 Like

Thanks @hotNipi !! And indeed I think your format is simple enough to allow users to create such a message with a single Change-node, so they don't have to clutter their flows to setup my new node ...

One addition - you'll need to validate name field on config edit page against names must be unique.

I have created a validation function last evening already. Of course they can deploy anyway, but then it is out of my hands ...

What can the user expect from node with configuration error (red triangle)? I mean if user decides to deploy in such error situation..

warning... ui_control messages currently get processed to overwrite exiting properties that otherwise can't be (like chart axis font size etc)... i "think" it should be ok for you to re-use like this... but ensure you don't have anything in your node config with the same property names.... and test before release :wink: