Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting with bluetooth only succesfull on 3rd attempt. #27

Open
jeromba6 opened this issue Jan 9, 2022 · 7 comments
Open

Connecting with bluetooth only succesfull on 3rd attempt. #27

jeromba6 opened this issue Jan 9, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@jeromba6
Copy link

jeromba6 commented Jan 9, 2022

I have the mindstorms Robot Inventor (51515). When connecting to the brick via USB cable first attempt is always successful. But with bluetooth, which I prefer not having any cables in the way, I first have to set the bluetooth connection to serial.
After this startup VSCode try to connect (it fails)
Close VSCode
startup VSCode try to connect (it fails again)
Close VSCode
startup VSCode try to connect (succes 👍 )

This is aways the case.
My computer is running on Ubuntu 21.10, for now it's my only way to connect to the Lego brick from Ubuntu so I'm very happy to use the plugin.

@PeterStaev PeterStaev added the bug Something isn't working label Jan 11, 2022
@PeterStaev
Copy link
Owner

Hey @jeromba6 , sadly I'm not a linux user myself (I wasn't even able to compile the plugin on a Ubuntu VM...). Hopefully a more experienced linux user/dev could help on this.

@dmusican
Copy link

I'm a Linux user (Ubuntu 20.04) with a Spike Prime, and I landed here trying to make a bluetooth connection work. I couldn't get it to work at all until I saw the hint from @jeromba6 about setting the bluetooth connection to serial. I don't know if this is what that meant, but after some searching, here's what I came up with. I'm adding it here to help others, but also because if it so happens that this is a different approach, maybe it would help with the reported bug?

  • Run the command bluetooth devices to see the list of paired devices
  • Then run sudo rfcomm bind 0 <dev>, where <dev> is the hex device id associated with the robot from the above list

That worked. I was then able to connect with /dev/rfcomm0 with VSCode.

@jeromba6: I don't know if I've provided useful info, or just told you what you already knew. At the very least, thanks for getting me started. And further thanks to @PeterStaev for this fantastic VSCode extension.

@PeterStaev
Copy link
Owner

@dmusican thanks for the input on this issue. Just to add to this - the plugin communicates over COM with the Brick and not directly on BLE. This is done automatically for Windows and Mac and for both USB and BLE connections (i.e. when you connect the brick to the computer it automatically opens/creates the COM port). I guess on Linux it is not done automatically :(

@TheWendyPower
Copy link

@dmusican I can't get this to work. I could be missing additional drivers. I follow this: https://gist.github.com/0/c73e2557d875446b9603 I can connect to the hub, but I'm unable to complete the sudo rfcomm bind 0 <dev> step, as it won't stay connected. It pairs and then disconnects.

@dmusican
Copy link

@TheWendyPower, I think that's by design. It pairs, then disconnects because you're not actually using it. It will then connect again when you actually connect to it from VSCode.

@foton
Copy link

foton commented Jul 5, 2023

Exactly. I start the BT on Ubuntu and RI (51515) hub and hub was after while displayed as "LEGO Hub A8:E2:C1:9C:67:16 disconnected" . According instructions from lego-hub-tk , I used commandsudo rfcomm connect /dev/rfcomm0 A8:E2:C1:9C:67:16 .

> sudo rfcomm connect /dev/rfcomm0 A8:E2:C1:9C:67:16
Connected /dev/rfcomm0 to A8:E2:C1:9C:67:16 on channel 1
Press CTRL-C for hangup

And bluetoothe state in "explorer" changed to "connected". On hub there is still blue button and "B" letter on display.

I can than select /dev/rfcomm0 from extension menu.... but it will throw VScode error Connecting to Hub Failed! Error: Operace zamítnuta, cannot open /dev/rfcomm0 ( "Operace zamítnuta" is in czech language, translated to english it is "Operation denied/forbidden") .

I tried instructions from webspace.fh-zwickau.de, to allow any user acces such connection (using UDEV rules).

And error changed Connecting to Hub Failed! Error Prostředek je dočasně nepřístupný Cannot lock port

When I connect hub by USB, I can run screen /dev/ttyACM0 115200 and it returns some number, which are changing when I move the hub. But VScode still says, that Connecting to Hub Failed! Error: Zařízení nebo zdroj jsou používány, cannot open /dev/ttyACM0 ("Zařízení nebo zdroj jsou používány" => "device or source is used")

@PeterStaev
Copy link
Owner

PeterStaev commented Jul 29, 2023

When I connect hub by USB, I can run screen /dev/ttyACM0 115200 and it returns some number, which are changing when I move the hub. But VScode still says, that Connecting to Hub Failed! Error: Zařízení nebo zdroj jsou používány, cannot open /dev/ttyACM0 ("Zařízení nebo zdroj jsou používány" => "device or source is used")

@foton this is a normal error since the COM ports do not allow simultanious connections. So while you have your screen running or you have connected through the LEGO app, no further connections are allowed. You need to close all and then try to connect through VSCode. Hopefully this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants