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

HubEmulation and PoweredUpRemote at a time #62

Open
paki111 opened this issue Oct 24, 2021 · 9 comments
Open

HubEmulation and PoweredUpRemote at a time #62

paki111 opened this issue Oct 24, 2021 · 9 comments

Comments

@paki111
Copy link

paki111 commented Oct 24, 2021

I combined HubEmulation and PoweredUpRemote functionality in one sketch. Now I can controll my esp32 with PoweredUp controller and at the same time in PoweredUp app I can connect emulated hub but controlls from the app doesn't work.

Every functionality separetely works fine, but in tandem only PoweredUpRemote works.

@paki111 paki111 changed the title HubEmulation and PoweredUpRemote at a time HubEmulation and PoweredUpRemote at a time :enhancement: Oct 24, 2021
@paki111 paki111 changed the title HubEmulation and PoweredUpRemote at a time :enhancement: HubEmulation and PoweredUpRemote at a time Oct 24, 2021
@corneliusmunz
Copy link
Owner

@paki111 First thanks for raising your first issue!
I have never tried to connect a PoweredUpRemote to the ESP and in parallel use the HubEmulation feature and connect to the same ESP with the App. I think this will not work because here the ESP will be the Client (PoweredUpRemote) and the Server (HubEmulation) at the same time. But I am not sure. Can you send me the example of your code that I can have a look on it. Maybe I didn't get your idea right. What do you want to do with that setup?

APP <--> ESP (HubEmulation)
PoweredUpRemote <--> ESP

@corneliusmunz
Copy link
Owner

I have searched the NimBLE-Arduino library about issues where the ESP works as Client and Server at the same time and I found the following issue: h2zero/NimBLE-Arduino#298
Fortunately they got it up and running but it is a matter of when do you initialize what. I have to do a test setup to try it out. The solution of that issue could be found here: h2zero/NimBLE-Arduino#298 (comment)

@corneliusmunz
Copy link
Owner

@paki111 I have got it up and running. I have connected the APP first to the Emulated Hub on the ESP and then connected the PoweredUp remote to the ESP. After that procedure I was able to change the color of the Remote via the APP and the ESP as a proxy in between.

I have added a feature branch (https://github.com/corneliusmunz/legoino/tree/feature/client_server_at_the_same_time) where I have modified the HubEmulation.ino example. Due to the same Device definition I have had to rename the Device struct to get it up and running. Additionally I have stripped out some initialization commands in the Lpf2HubEmulation.cpp file but this is maybe not needed. The important thing is that you have to follow the initialization procedure

  1. Intit and connect the App to the "Server"
  2. Init and connect the Remote to the "Client"

Hope it will work on your side 😄

@paki111
Copy link
Author

paki111 commented Oct 27, 2021

@corneliusmunz Thank you very much for quick response and for resolution. My sketch (HubEmulation.ino) was quite similar, but I did not notice that connection should be client-server for the App and server-client for the Remote.

My idea was to have one sketch for two scenarios: lego RC car controlled sometimes by the App and sometimes by the Remote.

I will check it tonight on my setup.

@paki111
Copy link
Author

paki111 commented Oct 27, 2021

It works absolutely flawless! My idea was to have 2in1 functionality and now we have even 3in1 - we can control the same ESP by the Remote or by the App or by the Remote and App at the same time!

This opens up new possibilities... and this example definitely is worth a commit 🍺 Thank You very much.

@paki111
Copy link
Author

paki111 commented Oct 27, 2021

To use Remote without App connected I slightly modified line in HubEmulation void loop():
if (myEmulatedHub.isConnected && !myRemote.isConnecting() && !myRemote.isConnected() && !isInitializing)
in to:
if (!myRemote.isConnecting() && !myRemote.isConnected() && !isInitializing)
and you even don't need to bother connection order

@corneliusmunz
Copy link
Owner

@paki111 Thanks for testing it on your side and giving feedback. I will check your changes and maybe add this as another example sketch to the library

@paki111
Copy link
Author

paki111 commented Oct 29, 2021

@corneliusmunz OK, I added example for ESP32 D1 mini with Wemos motor shield and tested control via the App and/or Remote.

@yokohtan
Copy link

yokohtan commented Nov 29, 2021

Nice to meet you. I always enjoy using this wonderful library. This library doubles the fun of Lego.
By the way, I'm trying to build an assist function for an excavator, and I'm trying to intervene with an ESP32 between the smartphone Lego app and the Technic hub x2.
Is it possible to make two emulator hubs with one ESP32 and connect to two control hubs at the same time?
Could you give me some advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants