custom-api OpenWRT #742
-
Why not clear dict/json? How I can get Full json: {{{"jsonrpc":"2.0","id":1,"result":[0,{"freq":5320,"clients":{"84:c5:a6:2b:42:42":{"auth":true,"assoc":true,"authorized":true,"preauth":false,"wds":false,"wmm":true,"ht":true,"vht":true,"he":false,"wps":false,"mfp":false,"mbo":false,"rrm":[113,0,0,0,0],"extended_capabilities":[4,0,202,2,1,64,0,192,1,33],"aid":2,"signature":"wifi4|probe:0,1,45,127,191,221(0050f2,4),221(506f9a,9),114,221(506f9a,22),221(0050f2,8),htcap:19ef,htagg:17,htmcs:0000ffff,vhtcap:039071f6,vhtrxmcs:0000fffa,vhttxmcs:2000fffa,extcap:0400ca02014040c0012120,wps:_|assoc:0,1,33,36,48,45,127,191,54,70,59,221(0050f2,2),htcap:19e7,htagg:17,htmcs:0000ffff,vhtcap:039071f6,vhtrxmcs:0000fffa,vhttxmcs:2000fffa,txpow:1600,extcap:0400ca02014000c00121","bytes":{"rx":54934752,"tx":153999589},"airtime":{"rx":6391824,"tx":151681010},"packets":{"rx":116416,"tx":159396},"rate":{"rx":173330000,"tx":156000000},"signal":-47,"capabilities":{"vht":{"su_beamformee":true,"mu_beamformee":true,"mcs_map":{"rx":{"1ss":9,"2ss":9,"3ss":-1,"4ss":-1,"5ss":-1,"6ss":-1,"7ss":-1,"8ss":-1},"tx":{"1ss":9,"2ss":9,"3ss":-1,"4ss":-1,"5ss":-1,"6ss":-1,"7ss":-1,"8ss":-1}}}}},"f2:74:41:ef:c1:89":{"auth":true,"assoc":true,"authorized":true,"preauth":false,"wds":false,"wmm":true,"ht":true,"vht":true,"he":false,"wps":false,"mfp":false,"mbo":false,"rrm":[115,16,145,0,4],"extended_capabilities":[4,0,0,2,0,0,0,64,0,0],"aid":1,"signature":"wifi4|probe:0,1,45,127,191,255,221(506f9a,22),htcap:016f,htagg:13,htmcs:000000ff,vhtcap:339179b2,vhtrxmcs:0186fffe,vhttxmcs:0186fffe,extcap:04000a82004000408001|assoc:0,1,33,36,70,48,54,55,59,45,127,191,221(0050f2,2),221(8cfdf0,1),htcap:0163,htagg:13,htmcs:000000ff,vhtcap:339179b2,vhtrxmcs:0186fffe,vhttxmcs:0186fffe,txpow:1808,extcap:04000002000000400000","bytes":{"rx":8449360,"tx":182025098},"airtime":{"rx":4506715,"tx":9087632},"packets":{"rx":53303,"tx":135496},"rate":{"rx":43330000,"tx":39000000},"signal":-59,"capabilities":{"vht":{"su_beamformee":true,"mu_beamformee":true,"mcs_map":{"rx":{"1ss":9,"2ss":-1,"3ss":-1,"4ss":-1,"5ss":-1,"6ss":-1,"7ss":-1,"8ss":-1},"tx":{"1ss":9,"2ss":-1,"3ss":-1,"4ss":-1,"5ss":-1,"6ss":-1,"7ss":-1,"8ss":-1}}}}}}}]}} 0xc0001ea000} - type: custom-api
title: OpenWRT Clients
cache: 30s
template: |
{{
$auth := newRequest "http://ax6000.lan/ubus"
| withHeader "Content-Type" "application/json"
| withStringBody `{
"jsonrpc": "2.0",
"id": 1,
"method": "call",
"params": [
"00000000000000000000000000000000",
"session",
"login",
{
"username": "root",
"password": "1234"
}
]
}`
| getResponse
}}
{{ if eq $auth.Response.StatusCode 200 }}
{{ $token := $auth.JSON.String "result.1.ubus_rpc_session" }}
{{
$clientsReqBody := printf `{
"jsonrpc": "2.0",
"id": 1,
"method": "call",
"params": [
"%s",
"hostapd.phy1-ap0",
"get_clients",
{}
]
}` $token
}}
{{
$req := newRequest "http://ax6000.lan/ubus"
| withHeader "Content-Type" "application/json"
| withStringBody $clientsReqBody
| getResponse
}}
{{ if eq $req.Response.StatusCode 200 }}
{{ $result := $req.JSON.Array "result.1.clients" }}
{{ len $result }} {{ $result }}
{{ end }}
{{ end }} |
Beta Was this translation helpful? Give feedback.
Answered by
ralphocdol
Jun 23, 2025
Replies: 1 comment 1 reply
-
I believe For clarity's sake, Author is trying to get the length of clients which is an object, not an array: "clients": {
"84:c5:a6:2b:42:42": { }
"f2:74:41:ef:c1:89": { }
} Referencing PR: #746 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
CakesTwix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe
len
only works on array. Though I am interested in this API now, I tried looking for a way but can't find one. Even GJson doesn't seem to have a way around this.For clarity's sake, Author is trying to get the length of clients which is an object, not an array:
Referencing PR: #746