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

[Bug] Remote.name() doesn't work on Technic hub #432

Closed
NStrijbosch opened this issue Aug 12, 2021 · 6 comments
Closed

[Bug] Remote.name() doesn't work on Technic hub #432

NStrijbosch opened this issue Aug 12, 2021 · 6 comments
Assignees
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) hub: movehub Issues related to the LEGO BOOST Move hub hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth

Comments

@NStrijbosch
Copy link

Describe the bug
When running the sample script: https://docs.pybricks.com/en/latest/pupdevices/remote.html#changing-the-name-of-the-remote using the Technic hub the remote name is not printed (line 7) and the internal name in the remote is not changed.

To reproduce
Steps to reproduce the behavior:

  1. On a technic hub run the sample script: https://docs.pybricks.com/en/latest/pupdevices/remote.html#changing-the-name-of-the-remote

Expected behavior
I expected the name to be printed and the internal name in the remote to be changed. On the PrimeHub this expected behaviour was obtained.

@NStrijbosch NStrijbosch added the triage Issues that have not been triaged yet label Aug 12, 2021
@dlech
Copy link
Member

dlech commented Aug 12, 2021

Sending messages to LWP3 devices is currently very buggy. Also see #417. As a workaround, you can try adding wait(500) after every call.

SPIKE Prime works since it is using write with response instead of write without response. But I haven't had any luck yet making the same change to the City/Technic hubs.

@dlech dlech added bug Something isn't working hub: cityhub Issues related to the LEGO Powered Up Smart hub (Hub No. 4) hub: movehub Issues related to the LEGO BOOST Move hub hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) 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 hub: handset Issues related to the LEGO Powered Up Handset (remote control) and removed triage Issues that have not been triaged yet topic: remote control Issues related to remotly controlling hubs labels Aug 12, 2021
@NStrijbosch
Copy link
Author

Thanks for the insight! That explains some of my other observations too.

Adding delays up to 2000 ms didn't fix it though..

@dlech dlech self-assigned this Aug 16, 2021
dlech added a commit to pybricks/pybricks-micropython that referenced this issue Aug 17, 2021
This modifies the pbdrv_bluetooth_write_remote() function in the CC2640
driver to use write with response instead of write without response.
This ensures that the remote device received the message before the
task ends.

This fixes issues like messages at the end of a MicroPython program not
being sent before the remote device is disconnected when the program ends.

After this commit, connecting to a Handset fails with RuntimeError.
This is expected due to a separate bug where remote_lwp3_char_handle
is being overwritten (and actually shows that one of the error paths
is working correctly).

Issue: pybricks/support#432
@dlech
Copy link
Member

dlech commented Aug 17, 2021

This should be fixed on the City and Technic hubs now. I still need to make similar changes on Move hub.

@NStrijbosch could you test and see if the Mario hack is still needed? The fixes for this may have fixed that too.

That is, delete this and see what happens:

    // HACK: Characteristics of LEGO Mario are not properly found by GATT_DiscCharsByUUID().
    // remote_lwp3_char_handle for mario is hard coded for now
    if (context->hub_kind == LWP3_HUB_KIND_MARIO) {
        remote_lwp3_char_handle = 0x0012;
    }

@NStrijbosch
Copy link
Author

Yes, this specific bug is fixed now!
From my first tests it seems sending messages from the technic hub to LWP3 devices (remote and city hub) is now more reliable. So this is a good step for multi hub!

On the other hand mario does have issues connecting with this update. I will investigate further!

@dlech
Copy link
Member

dlech commented Aug 18, 2021

If Mario is raising a RutimeError during connection, it could be that we are getting a ATT_EVENT_ERROR_RSP, in which case the following change might work:

diff --git a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
index 92095995..6f94603a 100644
--- a/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
+++ b/lib/pbio/drv/bluetooth/bluetooth_stm32_cc2640.c
@@ -554,6 +554,13 @@ try_again:
         HCI_StatusCodes_t status;
         (payload = get_vendor_event(remote_handle, &event, &status)) && ({
             if (event == ATT_EVENT_ERROR_RSP && payload[0] == ATT_READ_BY_TYPE_REQ) {
+                // HACK: Characteristics of LEGO Mario are not properly found by GATT_DiscCharsByUUID().
+                // remote_lwp3_char_handle for mario is hard coded for now
+                if (context->hub_kind == LWP3_HUB_KIND_MARIO) {
+                    remote_lwp3_char_handle = 0x0012;
+                    goto retry;
+                }
+
                 task->status = PBIO_ERROR_FAILED;
                 goto disconnect;
             }
@@ -577,12 +584,6 @@ try_again:
         });
     });
 
-    // HACK: Characteristics of LEGO Mario are not properly found by GATT_DiscCharsByUUID().
-    // remote_lwp3_char_handle for mario is hard coded for now
-    if (context->hub_kind == LWP3_HUB_KIND_MARIO) {
-        remote_lwp3_char_handle = 0x0012;
-    }
-
     // enable notifications
 
 retry:

@dlech
Copy link
Member

dlech commented Aug 18, 2021

Fix for Move hub has been committed.

We can start a new issue for the Mario regression.

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) hub: movehub Issues related to the LEGO BOOST Move hub hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth
Projects
None yet
Development

No branches or pull requests

2 participants