Simplest way to move data, SoftPac to Node-Red


How can we move data from SoftPAC (running strategy) to Node-Red?

I wish SoftPac has REST api, but my last option is to use text/csv file.

Any other Idea?

Yes, I wish it had one too. Its complicated, so perhaps one day, but for now, we work with what we have or haven’t got.

The best way to get data to Node-RED from SoftPAC is to use files.

Node-RED has both a file watch node and a file read node, so it can be pointed at the directory of interest and when a file is written you can pass the file name to the read node and thus read the file into Node-RED.
It looks something like this;

As you can see, its pretty straight forward to detect new files and then read them into Node-RED.
What you do with it from there is up to you.

The windows folder watch Node is here;

The file in and change nodes are part of the core nodes, so are already installed.

1 Like

It is possible to get data out of SoftPAC using forth commands from Node-Red using the tcp request function node. Here is an example that retrieves an integer called “Status_Trashcan” from SoftPAC.

[{"id":"54fcb9c5.ffd36","type":"debug","z":"7e05e28a.84a09c","name":"","active":true,"console":"false","complete":"false","x":643,"y":234,"wires":[]},{"id":"8ceebd76.85bea8","type":"inject","z":"7e05e28a.84a09c","name":"Request integer","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":156,"y":300,"wires":[["430381f3.cdf7d8"]]},{"id":"bf716770.280b2","type":"debug","z":"7e05e28a.84a09c","name":"","active":false,"console":"false","complete":"false","x":495,"y":319,"wires":[]},{"id":"430381f3.cdf7d8","type":"function","z":"7e05e28a.84a09c","name":"Request integer forth command","func":"msg.payload = \"A ^Status_Trashcan @@ .\\r\"\nreturn msg;","outputs":1,"noerr":0,"x":305,"y":231,"wires":[["bf716770.280b2","733b8d0c.c5c184"]]},{"id":"733b8d0c.c5c184","type":"tcp request","z":"7e05e28a.84a09c","server":"","port":"22001","out":"char","splitc":" ","name":"Wait for a space character","x":397,"y":173,"wires":[["cd0e2674.1764f8"]]},{"id":"cd0e2674.1764f8","type":"function","z":"7e05e28a.84a09c","name":"Parse result string","func":"//msg.payload will lead with a couple null values\nvar sRaw = msg.payload.slice(2);\n\nvar i = parseInt(sRaw, 10);\nmsg.payload = i;\n\nreturn msg;","outputs":1,"noerr":0,"x":629,"y":135,"wires":[["54fcb9c5.ffd36"]]}]

Thank you as usual to Beno and Philip.

@philip Probably TCP call you recommend is better than reading a text file.
I did not understand the forth command and parsing, but it amazingly worked. That is cool. Thanks.
I changed the “Status_Trashcan” to my softpac variable called “nValid” and it Worked.

when nValid is 1, Node-red will go ahead and read file (more data).

Thank you. This solves the problem.

:slight_smile: Understood - I grabbed the command from wireshark. I have others for other data types/tables etc. if you need them.

Using the Node-RED method in my first reply, as soon as the file is written, the Node-RED watch Node picks it up.
No need to have a trigger… so you don’t need the Forth flow…
(FYI. I cant not recommend or support the Forth method - even though it may work for you at the moment, Opto reserves the right to change it without notice at any time).

True, but then every previous PAC Control and PAC Display version would quit working too, so…

Missed this, So you do recommend it then??

I don’t know, my instinct says, there is something wrong with the following option:
Read file if and only if when directory change.

I rather want to read file every sec.
But Philip suggested use TCP to read data.
If you ask me, reading file via TCP (1 step) is more straight forward than reading file which was written (2 steps) - do this every sec.