Hurricos / realtek-poe

5 stars 10 forks source link

how to switch specific port on or off? #30

Closed bittorf closed 1 year ago

bittorf commented 1 year ago
root@switch-realtek-838x-zyxel-gs1900-8hp:~# cat /etc/openwrt_release 
DISTRIB_ID='OpenWrt'
DISTRIB_RELEASE='SNAPSHOT'
DISTRIB_REVISION='r23079-5636ffc22d'
DISTRIB_TARGET='realtek/rtl838x'
DISTRIB_ARCH='mips_4kec'
DISTRIB_DESCRIPTION='OpenWrt SNAPSHOT r23079-5636ffc22d'
DISTRIB_TAINTS=''

root@switch-realtek-838x-zyxel-gs1900-8hp:~# ubus -v list poe
'poe' @68c5f575
    "info":{}
    "reload":{}
    "sendframe":{"frame":"String"}
    "manage":{"port":"String","enable":"Boolean"}

root@switch-realtek-838x-zyxel-gs1900-8hp:~# ubus call poe info
{
    "firmware": "v22.4",
    "mcu": "ST Micro ST32F100 Microcontroller",
    "budget": 170.000000,
    "consumption": 0.000000,
    "ports": {
        "lan1": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Searching"
        }
    }
}

# trying to switch a port OFF:
root@switch-realtek-838x-zyxel-gs1900-8hp:~# ubus call poe manage "{\"port\":\"lan1\","enable":\"false\"}"
Command failed: Parsing message data failed

i am sure my syntax is wrong,
can sombody please give a working example?

mrnuke commented 1 year ago
ubus call poe manage ' { "port" : "lan1", "enable" : true }'
ubus call poe manage ' { "port" : "lan1", "enable" : false }'
Hurricos commented 1 year ago

root@switch-realtek-838x-zyxel-gs1900-8hp:~# ubus call poe info { "firmware": "v22.4", "mcu": "ST Micro ST32F100 Microcontroller", "budget": 170.000000, "consumption": 0.000000, "ports": { "lan1": { "priority": 2, "mode": "PoE+", "status": "Searching" } } }

"Searching" tells me what I need to know: your PoE device hasn't responded to the low-level protocol to request power in the first place. The port is nevertheless enabled.

FWIW Sometimes this comes out of a port mapping issue, I believe we've tested the GS1900-8HP though.

bittorf commented 1 year ago

thanks a lot @mrnuke - my mistake was really,
that \"enable\" was not correctly escaped,
so both are working:

ubus call poe manage '{ "port" : "lan1", "enable" : false }'
or
ubus call poe manage "{ \"port\" : \"lan1\", \"enable\" : true }"
bittorf commented 1 year ago

for the record, after writing a full configfile,
i can switch off and on all ports using above method - bravo!

root@switch-realtek-838x-zyxel-gs1900-8hp:~# cat /etc/config/poe
config global
    option budget   '170'

config port
    option enable   '1'
    option id   '1'
    option name 'lan1'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '2'
    option name 'lan2'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '3'
    option name 'lan3'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '4'
    option name 'lan4'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '5'
    option name 'lan5'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '6'
    option name 'lan6'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '7'
    option name 'lan7'
    option poe_plus '1'
    option priority '2'

config port
    option enable   '1'
    option id   '8'
    option name 'lan8'
    option poe_plus '1'
    option priority '2'
bittorf commented 1 year ago

a full info dump including all 8 ports looks like this.
spot the ports 2, 4 and 8, which are enabled AND active.

oot@switch-realtek-838x-zyxel-gs1900-8hp:~# ubus call poe info
{
    "firmware": "v22.4",
    "mcu": "ST Micro ST32F100 Microcontroller",
    "budget": 170.000000,
    "consumption": 0.400000,
    "ports": {
        "lan1": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Searching"
        },
        "lan2": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Delivering power",
            "consumption": 3.700000
        },
        "lan3": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Disabled"
        },
        "lan4": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Delivering power",
            "consumption": 2.900000
        },
        "lan5": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Disabled"
        },
        "lan6": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Searching"
        },
        "lan7": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Disabled"
        },
        "lan8": {
            "priority": 2,
            "mode": "PoE+",
            "status": "Delivering power",
            "consumption": 0.400000
        }
    }
}