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

Cannot connect to Powered Up Remote #397

Closed
laurensvalk opened this issue Jul 21, 2021 · 74 comments
Closed

Cannot connect to Powered Up Remote #397

laurensvalk opened this issue Jul 21, 2021 · 74 comments
Labels
bug Something isn't working hub: cityhub Issues related to the LEGO Powered Up Smart hub (Hub No. 4) hub: handset Issues related to the LEGO Powered Up Handset (remote control) OS: macOS Issues that only occur on macOS software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth topic: remote control Issues related to remotly controlling hubs

Comments

@laurensvalk
Copy link
Member

laurensvalk commented Jul 21, 2021

I'm using https://beta.pybricks.com/ and I've installed the (I assume) latest firmware though the interface.

When trying the Remote example code, the hub LED begins to pulse and the remote LED blinks white, but it doesn't appear to connect and then I get
Traceback (most recent call last): File "main.py", line 6, in OSError: [Errno 116] ETIMEDOUT

I'm using the City hub by the way

I press the "Download and run this program" button and the green button on my remote at the same time. The remote blinks white and the hub pulses but it doesn't appear to connect. The remote stops blinking roughly the same time as the timeout.

Originally posted by @pqhf5kd in #186 (comment)

@laurensvalk
Copy link
Member Author

Could you share the script you used?

Can you also add the following to your code, and share the output?

from pybricks import version
print(version)

@pqhf5kd
Copy link

pqhf5kd commented Jul 21, 2021

from pybricks.pupdevices import Remote
from pybricks.parameters import Button
from pybricks.tools import wait

# Connect to the remote.
my_remote = Remote()

while True:
    # Check which buttons are pressed.
    pressed = my_remote.buttons.pressed()

    # Show the result.
    print("pressed:", pressed)

    # Check a specific button.
    if Button.CENTER in pressed:
        print("You pressed the center button!")

    # Wait so we can see the result.
    wait(100)

@dlech dlech added bug Something isn't working software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: remote control Issues related to remotly controlling hubs labels Jul 21, 2021
@pqhf5kd
Copy link

pqhf5kd commented Jul 21, 2021

('cityhub', '3.1.0a3', 'v3.1.0a3 on 2021-07-19')

@dlech dlech added the topic: bluetooth Issues involving bluetooth label Jul 21, 2021
@dlech
Copy link
Member

dlech commented Jul 21, 2021

It is working for me with the same firmware version. They only way I know to troubleshoot would be to connect the defective remote to a computer and log the Bluetooth packets. Maybe the remote has different firmware or something like that?

@dlech
Copy link
Member

dlech commented Jul 21, 2021

Also, try turning on the remote later after the program is already started instead of pressing the buttons at the same time.

@pqhf5kd
Copy link

pqhf5kd commented Jul 21, 2021

I'm on a 2021 MacBook Air. The remote doesn't appear in the bluetooth list when in pairing mode, nor does it on iOS.
It does appear in the bluetooth list on iOS after connect through the PUP app. Is that normal?

It connects through the app quickly, without any issues.

@dlech
Copy link
Member

dlech commented Jul 21, 2021

You would need to use a program like pybricksdev that knows how to connect to the remote.

@laurensvalk
Copy link
Member Author

Maybe the remote has different firmware or something like that?

Do you remember roughly when this remote was purchased? Was it purchased separately or as part of a train set?

@laurensvalk
Copy link
Member Author

Someone on our Facebook page has reported a similar issue.

@dlech, if more people run into this, perhaps we can share a firmware zip here that prints out relevant debug info during the connection process, so people can try it without Pybricksdev.

@pqhf5kd
Copy link

pqhf5kd commented Jul 24, 2021

Someone on our Facebook page has reported a similar issue.

@dlech, if more people run into this, perhaps we can share a firmware zip here that prints out relevant debug info during the connection process, so people can try it without Pybricksdev.

That was me on Facebook, sorry!

The remote came from a 60198 set that I purchased sealed, but from a private seller, in December 2020. I had a look on the box, but it doesn't look like there's a date code.

The remote has the following under the battery box:

  • '25IO' in print

The following is moulded:

  • 209-J00326
  • HANDSET NO.2
  • IC: 3072A-28739
  • FCC ID: NPI 28739
  • CMIT ID: 2018DJ5115

@dlech
Copy link
Member

dlech commented Jul 26, 2021

I just had another idea. If you have iOS or Android, you can install nRF Connect and sniff the adverting data from the remote.

We are looking for the raw advertising data like this:
Screenshot_20210726-125115

@pqhf5kd
Copy link

pqhf5kd commented Jul 26, 2021

Thanks Dlech. Unfortunately I'm away from home until the end of August, but I'll try this as soon as I get back.

