node serial-port: how do I use one properly

2,547 views
Skip to first unread message

Max Hadley

unread,
Apr 6, 2014, 3:19:15 PM4/6/14
to node...@googlegroups.com
Hi,

I'm just starting a new node which will connect to an RFXcom RFXtrx433 remote control transceiver through a (USB) serial port. This is part of the device, and will always be in 38400-N-8-1 raw mode. Can somebody give me a quick heads-up on the 'proper' way to use a serial-port node for this job (if I should do so) as it doesn't seem to be documented anywhere? :-)

Thanks,

Max

Dave C-J

unread,
Apr 6, 2014, 3:45:12 PM4/6/14
to node...@googlegroups.com
Hi Max,

just place the node - edit the properties - hit the pencil to edit the port config - by default it looks for \n to break lines - if you really want raw just remove this \n - then you will get each character... up to you to then count / slice / detect starts of packets etc.

You can then "re-use" the same port for the output version also  - edit the properties and select the existing config. For output you can optionally append a newline (or whatever the inbound split char is) - but again if you are using it raw then you would have to send everything yourself.

Max Hadley

unread,
Apr 6, 2014, 4:08:45 PM4/6/14
to node...@googlegroups.com
Perhaps I'm not being dim: how do I, from within my node's .js/.html files, tell node-RED I want to use a serial port, so that I get the second dialog popping up when I click the pencil icon? And how do I access the path to the port, e.g. /dev/ttyUSB0 or whatever, to pass it it on to the rfxcom object I'm creating? (ditto for the baud rate & other settings)

Must be getting late...

Max

Dave C-J

unread,
Apr 6, 2014, 4:24:10 PM4/6/14
to node...@googlegroups.com
Max

do you have the node/npm  installed ? 
You need to do      npm install serialport       from within the node-red directory
On restart you should have two serial nodes in the left palette.
(PS - one windows serialport install is a real pain... hence why we don't pre-install it)
(PPS - start node-red        node red -v      to see more warnings and other packages you may wish to install  - or not.

Dave C-J

unread,
Apr 6, 2014, 4:33:02 PM4/6/14
to node...@googlegroups.com
Max

apologies... misread your question... thought you were asking how to get the serialport going... but now I think you're asking how to use a serialport within your own node ???

Max Hadley

unread,
Apr 6, 2014, 5:02:24 PM4/6/14
to node...@googlegroups.com
Yes, I need to use a serial connection to the rfxtrx and I got the general idea serial ports were a sort of pooled resource managed by node red so I shouldn't just ask for a device file path in my node editor. Is this not right?

Max Hadley

unread,
Apr 6, 2014, 5:02:25 PM4/6/14
to node...@googlegroups.com

Dave C-J

unread,
Apr 6, 2014, 5:02:55 PM4/6/14
to node...@googlegroups.com
As the serial port pool is only shared within the serial node space it's not available for other nodes to access. I think the (current) simplest way is currently to just copy the whole serial node and base your's on that. The key linkage is the word config in the html file  (category config ), and the input fields - ( node-config-input...) ,    and then type:  in the js file eg  serial: {type:"serial-port",required:true}  


Max Hadley

unread,
Apr 6, 2014, 5:14:29 PM4/6/14
to node...@googlegroups.com
Dave,

It looks like I may have got the wrong end of the stick then. Since the rfxtrx is itself a communication device, I may end up with multiple nodes - at least one input and one output type - and it was making these share a common configuration and underlying object that concerned me. Of course, there could be multiple rfxtrx devices present and there would need to be a way of configuring the association, which is what I assumed the serial pool was all about. But apparently not. What makes a node appear in the configuration tab? (Like serial ports do)

Max

Nicholas O'Leary

unread,
Apr 6, 2014, 5:51:40 PM4/6/14
to node...@googlegroups.com
Max,

there is a serial node pool - used by the serial nodes.

You want to create a rfxtrx pool - it just happens to use the serial port for communication - but as Dave said, there isn't a way to extend the existing serial connection pool to other node types. But that is okay - it is highly unlikely that you'd want an rfxtrx node and a serial node accessing the same serial port at the same time.


Dave gave you some pointers in his email... but let me elaborate on them.

If you look at the serial node files (nodes/core/io/25-serial.js + ..html)...

In the .html:

1) there are three node types registered - 'serial in', 'serial out' and 'serial-port'. The first two are the nodes you see in the palette. The third is a configuration node - note how it declares it's category as 'config'.

2) The serial in/out nodes declare a default property each called 'serial' (the name is irrelevant) with a 'type' of 'serial-port' - thats the magic that tells node-red that this node uses a config node. In the edit template for the serial nodes, there is a simple <input> with an id of 'node-input-serial' (ok, the name wasn't irrelevant... it needs to match this). If node-red finds an <input> with an id of node-input-XXX where XXX is the name of a property declared to be a config node type, (ie serial), then that's the magic to get the a drop-down list of available config nodes and the pencil button to add/edit them.

In the .js:

3) again, there are the three node types registered.

4) The config node, in this instance, is just a place holder for configuration details - there is no functional logic associated with it. This reflects the fact the config node mechanism came in after we already had the serial connection pool code. If we were to rewrite it today (and we probably should...), we'd move the connection pool logic to be in the config node object. That would then allow other nodes to declare their use of a serial-port config node as described above and make use of the pool for free.

4) when the serial in/out nodes are instantiated, they lookup their config node details. The 'serial' property of the node is the ID of the config node to use:

    this.serialConfig = RED.nodes.getNode(this.serial);



Hopefully that helps get you further. I really need to get the 'how to write a node' book written.


Nick



--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Martin Jarvis

unread,
Apr 7, 2014, 2:06:20 AM4/7/14
to node...@googlegroups.com
I already have a working node for rfxtrx433. I use it currently to control lightwave rf switches around the house.

See the RFXCOM node here: https://github.com/freakent/freakent-nodes

Regards
Martin

Nicholas Humfrey

unread,
Apr 7, 2014, 5:57:23 AM4/7/14
to node...@googlegroups.com
Wow, wish I had known about this. I am a rfxtrx433 owner too.

Are there any plans for a directory of third parts nodes?

Sent from my phone

Nicholas O'Leary

unread,
Apr 7, 2014, 6:01:26 AM4/7/14
to node...@googlegroups.com
Hi,

the plan is to expand the flows library to include nodes as well - but that's a little way off at the moment.

I would strongly encourage people to publicise their nodes on this mailing list - particular if they aren't added to the node-red-nodes repository.

Nick

Max Hadley

unread,
Apr 7, 2014, 5:40:20 PM4/7/14
to node...@googlegroups.com
Martin,

Thanks for the pointer! I'll take a look at it and decide what to do. I've been inclining towards the idea of using the message topic as the address, and the message payload as the command, along MQTT lines, so for instance:

msg = { topic: "AC/0x000bc5de/4", payload: "on" }

would turn on my washing machine, on a HomeEasy remote controlled socket (lighting2, subtype 'AC') at address 0x000bc5de, channel 4. This puts more of the work into the rfxcom-tx node, which has to work out what the protocol type is, tell the rfxtrx node to create protocol object of the right type & subtype, parse the topic to get the various parts of the address, and parse the payload to decide which protocol object method to call. But it keeps the message format very simple, and avoids having too much to configure in the node edit dialogue.

I'll play around with these ideas over the next few days...

Max

Martin Jarvis

unread,
Apr 8, 2014, 4:10:16 AM4/8/14
to node...@googlegroups.com
Max,

With hindsight I don't like the way I used the msg.payload currently so your idea sounds good to me, but I do want to keep the settings in the edit dialogue too. I actually use the subtype and address settings in the node edit dialogue instead of passing them in the msg. In my flow I have separate rfxcom nodes for each light so I can visually see the flow of events controlling each light. 

Regards
Martin

Max Hadley

unread,
Apr 8, 2014, 5:25:26 AM4/8/14
to node...@googlegroups.com
My thoughts for that use case were to add a 'topic mapping' to the node dialog. This would be a string matching and replacing that would look for (initial) strings in the topic like 'washing machine' and replace them with the full address 'AC/0x000bc5de/4', or optionally just a partial remap (e. g. excluding the 4). I think I can make a fairly simple UI for that

Max

Nicholas O'Leary

unread,
Apr 8, 2014, 5:31:42 AM4/8/14
to node...@googlegroups.com
Max - nodes should do one thing and do it well - let other nodes in the flow provide any sort of mapping needed within a property.

I plan to update the Change node to allow you to provide multiple change rules within a single node, rather than add multiple nodes for each thing you want to change. That will make creating such a mapping table easy and every other node benefits.

Nick


On 8 April 2014 10:25, Max Hadley <m...@zepler.org> wrote:
My thoughts for that use case were to add a 'topic mapping' to the node dialog. This would be a string matching and replacing that would look for (initial) strings in the topic like 'washing machine' and replace them with the full address 'AC/0x000bc5de/4', or optionally just a partial remap (e. g. excluding the 4). I think I can make a fairly simple UI for that

Max

Martin Jarvis

unread,
Apr 8, 2014, 9:07:21 AM4/8/14
to node...@googlegroups.com
Actually, thinking back, I did consider encoding the subtype and address together in the topic but later rejected it on the grounds of user friendlyness. Since the subtype controls which part of the underlying API gets invoked and depends heavily on actual implementation, I felt the subtype should be a validated setting in the UI.  The subtype will dictate which commands the node will respond to. Too much opportunity for confusion if that is all packed away in the topic string.

Looking at my code, I now remember why I didn't announce this previously :-) There's still some tidying up to do!

Martin Jarvis

unread,
Apr 8, 2014, 9:12:33 AM4/8/14
to node...@googlegroups.com
I agree with Nick that name/address mapping shouldn't be part of this node. Nick's plans for the Change node sounds it will become a very useful Routing node.

Max Hadley

unread,
Apr 8, 2014, 3:53:27 PM4/8/14
to node...@googlegroups.com
Nick,

Point taken: and I'm much inclined to go along with it. However, if it turns out that in real flows the Change and rfxcom-tx nodes are always used in pairs, there would be a case for adding this functionality - but it should in that case have exactly the same UI as the Change node. An example of this might the input scaling of bbb-analogue-in, which is very like the range node (in this case I suggest you grab the breakpoint editor from bbb-analogue-in & put it in range)

Max


On Tuesday, 8 April 2014 10:31:42 UTC+1, Nicholas O'Leary wrote:
Reply all
Reply to author
Forward
0 new messages