Difference between revisions of "How to use UBUS commands for Bluetooth device scanning / pairing"
PauliusRug (talk | contribs) |
|||
(30 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | This page contains instructions on how to use CLI / SSH command '''UBUS''' for scanning and pairing new Bluetooth devices on RUTX. | |
− | This page contains instructions on how to use | ||
---- | ---- | ||
− | + | The '''ubus''' command line tool allows to interact with the '''ubusd''' server (with all currently registered services). It's useful for investigating/debugging registered namespaces as well as writing shell scripts. For calling procedures with parameters and returning responses it uses the user-friendly JSON format. Below is an '''Help output''' of this command: | |
− | The '''ubus''' command line tool allows to interact with the '''ubusd''' server (with all currently registered services). It's useful for investigating/debugging registered namespaces as well as writing shell scripts. For calling procedures with parameters and returning responses it uses the user-friendly JSON format. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
... | ... | ||
− | root@Teltonika-RUTX11:~# | + | root@Teltonika-RUTX11:~# ubus |
− | + | Usage: ubus [<options>] <command> [arguments...] | |
− | + | Options: | |
− | + | -s <socket>: Set the unix domain socket to connect to | |
− | + | -t <timeout>: Set the timeout (in seconds) for a command to complete | |
− | + | -S: Use simplified output (for scripts) | |
− | + | -v: More verbose output | |
− | + | -m <type>: (for monitor): include a specific message type | |
− | + | (can be used more than once) | |
− | + | -M <r|t> (for monitor): only capture received or transmitted traffic | |
− | + | Commands: | |
− | + | - list [<path>] List objects | |
− | + | - call <path> <method> [<message>] Call an object method | |
− | + | - listen [<path>...] Listen for events | |
− | + | - send <type> [<message>] Send an event | |
+ | - wait_for <object> [<object>...] Wait for multiple objects to appear on ubus | ||
+ | - monitor Monitor ubus traffic | ||
... | ... | ||
+ | ---- | ||
+ | Steps to use '''UBUS''' for Bluetooth on RUTX: | ||
− | * | + | * Enable Bluetooth in Web UI menu '''Network -> Bluetooth -> General'''. Click ''"Save&Apply"''. |
+ | |||
+ | * Login using [[CLI]] and run '''scan.start''' command to start Bluetooth scan: | ||
... | ... | ||
Line 37: | Line 33: | ||
... | ... | ||
− | *To see scan results, use command '''scan.result''': | + | * To see scan results, use command '''scan.result''': |
... | ... | ||
Line 43: | Line 39: | ||
... | ... | ||
− | The scan | + | The scan takes about 30 seconds. The '''"scanning": 1''' output shows us that scan still in progress. You can use '''scan.result''' until '''"scanning": 1'''. You should see similar output: |
... | ... | ||
Line 52: | Line 48: | ||
"name": "RT_T", | "name": "RT_T", | ||
"rssi": -72, | "rssi": -72, | ||
− | "address": "FF:CB: | + | "address": "FF:CB:FA:6A:23:CB" |
} | } | ||
] | ] | ||
Line 58: | Line 54: | ||
... | ... | ||
− | The list of devices always contains '''"rssi"''' and '''"address"''', but '''"name"''' output might be missing | + | |
+ | |||
+ | The list of devices always contains '''"rssi"''' and '''"address"''', but '''"name"''' output might be missing: | ||
... | ... | ||
Line 66: | Line 64: | ||
{ | { | ||
"rssi": -42, | "rssi": -42, | ||
− | "address": " | + | "address": "28:21:06:02:72:AD" |
}, | }, | ||
{ | { | ||
"name": "RT_T", | "name": "RT_T", | ||
"rssi": -77, | "rssi": -77, | ||
− | "address": " | + | "address": "C6:0D:52:5E:35:D7" |
} | } | ||
] | ] | ||
Line 77: | Line 75: | ||
... | ... | ||
− | |||
− | |||
− | |||
− | |||
− | + | Prietaiso „pair’inimas“ su ubus komanda: | |
+ | |||
+ | ubus call blesem pair '{"address":"FF:CB:FA:6A:23:CB"}' | ||
+ | |||
+ | Kuri parodys ar pavyko supair’inti, | ||
+ | |||
+ | klaidos atveju bus: | ||
+ | |||
+ | { | ||
+ | "error": "failed to pair because…." | ||
+ | } | ||
+ | |||
+ | sėkmingu: | ||
− | + | { | |
− | |||
"success": "device successfully paired" | "success": "device successfully paired" | ||
− | + | } | |
− | + | ||
+ | Sėkmingu atveju, automatiškai į blesem config bus įrašoma: | ||
+ | |||
+ | config device | ||
+ | option address "FF:CB:FA:6A:23:CB" | ||
+ | |||
+ | Unpair komanda tiesiog ištrins config device sekciją. | ||
+ | |||
+ | Supai’rintų device stat gavimas ubus komanda: | ||
+ | |||
+ | ubus call blesem stat '{"address":"FF:CB:FA:6A:23:CB"}' | ||
+ | |||
+ | Kuri parodys prietaiso stats, | ||
− | + | klaidos atveju bus: | |
− | + | { | |
− | + | "error": "failed to retrieve status because…." | |
− | + | } | |
− | + | sėkmingu: | |
− | + | { | |
− | |||
"success": "successfully requested status", | "success": "successfully requested status", | ||
"model": "3901", | "model": "3901", | ||
Line 107: | Line 123: | ||
"humidity": 20, | "humidity": 20, | ||
"firmware": "23", | "firmware": "23", | ||
− | + | …. | |
− | + | } | |
− | + | ||
− | [ | + | |
+ | * stat komanda kol kas dar nerealizuota, todėl gali keistis. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | tuoj pasižiūrėsiu pas sau dar kartą. Bet vakar tai tikrai veikė ir dar su JSON RPC padariau | ||
+ | Galėsi irgi į instrukciją įtraukt | ||
+ | |||
+ | { "jsonrpc": "2.0", | ||
+ | "id": 1, | ||
+ | "method": "call", | ||
+ | "params": [ | ||
+ | "727d2dd26ed722a202a3daf2db8fcbcf", "blesem", "scan.result", | ||
+ | {} | ||
+ | ] | ||
+ | } |
Revision as of 12:18, 24 April 2020
Main Page > General Information > Configuration Examples > Hardware application > How to use UBUS commands for Bluetooth device scanning / pairingThis page contains instructions on how to use CLI / SSH command UBUS for scanning and pairing new Bluetooth devices on RUTX.
The ubus command line tool allows to interact with the ubusd server (with all currently registered services). It's useful for investigating/debugging registered namespaces as well as writing shell scripts. For calling procedures with parameters and returning responses it uses the user-friendly JSON format. Below is an Help output of this command:
... root@Teltonika-RUTX11:~# ubus Usage: ubus [<options>] <command> [arguments...] Options: -s <socket>: Set the unix domain socket to connect to -t <timeout>: Set the timeout (in seconds) for a command to complete -S: Use simplified output (for scripts) -v: More verbose output -m <type>: (for monitor): include a specific message type (can be used more than once) -M <r|t> (for monitor): only capture received or transmitted traffic Commands: - list [<path>] List objects - call <path> <method> [<message>] Call an object method - listen [<path>...] Listen for events - send <type> [<message>] Send an event - wait_for <object> [<object>...] Wait for multiple objects to appear on ubus - monitor Monitor ubus traffic ...
Steps to use UBUS for Bluetooth on RUTX:
- Enable Bluetooth in Web UI menu Network -> Bluetooth -> General. Click "Save&Apply".
- Login using CLI and run scan.start command to start Bluetooth scan:
... ubus call blesem scan.start ...
- To see scan results, use command scan.result:
... ubus call blesem scan.result ...
The scan takes about 30 seconds. The "scanning": 1 output shows us that scan still in progress. You can use scan.result until "scanning": 1. You should see similar output:
... { "scanning": 0, "devices": [ { "name": "RT_T", "rssi": -72, "address": "FF:CB:FA:6A:23:CB" } ] } ...
The list of devices always contains "rssi" and "address", but "name" output might be missing:
... { "scanning": 0, "devices": [ { "rssi": -42, "address": "28:21:06:02:72:AD" }, { "name": "RT_T", "rssi": -77, "address": "C6:0D:52:5E:35:D7" } ] } ...
Prietaiso „pair’inimas“ su ubus komanda:
ubus call blesem pair '{"address":"FF:CB:FA:6A:23:CB"}'
Kuri parodys ar pavyko supair’inti,
klaidos atveju bus:
{
"error": "failed to pair because…."
}
sėkmingu:
{
"success": "device successfully paired"
}
Sėkmingu atveju, automatiškai į blesem config bus įrašoma:
config device option address "FF:CB:FA:6A:23:CB"
Unpair komanda tiesiog ištrins config device sekciją.
Supai’rintų device stat gavimas ubus komanda:
ubus call blesem stat '{"address":"FF:CB:FA:6A:23:CB"}'
Kuri parodys prietaiso stats,
klaidos atveju bus:
{
"error": "failed to retrieve status because…."
}
sėkmingu:
{
"success": "successfully requested status", "model": "3901", "battery": 98, "temperature": "20.34", "humidity": 20, "firmware": "23",
…. }
- stat komanda kol kas dar nerealizuota, todėl gali keistis.
tuoj pasižiūrėsiu pas sau dar kartą. Bet vakar tai tikrai veikė ir dar su JSON RPC padariau
Galėsi irgi į instrukciją įtraukt
{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "727d2dd26ed722a202a3daf2db8fcbcf", "blesem", "scan.result", {} ] }