@dlech dlech added the hub: handset Issues related to the LEGO Powered Up Handset (remote control) label Aug 12, 2021
@pqhf5kd
Copy link

pqhf5kd commented Aug 21, 2021

It looks like nRF Connect doesn't show raw advertising data on iOS. I'll try and get an Android device for testing in the next few days.

@dlech
Copy link
Member

dlech commented Aug 31, 2021

FYI, we've made some changes that could affect this issue. Could you try again with the v3.1.0a4 firmware from https://beta.pybricks.com?

@pqhf5kd
Copy link

pqhf5kd commented Sep 3, 2021

V3.1.0a34 makes no difference unfortunately

@BertLindeman
Copy link

Completely different environment, but this combo works:
My remote coded 26I0 on win10 MS-edge 92.0.902.84
shows

('cityhub', '3.1.0a4', 'v3.1.0a4 on 2021-08-30')
pressed: (Button.LEFT_MINUS, Button.RIGHT_MINUS, Button.LEFT, Button.RIGHT, Button.LEFT_PLUS, Button.RIGHT_PLUS)
pressed: ()

and so on.

@pqhf5kd
Copy link

pqhf5kd commented Sep 5, 2021

I grabbed the advertising data using an Android device today
signal-2021-09-05-172826_001
0x020106110723D1BCEA5F782316DEEF12122316000009FF970300420A004100140948616E64736574000000000000000000000000051210002000020A00

@pqhf5kd
Copy link

pqhf5kd commented Sep 13, 2021

Was this any use?

@dlech
Copy link
Member

dlech commented Sep 13, 2021

It matches the advertising data from my hub (other than the hub name, which should not be relevant), so it rules out the possibility that LEGO changed the advertising data layout. However, that doesn't get us any closer to a solution.

We did have one other report of not being able to connect to a different LWP3 device: #442 (comment). Not sure if this might be related or not.

@pqhf5kd
Copy link

pqhf5kd commented Sep 14, 2021

I installed pybricksdev on an older, Intel MacBook and my remote connects without issue.

I'm unable to connect my city hub, although that might be my fault. I'll read the documentation further.

@dlech
Copy link
Member

dlech commented Sep 14, 2021

It the city hub currently has Pybricks firmware on it instead of LEGO firmware, then that would explain why it doesn't connect in the same way as the remote.

@pqhf5kd
Copy link

pqhf5kd commented Sep 14, 2021

I tried again with the Lego firmware and it connects.

Is there some diagnostics I can do with pybricksdev?

@dlech
Copy link
Member

dlech commented Sep 14, 2021

Since it is connecting properly with pybricksdev, there probably isn't much to be learned there. If you really want to, you can log the Bluetooth packets (instructions).

But what we really need is the Bluetooth traffic going between the city hub running Pybricks firmware and the remote handset. However, that requires a sniffer.

@mateusz
Copy link

mateusz commented Sep 17, 2021

Hi, just ran into seemingly similar issue on CityHub :)

  • flashed firmware into it from beta.pybricks.com without issue
  • REPL reports: MicroPython v3.1.0a4 on 2021-08-30; Powered Up City Hub with STM32F030RC
  • executing remote = Remote() from REPL, and then turning remote on after ~1s results in OSError: [Errno 116] ETIMEDOUT after delay
  • the same remote works fine with the same CityHub with latest LEGO firmware
  • interestingly, the remote connects without any issues with pybricked TechnicHub (also v3.1.0a4 firmware) from the 42124 Buggy set (same remote = Remote() command).
  • remote comes from the green cargo train set 60198
  • remote is a "HANDSET NO.2", with 19I9 printed (so different to OP)

Remote never shows up in beta.pybricks.com (neither flashing mode, nor the regular connection), but I can connect to it using pybricksdev lwp3 repl. Here is nRF adv dump:

remote

So if the remote can connect ok with TechnicHub, is it something special to do with cityhub? My CityHub is:

  • from the same lego set the remote was in
  • "HUB NO.4"
  • 46I9 printed
  • nRF adv dump:

cityhub

@mateusz
Copy link

mateusz commented Sep 20, 2021

Another experiment:

  • connect city hub to Pybricks Code
  • run the program by pressing the button on the hub
  • turn remote on
  • note remote is not connecting
  • disconnect Pybricks Code
  • remote connects immediately

@mateusz
Copy link

mateusz commented Sep 20, 2021

Also tried shortening the remote connect timeout remote = Remote(timeout=2000) just to make sure we are not losing any logs due to overflow. The resulting log (judging by diff) is the same as always, no indication of communication with the remote.

@dlech
Copy link
Member

dlech commented Sep 20, 2021

