Page 1 of 1

Best/easiest way to read/write IO with Javascript (RevPi Compact)

Posted: 11 Jun 2021, 07:14
by livesource
Hello from New Zealand :)

I just received my first RevPi Compact. I am planning to write my control program in nodejs/javascript. But I have not been able to find an example how to read, write, listen to changes of the IOs with Javascript.

What would you recommend to be the best approach and is there some example code somewhere?

One option I can see is https://github.com/erminas/noderedrevpinodes-server ... although there are no examples how to use it so I will have to go through the code to try work it out.

Another option I can see is to call the shell command

Code: Select all

piTest -r
from nodejs. That could work for me but I don't know what the variable names are that I am trying to read/write. Where can I find that information? For example, I have tried running

Code: Select all

piTest -r DIn_Status
,

Code: Select all

piTest -r RevPiLED
but I'm not having any luck (Cannot find variable 'RevPiLED'). Are these not the correct variable names? https://revolution.kunbus.com/tutorials ... rect=en_US

Thanks for any advice.

Shea

Re: Best/easiest way to read/write IO with Javascript (RevPi Compact)

Posted: 11 Jun 2021, 22:51
by crismancich
Hi Shea,

greetings back from the opposite side of the planet. ;-)

First of all we would love to have a library like the python RevPiModIo in JS, but unfortunately we don't... Yet. Having an SDK for any major language is one of the things on my list.

Before RevPiModIo was provided by Sven Sager, it was also quite common to wrap PiTest. In order to get values, you have to log on to the PI with your browser first. Then open pictory and drag in all modules that you use. The right hand side shows a list with the names available in PiTest. Make sure to save as "start config" and "reset driver". Then piTest will work.

The server you have found is the backend of our nodered nodes. You could use it with websockets. But its not meant for it. It would be easier to write a JS wrapper for RevPiModIo or as you did - wrap piTest.

As were getting more and more requests for JS, I will do what I can to drive the SDKs forward.

Hope this helps.

Best,
Boris

Re: Best/easiest way to read/write IO with Javascript (RevPi Compact)

Posted: 13 Jun 2021, 23:26
by livesource
OK I worked out how to use piTest. I needed to save the configuration in pictory to set the variable names. I think piTest will be the simplest way for me to interact with IO using javascript.

Re: Best/easiest way to read/write IO with Javascript (RevPi Compact)

Posted: 22 Jun 2021, 01:26
by livesource
Thanks for your reply Boris, sorry I didn't actually see that earlier. Great to hear that a JS SDK is something that's being looked into. I could look at packaging up and contributing my js wrapper in the mean time if that's useful. It's working well however one thing I am having an issue with is reading any of the Byte variables... ie. DIn_Status, DOut_Status, RevPiLED all return 00000000 regardless of the actual state.

-----

Example

Code: Select all

piTest -w DOutBit_1,1 
Success - Activates OUT 0 LED on the unit

Code: Select all

piTest -1 -q -r DOutBit_1
Success - Returns "1"

Code: Select all

piTest -1 -q -r DOut_Status,b
Fail - Returns "00000000"
I Expected - "10000000" from this. Have I got something wrong here? How can I read all the DOut_x bits in one piTest command?

-----

Thanks for any suggestions!