Help Implementing Bluetooth Classic RFCOMM program upload/run on EV3 without USB #2816
Unanswered
GLEM-Nambiar
asked this question in
Q&A
Replies: 1 comment
|
As it happens, we're working on this right now! We're hoping to publish a test version in a week or so. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi Pybricks team and community,
I am looking for some help getting wireless program uploading working on the LEGO MINDSTORMS EV3 with Pybricks.
My main goal is simple:
I would like to be able to program the EV3 from my Mac without having to connect a USB cable every time I want to upload and run a new program.
I am completely fine using USB initially to install Pybricks firmware.
What I am trying to eliminate is needing USB for normal development afterward.
Ideally, I would like a workflow such as:
or something similar where I can press Run in VS Code and have the program transferred wirelessly to the EV3.
What I am trying to achieve
My ideal workflow would be:
The important part for me is:
My setup
I am currently using:
pybricksdevWhat already works
USB program upload works
I can currently upload and run programs using USB.
For example:
This works correctly.
I can also successfully build custom EV3 Pybricks firmware from source.
The resulting firmware package is:
So my development environment itself appears to be working.
What I tried with Bluetooth
Because my main goal is wireless uploading, I started experimenting with the Bluetooth Classic RFCOMM work from PR #452 / the
ev3-bluetooth-rfcommbranch.I was able to get an EV3 Python program to listen for an RFCOMM connection.
For example:
This worked.
I was able to see a successful RFCOMM connection.
For example:
I also got Mac → EV3 Bluetooth communication working
On macOS, I created a small native test program using Apple's
IOBluetoothframework.I was able to connect from the Mac to the EV3 over Bluetooth Classic RFCOMM.
I was also able to send data such as:
and receive it on the EV3.
So I have successfully reached this point:
That made me think Bluetooth may be a possible transport for wireless program uploading.
However, I do not know if RFCOMM is actually the best or intended solution.
I am open to using a different wireless method if Pybricks already has a better architecture for this.
The problem with my current Bluetooth approach
The RFCOMM connection currently requires a Python program on the EV3 to already be running something like:
That does not solve my actual problem.
It results in something like:
But what I want is:
I do not want a separate Bluetooth receiver Python program to be required before I can upload the real program.
What I found while looking through Pybricks
While investigating the source, I noticed that the Pybricks host system already has commands related to program uploading and execution.
I found commands including:
From what I understand, these already provide functionality similar to:
I also found code where USB and Bluetooth register the Pybricks host command handler.
For example:
This made me wonder whether there is already a way, or an intended architecture, for adding another wireless host connection.
What I tried next
I experimented with modifying the EV3 RFCOMM implementation so that Bluetooth could exist at the firmware level rather than requiring:
inside a user program.
I was able to make modified firmware compile successfully.
However, I ran into problems with Bluetooth discoverability/connectability after boot.
At that point I decided that I was probably going too far into modifying the Bluetooth driver without understanding the intended Pybricks architecture.
Rather than continue guessing, I wanted to ask here.
My main questions
1. Is wireless program upload to the EV3 already possible?
Is there currently any supported or experimental way to do something equivalent to:
with the EV3?
If so, I would much rather use the existing method.
2. What is the best wireless transport for the EV3?
Would you recommend using:
or:
or:
or another approach?
My priority is simply getting a reliable wireless connection for uploading and running Pybricks programs.
3. Can Bluetooth be available immediately after Pybricks boots?
Ideally I want:
without first running a Python program such as:
Is there an existing Pybricks host service that provides something like this?
4. Can the existing host command system be reused?
Since I found:
would a wireless transport normally feed into the existing Pybricks host command system?
Conceptually:
Or am I misunderstanding the role of those commands?
5. Is RFCOMM the wrong layer to modify?
I started modifying:
but I suspect program uploading should probably be implemented at a higher level.
Is there a host/transport abstraction that I should be looking at instead?
6. How does Pybricks normally transfer a compiled program?
On the Mac side, I would eventually like to do:
or possibly add support directly to
pybricksdev.What is the recommended way to compile a
.pyprogram into exactly the data that the EV3 program loader expects?I would prefer to reuse the existing Pybricks tooling rather than recreate the compiler/upload protocol.
7. Would this be easier on the current Pybricks 4.1 codebase?
I originally experimented with the RFCOMM development branch.
Would you recommend moving this work to the current Pybricks 4.1 beta/main branch before going any further?
I am not committed to RFCOMM
I want to emphasize that RFCOMM itself is not my end goal.
RFCOMM was simply the first wireless method I managed to get working between my Mac and EV3.
My actual goal is:
If Bluetooth Classic RFCOMM is not the right solution, I am completely open to another approach.
Ideal final result
Ultimately, I would love to be able to do something like:
or:
and have it perform:
Then I could eventually connect that command to the Run button in VS Code.
That would give me a normal development cycle without repeatedly plugging and unplugging USB from the EV3.
If anyone can point me toward the correct Pybricks host architecture, an existing wireless implementation, relevant source files, or a better approach than RFCOMM, I would really appreciate the help.
I am happy to test experimental changes and build custom EV3 firmware if necessary.
Thank you!
All reactions