Hi!
I've got a problem with choosing a "Node-RED" way to "construct" the message passed through nodes.
To describe my "problem" I have an array of relays, couple of boards, with 16 relays each, most of them are used to control my floor heating, but there are also some that turn on the lights or does some other automations.
To do "low level" operations, I've created a subflow that accepts messages in form {relay:{id:42, operation:"on"}}
and there are also "higher level" abstractions that accepts for example a mqtt message or something, to turn on the lights or heating, to keep things in order lets say that this it the 1st method.
But right now I'm thinking that information should be passed using the payload field, because 'this is the way' so the 2nd form would be {payload:{ relay:{id:42, operation:"on"}} }
or just {payload:{id:42, operation:"on"}}
(3rd) but... Now I'm thinking that we also have a topic, so it in the end, this might also be something like {payload:"on",topic:"/home/storey/0/kitchen/floor/heating"}
(4th)
And now... I'm confused because if this is a Nore-RED way of sending messages, why there is no builtin mechanism of routing messages by topic like for example in MQTT? (a switch node which outputs the message on all fitting topics, not only one) Right now topic is only a field without any defined form, and from what I can see, most people threat this as a "text field" (a key) setCurrent, temperature, etc rather then a topic. (whereas as topic I understand the same as in mqtt topic)
1-st option, obsoletes the payload field, so I assume this is not OK
2-nd has a redundant field 'relay' which is a little bit pointless, but still acceptable for me
3-rd looks OK for me, but it has and ID field which, in my opinion, should be moved to topic field
all the above schemas can take additional field in payload/relay object (e.g 'delay', or 'momentary') without a type change, I just add another field and that's it
4-th looks more like messages that I've seen in other flows, but this has the limitation that adding new field changes the type of message and somewhere i need to check for datatype and have different logic to both flows.
5-th? where payload is not a text field containing an operation but rather all needed information? {payload:{operation:"on", something:0}, topic:"..."}
?
The question is... If you where in the same situation, which schema would you use, and WHY? what strategy should I use in the future?
There is a PEP for python, where is PEP 8 for Node RED?
Br,
Bartoszek