Changes

no edit summary
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.
+
==Introduction==
 +
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:~# ubus
+
  root@Teltonika-RUTX11:~# blesemd -D
  Usage: ubus [<options>] <command> [arguments...]
+
  Initializing blesemd...
  Options:
+
  Warning: debug messages will be shown!
  -s <socket>:          Set the unix domain socket to connect to
+
  Preparing bluetooth interface...
  -t <timeout>:          Set the timeout (in seconds) for a command to complete
+
  Reading config...
  -S:                   Use simplified output (for scripts)
+
  Devices loaded: 0
  -v:                    More verbose output
+
  Creating database...
-m <type>:            (for monitor): include a specific message type
+
  modbus_data table already exists
                        (can be used more than once)
+
  SENT_ID_TABLE already exists
  -M <r|t>              (for monitor): only capture received or transmitted traffic
+
  Create DB done
  Commands:
+
  Initializing uloop...
  - list [<path>]                        List objects
+
  Connecting to ubus...
  - call <path> <method> [<message>]    Call an object method
+
  Initializing BLE device...
  - listen [<path>...]                  Listen for events
+
  Initializing BLE ubus interface...
  - send <type> [<message>]              Send an event
+
  Adding ubus object...
  - 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"''.
+
*Run '''scan.start''' command to start Bluetooth scan:
 
  −
* Login using [[CLI]] and run '''scan.start''' command to start Bluetooth scan:
      
  ...
 
  ...
Line 33: Line 37:  
  ...
 
  ...
   −
* To see scan results, use command '''scan.result''':
+
*To see scan results, use command '''scan.result''':
    
  ...
 
  ...
Line 39: Line 43:  
  ...
 
  ...
   −
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:
+
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 48: Line 52:  
                       "name": "RT_T",  
 
                       "name": "RT_T",  
 
                       "rssi": -72,  
 
                       "rssi": -72,  
                       "address": "FF:CB:FA:6A:23:CB"  
+
                       "address": "FF:CB:FF:6F:23:FB"  
 
               }  
 
               }  
 
       ]  
 
       ]  
Line 54: Line 58:  
  ...
 
  ...
   −
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 62: Line 66:  
               {   
 
               {   
 
                       "rssi": -42,  
 
                       "rssi": -42,  
                       "address": "28:21:06:02:72:AD"  
+
                       "address": "2F:2A:0A:0A:7A:AA"  
 
               },
 
               },
 
               {  
 
               {  
 
                       "name": "RT_T",  
 
                       "name": "RT_T",  
 
                       "rssi": -77,  
 
                       "rssi": -77,  
                       "address": "C6:0D:52:5E:35:D7"  
+
                       "address": "CF:0A:52:5E:35:D7"  
 
               }  
 
               }  
 
       ]  
 
       ]  
Line 73: Line 77:  
  ...
 
  ...
   −
* Device pairing command:
+
*In order to pair devices use this command:
    
  ...
 
  ...
  ubus call blesem pair '{"address":"FF:CB:FA:6A:23:CB"}'
+
  ubus call blesem pair '{"address":"FF:CC:FF:6A:23:CB"}'
 
  ...
 
  ...
   −
On success pairing you should see output:
+
If the pairing process was successful you should see this output:
    
  ...
 
  ...
Line 87: Line 91:  
  ...
 
  ...
   −
If fails, you will see error output:
+
*To get the statistics from paired devices, use '''stat''' command:
    
  ...
 
  ...
  {  
+
  ubus call blesem stat '{"address":"FF:CB:FA:6A:23:CB"}'
      "error": "failed to pair because…."  
  −
}
   
  ...
 
  ...
   −
* On success pairing new device info will be written in '''blesem''' service config:
+
You should see similar output:
    
  ...
 
  ...
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 125: Line 107:  
       "humidity": 20,
 
       "humidity": 20,
 
       "firmware": "23",
 
       "firmware": "23",
.
+
.
}
+
}
 
+
...
 
+
[[Category:Hardware application]]
* 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",
  −
{}
  −
]
  −
}