HowTo: Add a new Luci checkbox and edit /etc/config/system

I am compiling V19.07.4 just fine.

The Ubiquiti NS-5AC (https://openwrt.org/toh/ubiquiti/ubiquiti_nanostation_ac) has a secondary PoE port that is controlled by this section in /etc/config/system

config gpio_switch 'poe_passthrough'
        option name 'PoE Passthrough'
        option gpio_pin '3'
        option value '0'

But the current Luci does not allow editing of this section.

So my objective is to add a checkbox to the System/System page for that purpose.

I am a pretty good programmer ... but a bit lost working out:

  1. which file to edit to add my checkbox
  2. which file(s) to edit to cause the config file to be edited when clicking [Save & Apply] or [Save]

Any advice to get me started on the right track appreciated.

Rob

1 Like

Solved.
Documenting here to help others with same question.

In file:
feeds/luci/modules/luci-mod-system/htdocs/luci-static/resources/view/system/system.js

Added:

  if(uci.get('system','poe_passthrough')) {
                        o = s.taboption('general', form.Flag, 'value', _('Enable POE Passthrough<br>(24V from Main to Secondary)'));
                        o.ucisection = 'poe_passthrough';
                }

This code not only displayed the new checkbox in System / System, but also updated /etc/config/system on [Save & Apply]. And yes: the PoE passthrough was controlled as expected.

4 Likes

Hi,

It is working. Only I have one question. For my POE i have to set the GPIO to 0 to enable, and to 1 to disable. How can this be change in your code for LUCI?

o.enabled = '0';
o.disabled = '1';

Will the code than be this?

if(uci.get('system','poe_passthrough')) {
                        o = s.taboption('general', form.Flag, 'value', _('Enable POE Passthrough<br>(24V from Main to Secondary)'));
                        o.ucisection = 'poe_passthrough';
                        o.enabled = '0';
                        o.disabled = '1';
                }

Yes. You might also need o.forcewrite = true; if an absent option does not default to 0

1 Like

It works thnx .