-
Notifications
You must be signed in to change notification settings - Fork 15
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
Make the run
command wait for Hub to get ready
#30
Comments
This would be nice. 👍 However... if this were to become a direction we're going in, perhaps it would be time to pick up the old idea of making a proper Visual Studio Code extension (or something like it) to download and run programs and multi-file projects, and stay connected in between runs.
|
Visual Studio plugin would be nice but then we're stuck with that single IDE. I pretty much like That's why I volunteer to improve |
Giving the issue a second look, I have found the following:
When adding a I suspect the problem is that the Hub initialisation takes some time and when we send data prior to the Hub being initialised, it simply does not receive it and does not reply with the checksum. Am I correct here? I have also noticed the |
I added a similar delay in |
I can see the It's weird though that the same issue does not happen when the Hub is on before executing Since the Hub is ready when the connection is successful, I don't understand what is happening to the data sent. I'd like to fix this stuff properly without using |
Capturing Bluetooth packets to see what is actually going on is usually a good first step. |
Will give it a try. The problem I see is to be able to understand what all the packets mean 😊 |
If you are using SPIKE/MINDSTORMS hub, then the issue could also be that BTStack is doing more in the background than the other Bluetooth drivers on other hubs and it needs a bit of delay before advertising on boot. Also, those hubs now have some blocking code for the external flash memory that could be interfering. |
Tried to capture BLE packets for both scenarios - Hub turned on prior to running The results are the same for finding and connecting to the Hub. Two differences I've observed
|
The blocking flash stuff on startup is a likely offender. To find out, try downgrading the firmware to this one or something older. This commit is from just before merging the new flash code. |
Used the latest Four subsequent
I guess the code in static void stm32_main(void) {
#if PYBRICKS_HUB_PRIMEHUB
mp_hal_delay_ms(500);
pb_flash_init();
#endif |
All of flash needs to be rewritten, not just that one in particular. But if it’s choosing between waiting a second after boot versus no program being stored at all, I’d rather just wait a second for now. :) |
I don't know how this stuff works but wondering, @dlech mentioned that once the Hub is discoverable over BLE, it should be ready. So wondering if the flash init could be done before the Hub can be connected to, that would do the trick. But it might just be it's not possible this way.
As a workaround, I can add |
Assuming that |
@lobodpav, can you please test pybricks/pybricks-micropython@e884640 when it is finished building? |
Tested it now. Something is wrong - after writing the firmware the 3x3 LED square keeps on flashing and the Hub's main button light is off. An attempt to run a program ends with |
I see now that the "block" operations are calling |
Same issue. |
Introduction
When fine-tuning programs and running them via
pybricksdev
, I often run the program several times per minute.However, what happens to me frequently is that
In both cases, the execution fails and I have to either turn the Hub on or stop the program, and then re-run
pybricksdev run
command.It would be much more user firiendly if
pybricksdev
would handle these scenarios:pybricksdev run
is waiting for connection, the program should be loaded and executed once the Hub is turned onpybricksdev run
is executed,pybricksdev
shouldEnvironment
macOS 12
Python 3.10.1
pybricksdev v1.0.0-alpha.24
Inventor Hub
Replication steps
pybricksdev run ble program.py
asyncio.exceptions.TimeoutError
Stack trace
Analysis (
cli/__init__.py
andconnections.py
)device_or_address = await find_device(args.name)
works with a default10s
timeoutawait asyncio.wait_for(self.checksum_ready.wait(), timeout=0.5)
timeout does not helpnus_handler
isn't caled at all for some reason, once the Hub is turned onI've tried to fix the problem myself but failed. Would you guide me on how could I achieve the behaviour described in the
Introduction
section? Happy to code the stuff myself if that's possible.The text was updated successfully, but these errors were encountered: