LEGO / lego-ble-wireless-protocol-docs

This repository contains information about LEGO Hubs (name, battery level, etc.) and to interact with any sensors and motors connected to it.
https://lego.github.io/lego-ble-wireless-protocol-docs
MIT License
334 stars 43 forks source link

Startup / connection sequence: Best practices #12

Open Diamondback2010 opened 4 years ago

Diamondback2010 commented 4 years ago

Hello,

I'm looking for some information on best practices for the startup and connection process. Right now it appears that a connected hub immediately triggers its IO attached events for devices already attached at startup. However, I noticed that this sometimes takes multiple seconds to complete (for example, 3 out 4 of attached messages arrive right away while the 4th arrives 4 or 5 seconds later), which makes judging the connection state a bit difficult. Are there any tips on how to best time the connection process so that the connecting side is aware of "when" the handshake and everything is done?

marcrupprath commented 4 years ago

I am thinking about this, too:

Question is why whe wan't to know a specific "attached profile" ?

Two simple cenarios: Opperarting Rally car, and Crawler with same (hardware) remote conrol.

Knowledge of attached profile is needed , because Motors configuration is different in number an connection location.

I solved it as follows:

  1. At first i have stored the MAC Addresses of the hubs my cars have in the µC ROM.
  2. I have also provided a button where i can toggle the car profiles.

As a result i can opperate both car types using both hubs, with only minor selection opperation by the user, its a simple seelction switch on the remote you can use a toggle switch also,

Following the "KISS" concept: Profile indication is done by a simple LED and pulse code.

As a result a don't need to gues or read the configuration because i always know what is the real configuration of modell selected.

hope that helps.

Marc

marcrupprath commented 4 years ago

An addition: I am thinking about what would be a good practise to identify a new hub within a group of others. Assume that you are curently do not know any specific mac address.

My idea is to do as known from the "Binding" process of comon RC Remote controls. I think it must be possibe to attach a "unique" Resitor value to Port "A " for example. Question is i don't know exactly which connection to use and what the value will be when hub gets connected.

Doeas someone have a simple answer to do so ?