kedder / openvario-shell

Main Menu Shell for Openvario
GNU General Public License v3.0
12 stars 9 forks source link

Menu to set Bluetooth connection #2

Open condoratberlin opened 4 years ago

condoratberlin commented 4 years ago

I have connected a bluetooth adapter to connect my lx nano to my openvario. Currently i establish a bluetooth connection by command line and a two line in the start up script. It would be great if an interface for a bluetooth connection could be implemented.

condoratberlin commented 4 years ago

If you can provide me some quick start for adding a new python based menu entry, i will contribute. My Python knowledge is quiet good, but not with the GUI-stuff.

kedder commented 4 years ago

The API is a bit volatile at this stage, but you can more or less get the idea what it takes if you look at file manager (ovshell_fileman):

You create the extension, and reference it in setup.py of the project:

https://github.com/kedder/openvario-shell/blob/72ab73ab0f7ec489acc1360347e9206630efde1b/src/ovshell_fileman/__init__.py#L7-L8 https://github.com/kedder/openvario-shell/blob/72ab73ab0f7ec489acc1360347e9206630efde1b/setup.py#L40-L44 Extension provides one or more apps

https://github.com/kedder/openvario-shell/blob/72ab73ab0f7ec489acc1360347e9206630efde1b/src/ovshell_fileman/ext.py#L15-L16

App pushes activity (the UI screen) to the stack

https://github.com/kedder/openvario-shell/blob/72ab73ab0f7ec489acc1360347e9206630efde1b/src/ovshell_fileman/downloadapp.py#L41-L45

And create() method of activity creates the actual urwid widget to show on the screen. The menu item you see is the title of the app.

I would start a new package (ovshell_wireless) for these conectivity apps.

kedder commented 3 years ago

I expect Bluetooth connections to work in the newest version of openvario-shell (0.7.1), but I did not have a chance to test it myself (I don't have a bluetooth usb dongle at hand). The "Networking" app in ovshell is generic enough to handle anything that connman supports, so (in theory) that should also include bluetooth connections.

Please try it out with your hardware and let me know. I'll close this issue meanwhile.

condoratberlin commented 3 years ago

Thanks a lot for the great work. The wlan menue works as expected very well, exept an issue i will post in issue #3. The bluetooth menu does not work for my configuration. I was not able to see my nano logger!

I managed to connect to my bluetooth nano logger by another approach using bluetoothctl.

Here my approach connecting to a bluetooth device:

Instruction inspired from open-vario-bluetooth with slight modifactions worked for Stefly OpenVArio with Linux 5.2 Kernel.

first install your linux friendy usb bluetooth dongle...

  1. interupt the OVmenu at startup and then exit to the shell so you get a command prompt

  2. check the usb bluetooth device recognised

root@openvario-57lvds:~# lsusb
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

you can see mine is the Cambridge Silicon Radio one.

  1. create a main.conf under /etc/bluetooth/main.conf with:

    [Policy]
    AutoEnable=true

    to enable bluetooth at boot up.

  2. search for the device by starting bluetooth service and scan for your device and the corresponding MAC-Addr.

    root@openvario-57lvds:~# systemctl enable bluetooth.service
    root@openvario-57lvds:~# systemctl start bluetooth.service
    root@openvario-57lvds:~# hcitool scan
    Scanning ...
        <MAC-Addr>       Nano-Logger 239

here its detected my soartronic module , yay !

  1. Now use bluetoothctl to pair with the device:

    [bluetooth]# power on
    [bluetooth]#pair <MAC-Addr>
    Request PIN code
    [agent] Enter PIN code: 1234
    [CHG] Device 12:34:56:78:9A:BC UUIDs:
        xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    [CHG] Device 12:34:56:78:9A:BC Paired: yes
    Pairing successful
    [bluetooth]#trust <MAC-Addr>
  2. now test connect the dongle to your bluetooth source

root@openvario-57lvds:~# rfcomm connect 0  <MAC-Addr>
Connected /dev/rfcomm0 to <MAC-Addr> on channel 1

Press CTRL-C for hangup

If you get this then you have paired successfully ! do the CTRL -C to exit out

  1. edit or create a .bashrc file in /home/root/.bashrc with:
rfcomm bind 0 <MAC-Addr>

now the paired and connected bluetooth device in binded to the channel 0 and will be connected if somethings tries to access the channel.

  1. reboot the OV with CTRL-ALT-DEL

  2. when OV restarts, let it get to Xcsoar

make sure your bluetooth device is on and transmitting, connected to your flarm

  1. from XCSoar menu, go to config-devices add a new device, select rfcomm0 as the device suggest baud rate as 19200 ( it should match your BT transmitter ) driver FLARM

  2. thats it, the flarm data should be appearing on your new device

I hope this helps other people to use bluetooth with OpenVario

kedder commented 3 years ago

Hm, can you try connecting to bluetooth through connmanctl? I've seen connman does support bluetooth devices, but not sure how that actually work.

condoratberlin commented 3 years ago

I had tried but didn't managed to connect bluetooth wit connman. If i have time to check againn I will report, but my solution described above works very stable, so I'm not sure when I will try again.

condoratberlin commented 3 years ago

I tried the new release 0.7.3 and tried to scan. now the application fails again with the following message:

IMG_20210328_160812

I hope it helps.

kedder commented 3 years ago

Interesting. What kind of wifi hardware do you have?

condoratberlin commented 3 years ago

Ahh, soory, I forgot to say, that I selected only Bluetooth and nothing else. Than when trying to scan this failure is thrown.

kedder commented 3 years ago

Aha! Got it. So wifi is powered down in this case and openvario still tries to scan it. Should be an easy fix.

condoratberlin commented 3 years ago

Perfect. This will increase the robustness.

Thanks a lot for your great work. I love your shell menu.

kedder commented 3 years ago

Ok, just released 0.7.4 with the fix for this.