Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Running “bluetoothctl “ command in Linux terminal and in C++ code .
Forum Updated to NodeBB v4.3 + New Features

Running “bluetoothctl “ command in Linux terminal and in C++ code .

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    When I use Linux terminal I have to type
    bluetoothctl --list
    to get full and correct response in terminal.

    When I run the following code
    QString process = “bluetoothctl”;
    QString argument = “list”

    proc->start(process, QStringList() <<(argument) );
    

    I get same result WITHOUT “--” Added ANYWHERE .
    The code actually fails when the "--" is added.

    Why does it work without “--” ?
    What am I doing wrong ?

    Secondly
    I also need to have this to work in my code

    bluetoothctl –scan on

    with previous" problem" I have no idea how to add the “on” as second argument .

    However I need to solve the first issue first and would appreciate any help.

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      When I use Linux terminal I have to type
      bluetoothctl --list
      to get full and correct response in terminal.

      When I run the following code
      QString process = “bluetoothctl”;
      QString argument = “list”

      proc->start(process, QStringList() <<(argument) );
      

      I get same result WITHOUT “--” Added ANYWHERE .
      The code actually fails when the "--" is added.

      Why does it work without “--” ?
      What am I doing wrong ?

      Secondly
      I also need to have this to work in my code

      bluetoothctl –scan on

      with previous" problem" I have no idea how to add the “on” as second argument .

      However I need to solve the first issue first and would appreciate any help.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @AnneRanch
      Did you try bluetoothctl list from a shell? That is what the QProcess code executes.

      From what is shown at e.g. https://waylonwalker.com/til/linux-bluetoothctl/ and https://superuser.com/questions/1500383/bluetoothctl-list-connected-devices there is no indication bluetoothctl accepts a --list argument, it seems to expect commands as argument without a leading --. Though it's not very clearly documented.

      bluetoothctl –scan on

      Try either of

      proc->start(process, QStringList() << "scan" << "on" );
      proc->start(process, QStringList() << "--scan" << "on" );
      

      It looks like you are "lucky" if you can get all your desired commands through as arguments to blutetoothctl on the command line. It is more designed as a "shell" to which you input commands. As https://stackoverflow.com/a/52012231/489865 says:

      I will say that bluetoothctl would be easier to use if it could be configured from the command line without needing to configure it interactively or having to resort to more complex scripting.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        Here is "shell" output- using "terminal " I am trying top replicate .
        Unfortunately the output form "bluetoothctl" , no option selected is indeed not documented anywhere .

        If that is correct result - how do I code "no option" as an argument ?

        proc->start(process, QStringList() << "scan" << "on" );

        q5@q5-desktop:~$ bluetoothctl
        Agent registered
        [CHG] Controller 00:15:83:15:A2:CB Pairable: yes
        [bluetooth]# list
        Controller 00:15:83:15:A2:CB q5-desktop [default]
        [bluetooth]# scan on
        Discovery started
        [CHG] Controller 00:15:83:15:A2:CB Discovering: yes
        [NEW] Device 98:D3:31:F8:39:33 SPP-CA
        [bluetooth]#

        JonBJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          Here is "shell" output- using "terminal " I am trying top replicate .
          Unfortunately the output form "bluetoothctl" , no option selected is indeed not documented anywhere .

          If that is correct result - how do I code "no option" as an argument ?

          proc->start(process, QStringList() << "scan" << "on" );

          q5@q5-desktop:~$ bluetoothctl
          Agent registered
          [CHG] Controller 00:15:83:15:A2:CB Pairable: yes
          [bluetooth]# list
          Controller 00:15:83:15:A2:CB q5-desktop [default]
          [bluetooth]# scan on
          Discovery started
          [CHG] Controller 00:15:83:15:A2:CB Discovering: yes
          [NEW] Device 98:D3:31:F8:39:33 SPP-CA
          [bluetooth]#

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @AnneRanch
          Yes, this is the way that SO shows it operating. Assuming true, it means you cannot pass on the command line the commands you want it to execute. You have to do just what you show doing from the shell: namely, start it with no arguments, and then supply it with commands on its input. That means you will have to write() these commands to the QProcess. It will be something like:

          proc->start(process, QStringList() );    // `QStringList()` is "empty/no command line arguments"
          proc->write("list\n");
          proc->write("scan on\n");
          ...
          proc->close();    // hoping this will end the `bluetoothctl` process
          

          I have not dealt with looking at or waiting for responses to arrive (slot on QProcess::readyRead() which does a proc->readAll()), just showing you how you need to send these commands to the process once it is running.

          A 1 Reply Last reply
          1
          • JonBJ JonB

            @AnneRanch
            Yes, this is the way that SO shows it operating. Assuming true, it means you cannot pass on the command line the commands you want it to execute. You have to do just what you show doing from the shell: namely, start it with no arguments, and then supply it with commands on its input. That means you will have to write() these commands to the QProcess. It will be something like:

            proc->start(process, QStringList() );    // `QStringList()` is "empty/no command line arguments"
            proc->write("list\n");
            proc->write("scan on\n");
            ...
            proc->close();    // hoping this will end the `bluetoothctl` process
            

            I have not dealt with looking at or waiting for responses to arrive (slot on QProcess::readyRead() which does a proc->readAll()), just showing you how you need to send these commands to the process once it is running.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @JonB Pr ogres report
            I get expected response and some benefits when no arguments are used to run the process.
            The attached extracts the Bluetooth address and actually reports some progress ( Waiting to connect...)

            Many thanks for you help.
            Appreciate that.

            1130687e-8d97-4027-8b12-2dabae6d75c3-image.png

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved