Stuck using Serial Node

Hi All,

I am trying to use a serial flow to drive a relay box via serial over a USB/RS485 device.
I tried to import dedicated RS485 nodes, but they will not load.

When I send using a standard serial node, I get a response of "0x00" from the other device, so it is listening (I believe).
If I power the other device off and on, it sends a message of payload 0x0, followed by another of 0xf0, 0xa2,0x76,0x6, 0x0 which means nothing to me.

I am trying to send "FD 20 02 01 01 5D" in ASCII terms, and if I capture debug, I send [253, 2 32,1,1,93], and it is received and I get a response of the same buffer back (as "request_payload", and a payload of 0x0.

I am stuck, and have been trying various things to no effect. Appreciate any help here folks.

My flow is as below:

[
    {
        "id": "4a0ac2ce.818e0c",
        "type": "debug",
        "z": "7b472191.351b1",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 990,
        "y": 420,
        "wires": []
    },
    {
        "id": "34c334a.41043cc",
        "type": "serial in",
        "z": "7b472191.351b1",
        "name": "485-Rx",
        "serial": "e19b9f04.c6402",
        "x": 790,
        "y": 420,
        "wires": [
            [
                "4a0ac2ce.818e0c"
            ]
        ]
    },
    {
        "id": "a713e90a.e26dd8",
        "type": "inject",
        "z": "7b472191.351b1",
        "name": "",
        "topic": "Relay 1 - 485",
        "payload": "ON",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 340,
        "wires": [
            [
                "5b15a315.665a3c"
            ]
        ]
    },
    {
        "id": "216318b1.0d9728",
        "type": "debug",
        "z": "7b472191.351b1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 950,
        "y": 480,
        "wires": []
    },
    {
        "id": "5b15a315.665a3c",
        "type": "function",
        "z": "7b472191.351b1",
        "name": "Set Buffer",
        "func": "//var buf = JSON.stringify([\"0xFD\",\"0x02\",\"0x20\",\"0x01\",\"0x01\",\"0x5D\"]);\nvar buf = ([0xFD,0x02,0x20,0x01,0x01,0x5D]);\n//var buf = Buffer.from([0xFD,0x02,0x20,0x01,0x00,0x5D]);\n//var buf = JSON.stringify(['FD 02 20 01 00 5D']);\n//var buf = ([253,2,20,1,0,93]);\n//var buf = (['FD','02','20','01','01','5D']);\n\nmsg.payload=buf;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 320,
        "y": 340,
        "wires": [
            [
                "2b040dd5.6787b2"
            ]
        ]
    },
    {
        "id": "2b040dd5.6787b2",
        "type": "json",
        "z": "7b472191.351b1",
        "name": "To JS Object",
        "property": "payload",
        "action": "obj",
        "pretty": true,
        "x": 510,
        "y": 360,
        "wires": [
            [
                "b764cca6.ad507",
                "f85acbfa.253f18",
                "70fa758d.f0316c"
            ]
        ]
    },
    {
        "id": "70fa758d.f0316c",
        "type": "serial request",
        "z": "7b472191.351b1",
        "name": "485-Tx",
        "serial": "e19b9f04.c6402",
        "x": 800,
        "y": 360,
        "wires": [
            [
                "2f8b8eb.fda4d72"
            ]
        ]
    },
    {
        "id": "e287a329.e8872",
        "type": "inject",
        "z": "7b472191.351b1",
        "name": "",
        "topic": "Relay 1 - 485",
        "payload": "OFF",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 150,
        "y": 380,
        "wires": [
            [
                "37c37ef9.805612"
            ]
        ]
    },
    {
        "id": "37c37ef9.805612",
        "type": "function",
        "z": "7b472191.351b1",
        "name": "Set Buffer",
        "func": "//var buf = JSON.stringify([\"0xFD\",\"0x02\",\"0x20\",\"0x01\",\"0x01\",\"0x5D\"]);\nvar buf = ([0xFD,0x02,0x20,0x01,0x00,0x5D]);\n//var buf = Buffer.from([0xFD,0x02,0x20,0x01,0x00,0x5D]);\n//var buf = JSON.stringify(['FD 02 20 01 01 5D']);\n//var buf = ([253,2,20,1,0,93]);\n//var buf = (['FD','02','20','01','00','5D']);\n\nmsg.payload=buf;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 320,
        "y": 380,
        "wires": [
            [
                "2b040dd5.6787b2"
            ]
        ]
    },
    {
        "id": "2f8b8eb.fda4d72",
        "type": "debug",
        "z": "7b472191.351b1",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 990,
        "y": 360,
        "wires": []
    },
    {
        "id": "b764cca6.ad507",
        "type": "json",
        "z": "7b472191.351b1",
        "name": "",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 790,
        "y": 480,
        "wires": [
            [
                "216318b1.0d9728"
            ]
        ]
    },
    {
        "id": "d875a16f.90171",
        "type": "serial out",
        "z": "7b472191.351b1",
        "name": "",
        "serial": "e19b9f04.c6402",
        "x": 810,
        "y": 300,
        "wires": []
    },
    {
        "id": "f85acbfa.253f18",
        "type": "debug",
        "z": "7b472191.351b1",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 810,
        "y": 240,
        "wires": []
    },
    {
        "id": "e19b9f04.c6402",
        "type": "serial-port",
        "z": "",
        "serialport": "/dev/ttyUSB0",
        "serialbaud": "115200",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "0",
        "bin": "bin",
        "out": "time",
        "addchar": "",
        "responsetimeout": ""
    }
]

If you are using the serial request node then you don't need the in and out nodes.
I am surprised it wants you to send an array... usually serial devices like binary (buffer) type data - so to me the line 3 in your function node looks a better bet... and then you don't need the json node... so I would start with just

[{"id":"8a6f188b.86e888","type":"inject","z":"3ead5d77.6a6672","name":"","topic":"Relay 1 - 485","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":380,"wires":[["5c3528cc.0baab8"]]},{"id":"5c3528cc.0baab8","type":"function","z":"3ead5d77.6a6672","name":"Set Buffer","func":"//var buf = JSON.stringify([\"0xFD\",\"0x02\",\"0x20\",\"0x01\",\"0x01\",\"0x5D\"]);\n//var buf = ([0xFD,0x02,0x20,0x01,0x01,0x5D]);\nvar buf = Buffer.from([0xFD,0x02,0x20,0x01,0x00,0x5D]);\n//var buf = JSON.stringify(['FD 02 20 01 00 5D']);\n//var buf = ([253,2,20,1,0,93]);\n//var buf = (['FD','02','20','01','01','5D']);\n\nmsg.payload=buf;\nreturn msg;\n","outputs":1,"noerr":0,"x":440,"y":380,"wires":[["b88ed16.3358a3","298340c.477ecc"]]},{"id":"b88ed16.3358a3","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":630,"y":340,"wires":[]},{"id":"298340c.477ecc","type":"serial request","z":"3ead5d77.6a6672","name":"485-Tx","serial":"cb4a85a.b42ed78","x":640,"y":380,"wires":[["f054c5f2.97dbf8"]]},{"id":"f054c5f2.97dbf8","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":830,"y":380,"wires":[]},{"id":"cb4a85a.b42ed78","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"0","bin":"bin","out":"time","addchar":"","responsetimeout":""}]

Hi, Thank You for your reply, and I have tried it, but sadly to no avail.
The only documentation I got with the device is as attached here, and I believe you are quite right, when you say the way forward is to just send the necessary characters in the simplest form.... The Problem is, I fear I may be even more simple than that! :slight_smile:

Thanks for the help, which has encouraged me to solve the issue even more! Cheers, Bob!

(I hope I don't regret this)

Hi @BobD

That isn't serial. That is IP.

You are sending stuff to an IP address.

A long time ago I had a similar problem with a relay board I bought.

Just for the sake of it, could you send a piccie of the relay board?

Because I am suspicious you are going to need UDP nodes, not SERIAL.

Oh, just to cut down on how many times you post - as new members are limited - what happens if you do what is written at the bottom of the page?

http:192.168.1.4/3000 in the browser's address bar

What do you see and can you control the relay from there?

Hiya, The serial is the problem, the IP addressable part is easy to control (if a little clunky).

The relay box works fine from the IP address.....it runs a little web page, so you can send it commands.

Stuck a network cable in, and it is fine (although fixed IP).

That part of it works fine, as do the discrete pins which you can take high or low to control the relays too.

It claims to have half-duplex 485 comms, and although I can get it to reply with a "0x00" (which I think is "OK"), I am just not sending it the right command on the serial.

I am fairly sure it is my lack of experience with node-red, rather than the little box :slight_smile:

Cheers though for the prompt.....I should have explained better.

ATB,

Bob

This is the "other half" of the comprehensive instruction manual...LOL.

I have mailed the vendor, but they have quite a bit going on to reply just now, I fear. (New Year, and viruses in the air).

Best Regards,

Bob

Well, I'll call it as I see it.

You need to use UDP packets to get the relay to work.

(You haven't sent a piccie of the relay board.)

The 485 comms is from the board to the relay - well not exactly but .....

Again: My take:
From the web page, you send things and the relay operates.

Where you are in the scheme is at the web page point. Not at the relay board point.

So you need to send commands via the IP part.

I'm guessing UDP but it could support HTTP too. My relay board takes both/either.

Alas it was a long time ago when I set up my relay board.

Suggestion: Heaps of `UDP` nodes. Set up the IP address and enter values increasing from 0x00 to.... how ever many you are prepared to do.

Are you familiar with WireShark?
You need to see what is being sent.
I'm guessing something around the 0x20h range.

Suggestion:
Heaps of UDP nodes. Set up the IP address and enter values increasing from 0x00 to.... how ever many you are prepared to do. Try around 0x20 and up.

Inject them into the UDP node which sends the value to the IP address.

If you are lucky you will quickly find the value which turns the relay on/off.

But, this is based on what I have been through.

I'll look at your post you posted just now.

Yeah, fine.

That says the board talk RS485 LOCALLY on the board. From the RJ-45 to the relays.

You need to deliver a IP packet to make things work.

here is a flow I bashed together to get my relay board to work.

[{"id":"8666a6b3.e4f6e","type":"inject","z":"bdf022da.6d6178","name":"","topic":"","payload":"11*","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":115,"y":180,"wires":[["847612f8.a659e8"]]},{"id":"847612f8.a659e8","type":"ui_button","z":"bdf022da.6d6178","name":"","group":"d89e6903.965fb8","order":3,"width":"6","height":"1","passthru":true,"label":"Pulse Relay 1","color":"","bgcolor":"","icon":"","payload":"11*","payloadType":"str","topic":"","x":270,"y":180,"wires":[["1095c327.4fb3f5"]]},{"id":"1095c327.4fb3f5","type":"udp out","z":"bdf022da.6d6178","name":"","addr":"192.168.0.21","iface":"","port":"6723","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":610,"y":280,"wires":[]},{"id":"26873451.ebf88c","type":"ui_button","z":"bdf022da.6d6178","name":"","group":"d89e6903.965fb8","order":6,"width":"6","height":"1","passthru":true,"label":"Turn on Relay 1","color":"","bgcolor":"","icon":"","payload":"11","payloadType":"str","topic":"","x":270,"y":220,"wires":[["1095c327.4fb3f5"]]},{"id":"718dd5bd.a486e4","type":"ui_button","z":"bdf022da.6d6178","name":"","group":"d89e6903.965fb8","order":7,"width":"6","height":"1","passthru":true,"label":"Turn off Relay 1","color":"","bgcolor":"","icon":"","payload":"21","payloadType":"str","topic":"","x":270,"y":260,"wires":[["1095c327.4fb3f5"]]},{"id":"3fb79ced.720d74","type":"ui_button","z":"bdf022da.6d6178","name":"","group":"d89e6903.965fb8","order":9,"width":"6","height":"1","passthru":true,"label":"Pulse Relay 2","color":"","bgcolor":"","icon":"","payload":"12*","payloadType":"str","topic":"","x":270,"y":300,"wires":[["1095c327.4fb3f5"]]},{"id":"3821c05c.a10e3","type":"ui_button","z":"bdf022da.6d6178","name":"","group":"d89e6903.965fb8","order":11,"width":"6","height":"1","passthru":true,"label":"Turn on Relay 2","color":"","bgcolor":"","icon":"","payload":"12","payloadType":"str","topic":"","x":270,"y":340,"wires":[["1095c327.4fb3f5"]]},{"id":"36385393.afe414","type":"ui_button","z":"bdf022da.6d6178","name":"","group":"d89e6903.965fb8","order":13,"width":"6","height":"1","passthru":true,"label":"Turn off Relay 2","color":"","bgcolor":"","icon":"","payload":"22","payloadType":"str","topic":"","x":270,"y":380,"wires":[["1095c327.4fb3f5"]]},{"id":"bb8b0ca4.db13b","type":"inject","z":"bdf022da.6d6178","name":"","topic":"","payload":"11","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":115,"y":220,"wires":[["26873451.ebf88c"]]},{"id":"e86b92d9.3fbb58","type":"inject","z":"bdf022da.6d6178","name":"","topic":"","payload":"21","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":115,"y":260,"wires":[["718dd5bd.a486e4"]]},{"id":"e627ed3.7ea171","type":"inject","z":"bdf022da.6d6178","name":"","topic":"","payload":"12*","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":115,"y":300,"wires":[["3fb79ced.720d74"]]},{"id":"ffb5e903.8455c","type":"inject","z":"bdf022da.6d6178","name":"","topic":"","payload":"12","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":115,"y":340,"wires":[["3821c05c.a10e3"]]},{"id":"91fc8fbc.e885b8","type":"inject","z":"bdf022da.6d6178","name":"","topic":"","payload":"22","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":115,"y":380,"wires":[["36385393.afe414"]]},{"id":"d89e6903.965fb8","type":"ui_group","z":"","name":"BUTTONS","tab":"b491efec.21f03","order":2,"disp":true,"width":"12","collapse":false},{"id":"b491efec.21f03","type":"ui_tab","z":"","name":"Relay Control","icon":"dashboard","order":12}]

Select the code. Copy to clip board.

Go to Node-Red. Menu. Import.
Paste the code and press OK.

Deploy - if you want.

Change the IP address to yours.

You will also (probably) need to change the port. But, hey: you could be lucky.

That is what you are going to need to control the relays.

The HTTP works very well, but I am trying to use the 2-wire RS485 (bottom right of the image).

I haven't tried UDP, (might give it a whizz....but I think it is set for HTTP, which works OK).

I am pretty sure it is just that I am sending the message in the wrong format over the RS485 box.

I can have a peek with wireshark, but I haven't used it for 485 (I have a 485 debugger though, which is similar).

Thanks for your help though, I am sure it is something that will make me just "DOH!" when I realise what it is,

Bob

Cheers,

Bob

I can control the relays fine via the network interface (or the discretes).
It is just the two wire half-duplex.
:slight_smile:

WHY?
(And it is not exactly "bottom right" It is more: bottom right-ish.)

I can't read that stuff easily. I'm suspicious it is is an RS 485 OUTPUT to control MORE RELAYS rather than an alternate input method.

But........

Who knows?

IF it is a RS 485 input you have to understand:

You are going to have to build a RS 485 hardware port/circuit to allow you to send RS 485 signals.

It doesn't just magically happen.

Rather, invest a bit of time and work out how to control it via the HTTP/IP link.

A lot less messing around and you know it works.

If you build the RS 485 port, any number of things could be wrong and it not sending the right things and so you are increasing the number of points of failure from being only software to any number of components failing in the RS 485 port.

Hiya,
Sorry, I meant bottom-right of the diagram.
I am pretty certain I just need to send a message of the format ... FD 02 20 01 01 5D
to the RS485 connector. (it seems to want to be hexadecimal to me).

It is not life-or-death (well....only to my pride), and I am sure there is someone who knows the answer to this one....(even if it is not me yet).

Have a good one......and thanks for the help so far!

Cheers,

Bob

I have a USB-RS485 box (and I can test that against a number of other places).

The relay works fine (on all but the RS485).
It communicates (on the RS 485)
The RS485 box communicates (to other 485 connections).
I'm just stuck...LOL
It is feeling like a "tomorrow job".
:slight_smile:

(As pointed out to another new member:)

At this point in time you have a limited number of posts / day and you are then blocked.

Rather than posting small replies, EDIT a previous one and save your "posts / day" count.

Again I strong suggest you get WireShark and look at what is being sent.
Then you just send those packets to control the relays.

I don't mind helping you with that part. Alas though I am not too good with WireShark. Though it isn't rocket science to use.

Yes, but I am suspicious that is what you send down the TCP/IP link.
The RS 485 part will be a sub section - I think.
All the RS 485 needs is a Relay number and a state. Which is a lot less than what you posted.

Read the bottom part where it explains what you send.

FD 02 20 01 01 5D 1 Open
FD 02 20 01 00 5D 1 Close

All that is is 01 01 or 01 00 Open close.
Relay 2 is similar:
FD 02 20 02 01 5D 2 Open.
I'm guessing it will be:
FD 02 20 02 00 5D 2 Close

The other stuff is "wrapping" for the TCP stuff.

Try sending 02 00 or 02 01 and see if relay 2 does something/anything.

Of course you may have to send the 02 01 to get something to happen as if relay 2 is "off" and you send 02 00 which turns it off.... Nothing will happen.

Get what I am saying?

I get what you are saying, thanks.
The problem I have is trying to send the messages that the vendor has stated are the correct ones, down the two-wire (RS485) serial link.
It is all clearly marked on the diagram and in the text, (near the bottom of the page).
I fear you are confusing network comms with twisted-pair serial comms.

I have said the box works fine using the web interface.

The box works fine with discretes.

I am trying to test it with the RS485 (which then gives comms good for half a mile).

I am calling it a night here, as it is already Sunday.....

Tomorrow is another day, and I will have at it again!

Cheers,

Bob

Looking at similar type boards on the web - it does seem like yes you should be able to control it over rs485 - no need for ethernet... BUT... you can setup the board parameters via the web interface - so you may want to check baud rates, parity setting etc are all as you expect via the ethernet first before disconnecting that.

From that single page of docs it looks like you should be able to just send those bytes as I suggested previously (IE a buffer) - but that you should get a reply like FB 21 55 xx yy 5D back where xx is the channel and yy is 0 or 1 for off and on.
If you are just getting 00 then I don't think that is OK.

@dceejay I have tried sending the buffer in two ways, one of which sends the characters (but as two character strings by the look of it), and one which treats the characters as hex, and sends numbers in an array. I don't seem to be able to send the actual characters as a buffer, which I believe might do the job.

What I have posted here (the pictures) is the sum total of what was in the box, and the web interface to the device is a quite basic and functional one, that has a way of setting the net IP address, but nothing pointing to any RS485 settings. When I send to it, I get a flash on the Rx line, and it messages back, so I think the line settings are working, but I am juist not sending the exact format the device needs perhaps. I have mailed the vendor, and hopefully I will get a little more info to solve this. Thanks for the help so far, which is greatly appreciated.

I am pretty sure this might be a good pointer.

It seems to be sending something called "request_payload" rather than the msg.payload?

Is that something I can correct in the node with JS?

No that is just an "feature" of the serial request node - it copies the original request into that property so you can be sure what request gave which result.
To be sure add another debug to the output of the set buffer function to see what you are sending out... it should just be a payload that is of type buffer of the "correct" bytes.

So yes it does look wrong in that you have an array - It should be a buffer - as per the version I sent you - or the line 3 of your original function.