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

From Teltonika Networks Wiki
(32 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Introduction==
+
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 '''ubus''' commands in [[CLI]] / SSH to scan and pair '''Bluetooth''' devices on '''RUTX10/11'''.
 
  
 
----
 
----
 
+
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.  
 
 
 
----
 
Before you start using ubus commands to control Bluetooth, make sure to enable it first. You can do that in '''Network → Bluetooth → General''' settings. Click '''Enable Bluetooth''' and press '''Save & Apply'''.
 
 
 
[[File:Networking_rutx_configuration_example_bluetooth_enable_v1.png]]
 
 
 
*Now login to [[CLI]] or SSH and initialize blesemd, run '''blesemd -D''' command:
 
 
 
 
  ...
 
  ...
  root@Teltonika-RUTX11:~# blesemd -D
+
  root@Teltonika-RUTX11:~# ubus
  Initializing blesemd...
+
  Usage: ubus [<options>] <command> [arguments...]
  Warning: debug messages will be shown!
+
Options:
  Preparing bluetooth interface...
+
  -s <socket>:           Set the unix domain socket to connect to
  Reading config...
+
  -t <timeout>:          Set the timeout (in seconds) for a command to complete
  Devices loaded: 0
+
  -S:                    Use simplified output (for scripts)
  Creating database...
+
  -v:                   More verbose output
  modbus_data table already exists
+
  -m <type>:            (for monitor): include a specific message type
  SENT_ID_TABLE already exists
+
                        (can be used more than once)
  Create DB done
+
  -M <r|t>              (for monitor): only capture received or transmitted traffic
  Initializing uloop...
+
  Commands:
  Connecting to ubus...
+
  - list [<path>]                        List objects
  Initializing BLE device...
+
  - call <path> <method> [<message>]    Call an object method
  Initializing BLE ubus interface...
+
  - listen [<path>...]                  Listen for events
  Adding ubus object...
+
  - 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:
  
*Run '''scan.start''' command to start Bluetooth scan:
+
* 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 process takes about 30 seconds. If you can see '''"scanning": 1''' in the output, it means, that scanning is still in progress. After it finishes you should see a similar output:
+
You should see similar results format like this:
  
 
  ...
 
  ...
Line 52: Line 48:
 
                       "name": "RT_T",  
 
                       "name": "RT_T",  
 
                       "rssi": -72,  
 
                       "rssi": -72,  
                       "address": "FF:CB:FF:6F:23:FB"
+
                       "address": "FF:CB:FA:6A:23:CB"  
              }
 
      ]
 
}
 
...
 
 
 
The list of devices always contains '''"rssi"''' and '''"address"''', but '''"name"''' output might be missing if the device is not supported:
 
 
 
...
 
{
 
      "scanning": 0,
 
      "devices": [
 
              { 
 
                      "rssi": -42,
 
                      "address": "2F:2A:0A:0A:7A:AA"
 
              },
 
              {
 
                      "name": "RT_T",
 
                      "rssi": -77,
 
                      "address": "CF:0A:52:5E:35:D7"  
 
 
               }  
 
               }  
 
       ]  
 
       ]  
Line 77: Line 54:
 
  ...
 
  ...
  
*In order to pair devices use this command:
+
Skanavimas vyksta apie 30sek., todėl su „scanning“ rodoma ar vis dar yra vykdomas skanavimas. Šiuo atveju, galima užklausinėti „scan.result“ kol „scanning“ = 1.
 
 
...
 
ubus call blesem pair '{"address":"FF:CC:FF:6A:23:CB"}'
 
...
 
 
 
If the pairing process was successful you should see this output:
 
 
 
...
 
{
 
      "success": "device successfully paired"
 
}
 
...
 
 
 
*To get the statistics from paired devices, use '''stat''' command:
 
 
 
...
 
ubus call blesem stat '{"address":"FF:CB:FA:6A:23:CB"}'
 
...
 
 
 
You should see similar output:
 
 
 
...
 
{
 
      "success": "successfully requested status",
 
      "model": "3901",
 
      "battery": 98,
 
      "temperature": "20.34",
 
      "humidity": 20,
 
      "firmware": "23",
 
.
 
}
 
...
 
[[Category:Hardware application]]
 

Revision as of 12:05, 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 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
...

You should see similar results format like this:

...
{ 
      "scanning": 0, 
      "devices": [ 
              { 
                      "name": "RT_T", 
                      "rssi": -72, 
                      "address": "FF:CB:FA:6A:23:CB" 
              } 
      ] 
}
...

Skanavimas vyksta apie 30sek., todėl su „scanning“ rodoma ar vis dar yra vykdomas skanavimas. Šiuo atveju, galima užklausinėti „scan.result“ kol „scanning“ = 1.