Lucifer06 / RemoteGPIO

Remote General Purpose I/O for Venus OS devices (Cerbo GX, ...)
12 stars 3 forks source link

**** RemoteGPIO * PLEASE READ IMPORTANT INFORMATION **** * INSTALL/SETUP INSTRUCTIONS BELOW ****


Raspberry is partially supported: Relay is OK, DigitalInputs is KO CerboGX is confirmed to perfectly work Don't know for any other GX devices Thanks to drtinaz for the optimisations added since first v3.x release

***** UPDATE as of v3.3.0 **

Several settings menu enhancements. Added option to enable/disable digital inputs per module. Added option to 'Restart RemoteGPIO' from the menu. Overall cpu usage can be reduced by up to 75% depending on number of modules and options selected.

***** UPDATE as of v3.2.1 **

Now supports reading of external relay state and dynamically updating the gui. (Useful for those people who have methods of switching the relays from external sources, such as switches connected directly to the relay modules). If using node-red logic to control the external relays, it is important that you also include a debounce method to eliminate looping. This feature is disabled by default and can be enabled from within RemoteGPIO settings.

***** UPDATE As of v3.2 ****

RemoteGPIO is now working with up to 3 relay modules, with a total of up to 16 relays/inputs across all connected/active modules. Number of modules and relays per module can be changed dynamically from the RemoteGPIO menu in gui (menu>IO>RemoteGPIO).

Each module may select 2, 4 or 8 relays/inputs. You may select any combination of modules and number of relays/inputs for each module as long as the total number of relays/inputs accross all connected/active modules does not exceed 16x.

***** NEW VERSION 3.x **

RemoteGPIO is now working natively with D-Bus and no longer requires Node-Red to be installed. Built in relays and additionnal relays (up to a total of 18) are displayed on a single scrolling Relay Overview page (Thank you to Kevin Windrem and GuiMods). Additional Digital Inputs are also supported and available for configuration via the IO/Digital Inputs settings page.

In previous version the « driver » for controlling the relays was implemented in Node-Red. Now the driver is integrated as native D-Bus and is running as a service in Venus OS.

Node-Red is still useful for adding any logics to turn on or off any relays based on external dependencies. These changes are reducing the CPU load (about 4% usage) and are decreasing latency. (Latency can be set in RemoteGPIO configuration menu high/medium/low).

It is recommended to use USB adapters based on FTDI FT232R chipset and program it with Product Description = "RemoteGPIO"


** INSTALLATION INSTRUCTIONS ****


1: If Package Manager and GuiMods is already installed and running, skip to step 3.

2: Install Kevin Windrem's setup helper. Refer to Kevin's github for instructions. https://github.com/kwindrem/SetupHelper

2: Install GuiMods: a: Go to settings>package manager>inactive packages b: Find GuiMods in the list and add it to active packages c: Wait until GuiMods installs and reboots the gui

3: Install RemoteGPIO a: Go to settings>package manager>inactive packages. b: Find RemoteGPIO in the list and add it to active packages. (If RemoteGPIO is not on the list, it can be added manually > Package Name:RemoteGPIO githubusername:Lucifer06 branch/tag:main) c: Once install is complete, the system will reboot.

4: Enable and configure RemoteGPIO a: Go to menu>IO>RemoteGPIO and enable RemoteGPIO. b: Select number of relay modules c: For each module unit select the protocol, USB port (if using rs485), IP address of the module, and the number of relays for each module. d: Reboot the venus device

** OLD ****

This package is mainly targeting Cerbo GX users that wants to extend Digital Inputs and Relays on their system. Please note that there is a conflict with Kwindrem's RpiGpioSetup that is targeting Raspberry pi users

In order to have a reliable direct attached interface to the relay, I selected a Modbus/RTU based relai from Dingtian that attaches on the USB port of the Cerbo GX. There are many solutions for attaching relays via Ethernet, but I didn't the relays to rely on an external Ethernet network switch.

