Relay expansion
-
Hello guys.
Is it possible to read the state of a relay?
I cant seem to figure this out?
-
@Samuel-Mathieson Yes, this is definitely possible, but it's not implemented in the Relay Expansion C library or the Python module yet.
Definitely an oversight that we will be correcting in the near future. For now you can look at the source code to reverse engineer the read.
We'll let you know when the functions have been added to the libraries!
Gabe
-
Ok,
I figured out that you can use the following command to read the relay states:
i2cdump -y i2c-gpio0 0x26 (or some other address)Is there any way to use the "I2C block" option to read the 00x9 block? Or do I have to parse the output?
-
Ok, here is a command that will get the relay state of a block, however it is rather hacky.
In case anyone wants to use:
i2cdump -y i2c-gpio0 0x23 i|grep 00:|awk '{print $11}'Will give you a decimal of the binary representation of the relay.
-
I've got around it for my applications by just writing a text file containing the state each time any of the scripts I wrote perform a relay-exp command.
A bit of extra work but has worked fine as a workaround.
-
Yes, I do the same. But it has always bothered me. Now I just have a helper function that gets the relay states using this command. I am not quite as happy as with a built in function, but better than saving it myself.
-
One bug I think I found is if I have a cron that fires the two relays (or more?) at once but a setup as separate cron commands for each - sometimes both relays fail to change state.
Since inserting a delay into the second command the problem hasn't cropped up again.
Might be something Onion want to look at (Collision of concurrent i2c requests?)
-
@None-None yeah... if two processes try to write to the the i2c sysfs file at the same time, it would make sense that the transmissions collide and get garbled so the commands don't actually take effect.
Not much we can do about that!
-
Hey @Samuel-Mathieson,
We've updated the Relay Expansion libraries to be able to read the current state of a specified relay.
This includes updates to therelay-exp
command line tool, the C library, and the Python Module. The documentation is updated as well.To grab the latest code, either upgrade to the latest firmware, or run:
opkg update opkg upgrade libonionrelayexp relay-exp pyRelayExp
-
Great! Thanks very much!