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

From Teltonika Networks Wiki
Line 22: Line 22:
 
  ...
 
  ...
  
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:
+
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:
  
 
  ...
 
  ...
Line 37: Line 37:
 
  ...
 
  ...
  
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 if the device is not supported:
  
 
  ...
 
  ...
Line 56: Line 56:
 
  ...
 
  ...
  
*Device pairing command:
+
*In order to pair devices use this command:
  
 
  ...
 
  ...
Line 62: Line 62:
 
  ...
 
  ...
  
On success pairing you should see output:
+
If the pairing process was successful you should see this output:
  
 
  ...
 
  ...
Line 70: Line 70:
 
  ...
 
  ...
  
On success pairing new device info will be written in '''blesem''' service config:
+
*In order to unpair devices use this command:
 
 
...
 
      config device
 
            option address "FF:CB:FA:6A:23:CB"
 
...
 
 
 
*Device unpairing command:
 
  
 
  ...
 
  ...
Line 83: Line 76:
 
  ...
 
  ...
  
*To get statistic from paired devices, use '''stat''' command:
+
*To get statistics from paired devices, use '''stat''' command:
  
 
  ...
 
  ...
Line 89: Line 82:
 
  ...
 
  ...
  
You should see output:
+
You should see similar output:
  
 
  ...
 
  ...

Revision as of 17:47, 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 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.


Before you start using ubus commands to control Bluetooth, make sure you have enabled it. You can do that in Network → Bluetooth → General settings. Click Enable Bluetooth and press Save & Apply.

Networking rutx configuration example bluetooth enable v1.png

  • Now login to CLI or SSH 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 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:

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

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" 
              } 
      ] 
}
...
  • In order to pair devices use this command:
...
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" 
}
...
  • In order to unpair devices use this command:
...
ubus call blesem unpair '{"address":"FF:CB:FA:6A:23:CB"}'
...
  • To get 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",
.
}
...