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] Connecting to remote suppresses standard output #417

Closed
laurensvalk opened this issue Aug 4, 2021 · 6 comments
Closed

[Bug] Connecting to remote suppresses standard output #417

laurensvalk opened this issue Aug 4, 2021 · 6 comments
Assignees
Labels
bug Something isn't working hub: handset Issues related to the LEGO Powered Up Handset (remote control) hub: movehub Issues related to the LEGO BOOST Move hub platform: Powered Up Issues related to LEGO Powered Up software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: bluetooth Issues involving bluetooth

Comments

@laurensvalk
Copy link
Member

Describe the bug
Some output gets suppressed after connecting to the remote and reading the name.

Changing the name also appears to fail.

This happens consistently, so may provide some debugging starting points,

To reproduce

from pybricks.pupdevices import Remote
from pybricks import version

print(version)

# Connect to any remote.
print("Connecting...")
my_remote = Remote()

print("Connected to:") 

# Print the current name of the remote.
print(my_remote.name())

# Choose a new name.
my_remote.name('truck2')

print("Done!")

Gives

('technichub', '3.1.0a3', 'v3.1.0a3-37-g3c277462 on 2021-08-04')
Connecting...
et
Done!

Expected behavior

('technichub', '3.1.0a3', 'v3.1.0a3-37-g3c277462 on 2021-08-04')
Connecting...
Connected to:    <----- This is missing altogether
handset:  <----- Probably. Seems like we see last two characters. And it's the same despite changing it.
Done!
@laurensvalk laurensvalk added bug Something isn't working platform: Powered Up Issues related to LEGO Powered Up hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) labels Aug 4, 2021
@dlech
Copy link
Member

dlech commented Aug 4, 2021

And it's the same despite changing it.

This is probably a separate issue. I think this happens because we disconnect the handset at the end of the program. When we send a message, it is using write without response. We only block until this message has been sent to the local Bluetooth chip. But there are already other messages queued there from printing to stdout. The disconnect command probably doesn't wait for these queued messages to be sent and drops them. If you add a delay to the end of the program, the name will change as expected. Printing to stdout still works after the program has ended since that is a different connection that is not disconnected.

So I think the solution for that one is to figure out if there is any kind of feedback from the Bluetooth chips to see if all pending messages have been sent before disconnecting after the user program has ended.

Another possibility could be to use write with response instead of write without response. This would make communication slower since we always have to wait for the response. And the user would have to handle the error if they don't want the program to crash when a message failed.

As a workaround, adding a wait(500) to the end of the program should make the name change take effect.

We can also compare the behavior to the SPIKE/RI large hub since it currently uses write with response (but it doesn't raise an error on failure yet).

@dlech dlech added the topic: remote control Issues related to remotly controlling hubs label Aug 12, 2021
@dlech dlech added topic: bluetooth Issues involving bluetooth hub: handset Issues related to the LEGO Powered Up Handset (remote control) and removed topic: remote control Issues related to remotly controlling hubs labels Aug 12, 2021
@dlech dlech self-assigned this Aug 16, 2021
@dlech
Copy link
Member

dlech commented Aug 17, 2021

This is fixed on City and Technic hubs now (fix for #432 fixes this). Similar changes still need to be made to the Move hub.

@dlech
Copy link
Member

dlech commented Aug 18, 2021

Fix for Move hub has been committed now as well.

@dlech dlech closed this as completed Aug 18, 2021
@dlech
Copy link
Member

dlech commented Aug 18, 2021

It looks like this is not entirely fixed. The original test case works now, but when I run the following program on the Move hub, the output ends at Connected to: truck2 with no newline. When the program ends, the IDE doesn't update (stop button is still active). We known the program has ended because pressing the button on the hub starts the in-flash-memory program, but the IDE still doesn't respond (meaning status messages are not being sent/received). Disconnecting the hub from the IDE fixes everything.

from pybricks.hubs import ThisHub
from pybricks.pupdevices import Remote
from pybricks import version
from pybricks.parameters import Color
from pybricks.tools import StopWatch

print(version)

hub = ThisHub()

print("Connecting...")
remote = Remote()

print("Connected to:", remote.name()) 

timer = StopWatch()

for h in range(360):
    c = Color.BLUE << h
    remote.light.on(c)
    hub.light.on(c)

print(timer.time())

print("Done!")

@dlech dlech reopened this Aug 18, 2021
@dlech dlech added hub: movehub Issues related to the LEGO BOOST Move hub and removed hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) labels Nov 17, 2021
@BertLindeman
Copy link

BertLindeman commented Oct 18, 2022

Copied from #736
[EDIT] test below ran using CI-build 2130 [/EDIT]

Print output not OK on the MoveHub.

Even on a simple print does not get correct output.
Example:

print("          1         2         3         4         5         6         7         8")
print("0123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 ")

produces:

          1         2         3         4         5         6         7         8
0123456789 123456789 123456789 123456789 123456789 123456789
789

With a wait(20) after each print, the output is correct:

          1         2         3         4         5         6         7         8
0123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789

@dlech
Copy link
Member

dlech commented Mar 23, 2023

After some reworking of the BlueNRG driver, the reproducible case from #417 (comment) is fixed. There were probably multiple contributing factors to the various symptoms, but the commit pybricks/pybricks-micropython@04d548a is the first commit where the symptom "When the program ends, the IDE doesn't update (stop button is still active)." is fixed.

@dlech dlech closed this as completed Mar 23, 2023
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: handset Issues related to the LEGO Powered Up Handset (remote control) hub: movehub Issues related to the LEGO BOOST Move hub platform: Powered Up Issues related to LEGO Powered Up 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

3 participants