Difference between revisions of "How to use UBUS commands for Bluetooth device scanning / pairing"

From Teltonika Networks Wiki
Line 5: Line 5:
 
  ...
 
  ...
 
  root@Teltonika-RUTX11:~# ubus
 
  root@Teltonika-RUTX11:~# ubus
  Usage: ubus [<options>] <command> [arguments...]
+
  Usage: ubus [<options>] <nowiki><command></nowiki> [arguments...]
 
  Options:
 
  Options:
 
  -s <socket>:          Set the unix domain socket to connect to
 
  -s <socket>:          Set the unix domain socket to connect to
Line 19: Line 19:
 
  - listen [<path>...]                  Listen for events
 
  - listen [<path>...]                  Listen for events
 
  - send <type> [<message>]              Send an event
 
  - send <type> [<message>]              Send an event
- wait_for <object> [<object>...]      Wait for multiple objects to appear on ubus
+
- wait_for <nowiki><object> [<object>...]      Wait for multiple objects to appear on ubus</nowiki>
 
  - monitor                              Monitor ubus traffic
 
  - monitor                              Monitor ubus traffic
 
  ...
 
  ...
Line 25: Line 25:
 
Steps to use '''ubus''' for '''blesem''' service on RUTX:
 
Steps to use '''ubus''' for '''blesem''' service on RUTX:
  
* Enable Bluetooth in Web UI menu '''Network -> Bluetooth -> General'''. Click ''"Save&Apply"''.
+
*Enable Bluetooth in Web UI menu '''Network -> Bluetooth -> General'''. Click ''"Save&Apply"''.
 
 
 
 
 
    
 
    
* Login using [[CLI]] and run '''scan.start''' command to start Bluetooth scan:
+
*Login using [[CLI]] and run '''scan.start''' command to start Bluetooth scan:
  
 
  ...
 
  ...
Line 35: Line 33:
 
  ...
 
  ...
  
* To see scan results, use command '''scan.result''':
+
*To see scan results, use command '''scan.result''':
  
 
  ...
 
  ...
Line 75: Line 73:
 
  ...
 
  ...
  
* Device pairing command:
+
*Device pairing command:
  
 
  ...
 
  ...
Line 96: Line 94:
 
  ...
 
  ...
  
* Device unpairing command:
+
*Device unpairing command:
  
 
  ...
 
  ...
Line 102: Line 100:
 
  ...
 
  ...
  
* To get statistic from paired devices, use '''stat''' command:
+
*To get statistic from paired devices, use '''stat''' command:
  
 
  ...
 
  ...

Revision as of 13:07, 24 April 2020

Main Page > General Information > Configuration Examples > Hardware application > How to use UBUS commands for Bluetooth device scanning / pairing

This 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 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 blesem service 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. After it finish 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" 
              } 
      ] 
}
...
  • Device pairing command:
...
ubus call blesem pair '{"address":"FF:CB:FA:6A:23:CB"}'
...

On success pairing you should see output:

...
{ 
      "success": "device successfully paired" 
}
...

On success pairing new device info will be written in blesem service config:

...
     config device
            option address "FF:CB:FA:6A:23:CB"
...
  • Device unpairing command:
...
ubus call blesem unpair '{"address":"FF:CB:FA:6A:23:CB"}'
...
  • To get statistic from paired devices, use stat command:
...
ubus call blesem stat '{"address":"FF:CB:FA:6A:23:CB"}'
...

You should see output:

...
{ 
      "success": "successfully requested status",
      "model": "3901",
      "battery": 98,
      "temperature": "20.34",
      "humidity": 20,
      "firmware": "23",
.
}
...