Wall switch - with Evok
devmicha last edited by devmicha
I have a simple question. I have one wall switch (toggle wall switch type) connected to digital input and 6 lights connected to 6 relays / relay outputs to UniPi. I would like the wall switch to toggle (turn on or off) 6 lights when it's pressed. The lights can not be connected to one single relay because I would like to control lights separately from web interface ('direct switch' not very useful).
What is the most optimal way to implement this scenario using evok (and python)? The most popular method is REST Api - however checking the digital input several times per second and switching on the lights when detecting changes on digital input (using GET requests) does not seem to be the optimal way... CPU consumption and temperature can be high. But what are the alternatives? Does using websockets from Evok Api cause a similar processor load as Rest Api and is this the best solution?
Is it possible to directly communicate with hardware and read a single digital input using for example i2c or spi? Is it possible to read this in the evok code and if so in which files? This is what bothers me in the recent days
The infrastructure looks like this:
IOs -> (SPI) -> ModbusTCP server -> (ModbusTCP) -> Evok -> (REST, WebSockets,...) -> your code
- The ModbusTCP server (unipitcp service) is polling the complete status of underlying HW via SPI. This happens very quickly, in less than milisecond interval.
- The Evok aggregates data from the ModbusTCP server and from the owfs (for 1-Wire devices).
- Your application can poll data from the Evok in multiple ways (REST, WebSockets,...)
As you can see, the Evok doesn't communicate with the HW directly. We discussed the possibility of custom software pulling the SPI in this thread: https://forum.unipi.technology/topic/711/reading-spidev
I fully understand your concerns about infinite polling data over GET requests. This is generally slow and causes high load on the PLC. The WebSocket offers you a way to subscribe to updates of the IO. You can poll the complete status of the PLC at any time and yet you can listen to updates and act accordingly. Check the documentation and example: https://evok-9.api-docs.io/1.08/ubmjnyexu77wxwo4q/websocket.