Sending HEX payload to serial connection with Serial Port Node

I'm hoping someone can provide some guidance, and nudge me in the right direction. I have a Pylontech battery bank, as part of my solar power system.

I would like to use Node-RED to periodically poll the battery bank for operational parameters, via the RS232 Console port.

The instructions I have instruct the following:

First, the console has to be activated. To do this, switch the terminal program to 1200, 8, N, 1.

Then send the following hex string to the battery:

Data: 7E 32 30 30 31 34 36 38 32 43 30 30 34 38 35 32 30 46 43 43 33 0D

Now switch to 115200,8, N, 1 ..

Data: Send 0D 0A.

The pylon> prompt appears, which enables commands to be entered.

First command e.g.

help \ n (\ n = line feed character 0A)

shows some help

pwr \ n

@

Power Volt Curr Tempr Tlow Thigh Vlow Vhigh Base.St Volt.St Curr.St Temp.St Coulomb Time BVSt BTSt

1 49884 4310 28000 25000 26000 3322 3327 Batch Normal Normal Normal 31% 2017 - 07 - 09 14:56: 37 Normal Normal

2 49832 4472 28000 25000 25000 3321 3323 Batch Normal Normal Normal 31% 2017 - 07 - 09 14:56: 36 Normal Normal

3 49842 4318 28000 25000 25000 3322 3324 Batch Normal Normal Normal 30% 2017 - 07 - 09 14:56: 36 Normal Normal

4 49858 4111 27000 23000 23000 3322 3325 Batch Normal Normal Normal 30% 2017 - 07 - 09 14:56: 36 Normal Normal

5 - ------ Absent - ------

6 - ------ Absent - ------

7 - ------ Absent - ------

8 - ------ Absent - ------

Command completed successfully

$$

The numbers are given as fixed point numbers and usually have to be divided by 1000.

I'm hoping to use the node-red-node-serialport pallette for this, but I'm having a bit of difficulty figuring out how to do this. Any help is greatly appreciated.

Unfortunately I do not believe that you can change the baud rate at run time with the serial nodes. I think you may have to do something like using a Python script to interface with the device and pass the result to node-red. Perhaps the supplier provides a python script that you could use.

1 Like

Or can you do the first part outside of Node-RED and then once into 115200 mode - just stay in that mode ? (and then use Node-RED)

1 Like

Though that would mean stopping node red in order to release the port if the device needed re-initialising. Then restarting node-red once it was initialised.

1 Like

If BAUD 1200 is fast enough for you and the pwr\n command works/responds, then stick with that (i.e. dont change speed)

Something like this might work...

[{"id":"741a12ab7e85b435","type":"inject","z":"62f0c6d6.6621a8","name":"0D 0A - get command prompt","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"0x0D\", \"0x0A\"]","payloadType":"bin","x":1020,"y":460,"wires":[["155d22f0618d2958"]]},{"id":"1f5815eb4435c35c","type":"debug","z":"62f0c6d6.6621a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1550,"y":460,"wires":[]},{"id":"8ddea5c7ce58bd41","type":"inject","z":"62f0c6d6.6621a8","name":"pwr - get  power data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"pwr","payloadType":"str","x":990,"y":520,"wires":[["8173a6cfcbf7edca"]]},{"id":"155d22f0618d2958","type":"serial request","z":"62f0c6d6.6621a8","name":"","serial":"e6c39153.e8eab8","x":1370,"y":460,"wires":[["1f5815eb4435c35c"]]},{"id":"8173a6cfcbf7edca","type":"function","z":"62f0c6d6.6621a8","name":"add \\n","func":"msg.payload += \"\\n\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1190,"y":520,"wires":[["155d22f0618d2958"]]},{"id":"e6c39153.e8eab8","type":"serial-port","serialport":"COM3","serialbaud":"1200","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

Obviously you will need to change com port accordingly.

1 Like

Thanks for all the responses!

Initially I was just looking for an example of how to send the HEX payload, and didn't even yet realise the issue with changing the BAUD rate after the flow starts.

I'm trying to test if the PWR command will work with a rate of 1200 as @Steve-Mcl suggested, using a modified version of his flow, but getting the following:

image

Here is how my flow is looking:

[{"id":"580e0e34.5a512","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"741a12ab7e85b435","type":"inject","z":"580e0e34.5a512","name":"0D 0A - get command prompt","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"10","topic":"","payload":"[\"0x0D\", \"0x0A\"]","payloadType":"bin","x":410,"y":180,"wires":[["155d22f0618d2958"]]},{"id":"1f5815eb4435c35c","type":"debug","z":"580e0e34.5a512","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":180,"wires":[]},{"id":"8ddea5c7ce58bd41","type":"inject","z":"580e0e34.5a512","name":"pwr - get  power data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"15","topic":"","payload":"pwr","payloadType":"str","x":380,"y":240,"wires":[["8173a6cfcbf7edca"]]},{"id":"155d22f0618d2958","type":"serial request","z":"580e0e34.5a512","name":"Serial Interface","serial":"e6c39153.e8eab8","x":720,"y":180,"wires":[["1f5815eb4435c35c"]]},{"id":"8173a6cfcbf7edca","type":"function","z":"580e0e34.5a512","name":"add \\n","func":"msg.payload += \"\\n\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":240,"wires":[["155d22f0618d2958"]]},{"id":"c79aaf44.ecb93","type":"inject","z":"580e0e34.5a512","name":"Enable Console","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"[\"0x7E\",\"0x32\",\"0x30\",\"0x30\",\"0x31\",\"0x34\",\"0x36\",\"0x38\",\"0x32\",\"0x43\",\"0x30\",\"0x30\",\"0x34\",\"0x38\",\"0x35\",\"0x32\",\"0x30\",\"0x46\",\"0x43\",\"0x43\",\"0x33\",\"0x0D\"]","payloadType":"bin","x":360,"y":120,"wires":[["155d22f0618d2958"]]},{"id":"e6c39153.e8eab8","type":"serial-port","serialport":"/dev/ttyUSB0","serialbaud":"1200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

Is the undefined payloads as a result of me doing something wrong, or due to the 1200 rate not working?

If the above isn't working, @dceejay 's solution of first activating the console externally might be the way to go, but I'm wondering if it will reset "activated console" everytime the serial port disconnects.

I tried connecting directly to the serial port using putty, and a few other serial programs and they all failed, so I suspect the cable I have is incompatible. Will try with a different cable/converter in the near future, and pick this part of the project up again after that. Thanks again for everyone's advice!

I asked my ascii table and got that in true ascii:
~20014682C0048520FCC3\n
No need to send that as hex characters. Simpy send it as plain text.

Just an update. Managed to get the above to work by including the msg.baudrate = property, which allowed me to change between baud rates on the fly, regardless of what baud rate was set on the serial node.

Thats great news! What did you send as property, simply 4800, 9600, 19200 aso?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.