Using SignalK and Node-RED to enable and disable switch ports on a Ubiquiti Edge Router

Previously I wrote about the challenges of internet access and how I display the active internet service. In this followup I’ll tell you how I added the ability to enable and disable the ports associated with the service. In this way I can force which service is used or prevent the expensive satellite internet from being used while we are moored.

In order for this to work you will need a few things. SignalK, Node-RED (installed along with SignalK), the signalk-n2k-virtual-switch plugin, and of course a Ubiquiti Edge Router.

I’m assuming that you already installed the Node-RED nodes node-red-node-snmp and node-red-contrib-bigssh.

I’m also assuming you have either already configured SNMP on your router or you understand how to do so. If you need assistance, please checkout the excellent article from Ubiquiti on Configuring SNMP using the Command Line.

  1. Download interface.sh script file from GitHub and save a copy to your router in /config/scripts/interface.sh.
  2. Login to SignalK and make sure you have the signalk-n2k-virtual-switch plugin installed and configured.
  3. Launch the Node-RED admin page from SignalK.
  4. You are now going to import the flow which checks the interface admin state as well as enable or disable the interface. Select the Import option. . 
  5. You will see the following dialog box open. 
  6. Copy the flow from GitHub and paste the code into the dialog box.
  7. Select new flow and click Import.
  8. You should now have a flow that looks like:undefined
  9. Now we need to set the ip address, username, and password for your router. Double-click on the “change interface state” node. Then click on the edit button that appears.
  10. Enter the IP Address, username, and password. Then click Add and then Done.
  11. Edit the “Interface Admin Status” node to set the Host and Community. Then click Done.undefined
  12. Click on  in the upper right hand screen.
  13. You should now be able to click on the button of the Inject node to execute the flow.

The interface state will update the following paths as outlined in the table below. This is just what I happen to use, but feel free to modify the switch bank and switch number as you see fit for your usage.

InterfaceSignalK Path
eth0electrical.switches.bank.101.16.state
eth1electrical.switches.bank.101.17.state
eth2electrical.switches.bank.101.18.state
Router Interface to SignalK Path Mapping

At this point the interface status will updated every minute. You can then choose to display the status on your favorite UI compatible with either SignalK or NMEA Switch Bank Status PGN 127501. The interface can also now be controlled via SignalK or NMEA Switch Bank Control PGN 127502 or Command PGN 126208 (like Maretron and some others do).

Here is an example of a page I created in Maretron N2KView.

1 thought on “Using SignalK and Node-RED to enable and disable switch ports on a Ubiquiti Edge Router

  1. Pingback: Using SignalK and Node-RED to Check the Active Internet Service on Ubiquiti Edge Router | Adventure NOT Vacation

Leave a Reply

Your email address will not be published. Required fields are marked *