-
Notifications
You must be signed in to change notification settings - Fork 34
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
Using several Lpf2Hub instances possible? #54
Comments
Hi @fredlcore! Connecting to multiple hubs is defenitely possible. Up to now you can have a connection to up to 9 hubs from one esp32. If you want to use more than three hubs, you have to configure the NimBLE-Arduino lib according to the followin procedure: https://github.com/corneliusmunz/legoino#connection-to-more-than-3-hubs You can find ab example of connections to multiple hubs in the following sketch: Now the issue #46 comes into place. Adding the non blocking scan has some benefits but also some drawbacks and you can "remove" the non blocking change by changing the following line in the Non blocking scan start: Change to blocking scan start: With this change the connection procedure should work for multiple hubs and you can check for each hub instance if it is connected with the myTrainHub1.init("90:84:2b:03:19:7f"); // initialize the listening train hub 1 // here you have to use your own device ids You can find an example in the |
Thanks for the detailed feedback! The reason why I would like to do this with an array of |
I just figured out the reason why my code was not working properly: I assumed that after issuing an |
@corneliusmunz: I now found a solution that works with non-blocking scan and gives you the freedom to initialize up to nine hubs without adding extra code - just by going through a loop using an array:
Later on, in the loop() function, I can use this to both execute individual code for each train as well as restart scanning after the initial scanning period is over, so that any disconnected device can easily reconnect:
Maybe this is an (easier) option for your TwoTrainHubs or MultipleTrainHubs examples as well? |
First of all, I'm not sure if this is a doublette of #46 - if so, feel free to close this right now.
I'm trying to connect my ESP32 to three Lego Duplo trains. The way I'm doing this is that I setup an array of Lfp2Hub objects like this:
and then send all of them into init mode in setup():
Subsequently, I can cycle through them in a for-loop:
However, this only works for the first train to be connected, and this will always be the last element of the myHubs array (2 in this case). Also, once the first connection is made, any subsequent train that is turned on won't connect.
After reading #46, I was wondering if this also has to do with the blocking-/non-blocking approach. But if changing to a blocking model would be necessary to connect multiple hubs, wouldn't that mean that I'd have to a) define how many hubs I want to use and b) make sure that all of these hubs are connected before the code will continue to execute? Because that's what blocking means, isn't it?
My goal would be that my kids can decide whether they put 1, 2 or 3 trains on the track and all active ones could be controlled (I would use the PS3 controller's "SELECT" button to switch between them). However, it seems that with blocking mode, they would have to always use the same number of trains, wouldn't it?
The text was updated successfully, but these errors were encountered: