Bluetooth Hub to Hub communication #2002
-
I just started working with Pybricks and I hope that my question is not completely silly. I am trying to communicate between a city hub and a technic hub to control my train. The train sends a message "switch" to the track switch. This does, however, not happen all the time. How can I ensure that the message is sent and received? Moreover, the message should only be processed once. Right now, I pause the program on the technic hub (track switch) for a longer time after it received a message to ensure it does not process the same message twice. The train broadcasts the message for 800ms right now. I hope that is long enough. I made a little YouTube video to show the behaviour of the system: https://youtu.be/Z5ptezsdyBY Here is the program for the technic hub (track switch):
and here is the program for the train:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This communication method works best for broadcasting continuous 'states' rather than sending 'messages'. As a reasonable analogy, think of you and a friend on distant rooftops where you can see but not hear each other. Instead of blinking a light briefly to indicate a switch (which would be easy to miss) you might set the light continously green for straight and red for turning. Your friend would always know how to set the switch by observing the signal, no matter when they look or no matter the initial position. In this example, instead of broadcasting 'switch now' for some time in the hope that someone will hear it, it is better to broadcast 'straight' or 'turn' as applicable. This will be correct even if you miss any messages. You also don't need any delays this way. The hub continues broadcasting your last value until you change it - no need to repeat it yourself. On the receiving end, you could make the motor move the switch if the motor is not already in the correct position. As a side note, it works even better if your broadcasts all have the same length, such as 'trn' and 'str'. Or simply 1 and 2. (This isn't the issue here, but it can be a factor if you want to send more data signals at once) |
Beta Was this translation helpful? Give feedback.
This communication method works best for broadcasting continuous 'states' rather than sending 'messages'.
As a reasonable analogy, think of you and a friend on distant rooftops where you can see but not hear each other. Instead of blinking a light briefly to indicate a switch (which would be easy to miss) you might set the light continously green for straight and red for turning. Your friend would always know how to set the switch by observing the signal, no matter when they look or no matter the initial position.
In this example, instead of broadcasting 'switch now' for some time in the hope that someone will hear it, it is better to broadcast 'straight' or 'turn' as applicable. This wil…