It's a long shot, but we could try adding this (suggested here to fix a similar issue of not able to connect a peripheral while another peripheral is connected).

diff --git a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
index 1a264a52..5d86204f 100644
--- a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
+++ b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
@@ -1355,6 +1355,11 @@ static PT_THREAD(gap_init(struct pt *pt)) {
     PT_WAIT_UNTIL(pt, hci_command_status);
     // ignoring response data
 
+    PT_WAIT_WHILE(pt, write_xfer_size);
+    GAP_SetParamValue(TGAP_REJECT_CONN_PARAMS, 1);
+    PT_WAIT_UNTIL(pt, hci_command_status);
+    // ignoring response data
+
     PT_END(pt);
 }
 

@stephg
Copy link

stephg commented Sep 21, 2021

I can confirm the same issue with latest beta: ('cityhub', '3.1.0b1', 'v3.1.0b1 on 2021-09-21').
When flashing the current program and disconnecting Pybricks Code, the hub connects to the remote without any issues.

@laurensvalk
Copy link
Member Author

laurensvalk commented Sep 22, 2021

@mateusz and @stephg, which operating system are you using on your computer?

Can you also reproduce this problem if you run https://beta.pybricks.com/ on your Android device?

This might help us see if perhaps there isn't necessarily a hardware difference between all of our city hubs.

@mateusz
Copy link

mateusz commented Sep 22, 2021

@laurensvalk OMG, I can't believe we haven't thought about that, great suggestion 😅 It works!

The scenario I described here works fine on Android - I can have both Android and remote connected, and I can see the log coming out too. The machine where I reported it not working is a MacBook Pro (16-inch, 2019), on Big Sur 11.6.

Amazing, I can now get some data out while having the remote on :) Nice! Thank you!

Some more info on the mac BT:

  Apple Bluetooth Software Version:	8.0.5d7
  Bluetooth Low Energy Supported:	Yes
  Handoff Supported:	Yes
  Instant Hot Spot Supported:	Yes
  Manufacturer:	Broadcom
  Transport:	UART
  Chipset:	4364B3
  Firmware Version:	v65 c4188
  Bluetooth Power:	On
  Discoverable:	Off
  Connectable:	Yes
  Auto Seek Pointing:	On
  Remote wake:	On
  Vendor ID:	0x05AC
  Product ID:	0x0096
  Bluetooth Core Spec:	5.0 (0x9)
  HCI Revision:	0x105C
  LMP Version:	5.0 (0x9)
  LMP Subversion:	0x3041
  Device Type (Major):	Computer
  Device Type (Complete):	Mac Portable
  Composite Class Of Device:	0x38010C
  Device Class (Major):	0x01
  Device Class (Minor):	0x03
  Service Class:	0x1C0
  Auto Seek Keyboard:	On

Mac browser:

Version 94.0.4606.54 (Official Build) (x86_64)

Android browser:

Chrome, Version 94.0.4606.50

@laurensvalk
Copy link
Member Author

I can have both Android and remote connected

Glad to hear it! Then so far we have:

The machine where I reported it not working is a mac.

Originally posted by @mateusz in #397 (comment)

I'm on a 2021 MacBook Air.

Originally posted by @pqhf5kd in #397 (comment)

@mateusz
Copy link

mateusz commented Sep 22, 2021

MacBook Pro (16-inch, 2019), Big Sur 11.6 to be specific (updated post)

@dlech
Copy link
Member

dlech commented Sep 22, 2021

I have an early 2015 MacBook Pro running macOS 12 beta and it works there. (I'm ready to upgrade, but I've been holding out to see what new models are announced this fall).

Since we've narrowed it down to potentially a macOS issue, we can try logging Bluetooth packets there and see if we see anything interesting. Instructions.

@dlech dlech added the OS: macOS Issues that only occur on macOS label Sep 22, 2021
@stephg
Copy link

stephg commented Sep 22, 2021

@mateusz and @stephg, which operating system are you using on your computer?

Can you also reproduce this problem if you run https://beta.pybricks.com/ on your Android device?

This might help us see if perhaps there isn't necessarily a hardware difference between all of our city hubs.

I was using OSX 11.5.2 on an 2019 MacBook Pro 16-inch and Chrome.

My Linux machine has no BLE, so can't test that.

When running Pybricks Code on my Android mobile, the remote can connect successfully!
However, when interacting with the remote it looks like the firmware is crashing... almost instantly after pressing buttons quickly. I added a heartbeat via led toggle on hub and remote in the main loop, and it stops suddenly as well as the stop button on the hub is not working anymore - a powercycle is required. When the program is flashed on the hub, everything is working fine. Interesting. That's another issue.

@stephg
Copy link

stephg commented Sep 22, 2021

Since we've narrowed it down to potentially a macOS issue, we can try logging Bluetooth packets there and see if we see anything interesting. Instructions.

You can find a btsnoop of downloading and running my sample program here: https://drive.google.com/file/d/1fZNnsmhxE0zbns8pn5axAkg3lHbvOjHn/view?usp=sharing

@dlech
Copy link
Member

dlech commented Sep 22, 2021

However, when interacting with the remote it looks like the firmware is crashing... almost instantly after pressing buttons quickly. I added a heartbeat via led toggle on hub and remote in the main loop, and it stops suddenly as well as the stop button on the hub is not working anymore - a powercycle is required.

If the hub actually crashes, it should reboot itself. If you are still able to power off with the button then it didn't totally crash, but got into some sort of bad state. If you have to remove the batteries, then something really bad is going on.

@dlech
Copy link
Member

dlech commented Sep 22, 2021

You can find a btsnoop of downloading and running my sample program here

Thanks for this. I looks like the Mac is periodically scanning the entire time. I wonder if these could be interfering with the process, e.g. if the Mac says to stop scanning right after the City hub starts scanning.

Here is a city hub firmware to try that does passive scanning instead of active scanning (and has the debug logging enabled).
firmware.zip

diff --git a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
index 1a264a52..1c2faa51 100644
--- a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
+++ b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
@@ -431,7 +431,7 @@ static PT_THREAD(scan_and_connect_task(struct pt *pt, pbio_task_t *task)) {
 
     // start scanning
     PT_WAIT_WHILE(pt, write_xfer_size);
-    GAP_DeviceDiscoveryRequest(GAP_DEVICE_DISCOVERY_MODE_ALL, 1, GAP_FILTER_POLICY_SCAN_ANY_CONNECT_ANY);
+    GAP_DeviceDiscoveryRequest(GAP_DEVICE_DISCOVERY_MODE_ALL, 0, GAP_FILTER_POLICY_SCAN_ANY_CONNECT_ANY);
     PT_WAIT_UNTIL(pt, hci_command_status);
 
     context->status = read_buf[8]; // debug

@mateusz
Copy link

mateusz commented Sep 23, 2021

Flashed the "passive-scanning" firmware (v3.1.0b1-3-g0602b0e7-dirty) - now the controller does not connect at all (regardless of connection to macos)

@dlech
Copy link
Member

dlech commented Sep 23, 2021

Did it log receiving advertising data though?

@mateusz
Copy link

mateusz commented Sep 28, 2021

Oh sorry, here is the output:

07 01 04 FE 03 03 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
09 04 FF 06 7F 06 00 04 FE 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
0E 01 1B FD 0A 00 00 00 12 00 00 40 00 00 00 
09 04 FF 06 7F 06 00 1B FD 00 
04 01 05 FE 00 
09 04 FF 06 7F 06 00 05 FE 00

@dlech dlech added the hub: cityhub Issues related to the LEGO Powered Up Smart hub (Hub No. 4) label Nov 16, 2021
@dlech
Copy link
Member

dlech commented Nov 17, 2021

I got a new MacBook a week ago and sure enough, I was able to reproduce the problem. I used my Bluetooth sniffer to compare it to a working setup (my Linux desktop) to see what the difference was. The only thing I could see is that connection interval when connected to the MacBook was 15 ms compared to something like 50 ms when connected to Linux (I've attached the file for the curious). Fortunately Apple spells out how to change this setting and I was able to find the TI API to do this so the issue is fixed.

pybricks-city-hub-linux-ok-then-mac-fail.zip

@laurensvalk
Copy link
Member Author

laurensvalk commented Nov 17, 2021

dlech closed this in dcc9fa5 2 minutes ago

Is this a Mac-specific fix, or could it fix it on Windows also?

@dlech
Copy link
Member

dlech commented Nov 17, 2021

Hard to say if it fixes other platforms without any logs to compare. However the change is generic and should affect all platforms.

@laurensvalk
Copy link
Member Author

Great - I'll get a Windows user who had this problem to try the new firmware.

@laurensvalk
Copy link
Member Author

Great - I'll get a Windows user who had this problem to try the new firmware.

Their problem could not be reproduced anymore. It is now working with this new build, as well as the current beta. So it must have been a different issue. We'll make logs next time.

@mateusz
Copy link

mateusz commented Mar 6, 2022

Thank you for fixing this! Amazing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hub: cityhub Issues related to the LEGO Powered Up Smart hub (Hub No. 4) hub: handset Issues related to the LEGO Powered Up Handset (remote control) OS: macOS Issues that only occur on macOS software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth topic: remote control Issues related to remotly controlling hubs
Projects
None yet
Development

No branches or pull requests

6 participants