This Dingtian box provide 8x relays, that can be controlled with Modbus Serial, but also over IP and with various additional protocols: https://fr.aliexpress.com/item/4000999069820.html They have variants of 4 or 8 relays. A USB to RS 485 adapter will be required. I selected this one as this is coming with a USB cable and can fit nicely on the Cerbo GX: https://fr.aliexpress.com/item/1005004778767986.html The RS485 must be connected on the first USB port of the Cerbo GX

SETUP:

The setup is now fully automated, no more requirement to issue shell commands! :-) It runs only with VenusOS Large with minimum version 2.92

1/ Configure the Relay Module The Dingtian IOT Relay module needs to be configured so Modbus RTU works: Connect the ethernet interface of the module and access to its configuration page (192.168.1.100 and admin/admin by default). Configure the RS485 with Protocol Modbus-RTU and set address to 1 (for the first unit).

2/ VenusOS Large Install the desired VenusOS Large version (minimum v2.92) Enable Node-RED (Settings/Venus OS Large features)

3/ Install RemoteGPIO Make sure SetupHelper from Kwindrem is installed. If not follow instructions from https://github.com/kwindrem/SetupHelper Add RemoteGPIO repo if not already listed in the inactive packages RemoteGPIO Lucifer06:main Download and install the package BE PATIENT during the Installation of the package, it can takes few minutes as it downloads few Node-RED palettes Reboot will be required for the USB to be not anymore preempted by VenusOS services

Using RemoteGPIO:

1/ RemoteGPIO can be used from VenusOS GUI to control 4x additional relays. It is required to install Kwindrem's GuiMods package (https://github.com/kwindrem/GuiMods) Go to Settings/Relay there are 4x additional relays to be enabled and then use the dedicated Relay page that should display the additional relays

2/ RemoteGPIO can also be used with Node-RED With Node-Red it is possible to use all 8x relays as well as the 8x digital inputs During the installation of the package, the following Node-RED palettes are automatically installed: — node-red-dashboard — node-red-contrib-buffer-parser — node-red-contrib-debounce If there was no flows yet running the RemoteGPIO flow got installed If a flow was already installed, in order to not break anything RemoteGPIO will need to be manually imported from the local library (Menu Import / Local / RemoteGPIO.json) The RemoteGPIO flow is also adding a Node-RED dashboard for controlling the Relays and monitoring the Digital Inputs RemoteGPIO v2.x is backward compatible with previous venus_rgpio (https://community.victronenergy.com/questions/166784/solution-adding-external-relays-to-cerbo-gx-using.html).

Troubleshooting:

Any questions or suggestions about RemoteGPIO are welcome here: https://community.victronenergy.com/questions/245584/remotegpio-ex-venus-rgpio-now-available-with-setup.html

Most of the issues are coming from USBtoRS485 adapter been trapped by the wrong VenusOS service. In order to make it working with default configuration file, it is important to attach it to the first USB port. IMPORTANT If a different adpater is used, or if a different USB port is used (or connected behind a USB hub) the file /etc/udev/rules.d/serial-starter.rules will required to be tweaked accordingly so the USB-RS485 adpater is always accesible with /dev/ttyUSB0

Toubleshooting from command line with dbus List of all dbus relays and their status: dbus -y com.victronenergy.system /Relay GetValue Close Relay 3: dbus -y com.victronenergy.system /Relay/3/State SetValue %1

Toubleshooting from command line with modbus Read Digital Inputs: /data/rgpio/modpoll/arm-linux-gnueabihf/modpoll -m rtu -b 115200 -p none -d 8 -r 11 -s 1 -c 1 /dev/ttyUSB0 Close Relay 1: /data/rgpio/modpoll/arm-linux-gnueabihf/modpoll -m rtu -b 115200 -p none -d 8 -1 -r 3 -s 1 -c 1 /dev/ttyUSB0 257 Open Relay 1: /data/rgpio/modpoll/arm-linux-gnueabihf/modpoll -m rtu -b 115200 -p none -d 8 -1 -r 3 -s 1 -c 1 /dev/ttyUSB0 256

Check that no process are talking to USB0: ps | grep USB0 Should return only rgpio services. If not, it may be required to reboot VenusOS for the serial-starter.rules to apply

Prevent USB0 to be used by another service: /opt/victronenergy/serial-starter/stop-tty.sh ttyUSB0