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

Sensor / Actor - Metadata: Retrieve live or cache / hardcode? #13

Open Diamondback2010 opened 4 years ago

Diamondback2010 commented 4 years ago

Hello,

when talking to devices connected to a hub, is it generally a good idea to always fetch their metadata (modes, value formats, min/max ranges) live or is it relatively safe (as in most likely won't change in the future) to just cache this data and/or assume it? Requesting everything live takes quite a while to complete, especially with motors and the color sensor.

marcrupprath commented 4 years ago

Can you please send an example how you fetch meta data? Because documentation is missing some practical examples: Can be send to marc.rupprath@web.de

Many thanks ;-)

undera commented 4 years ago

There's at least this Python implementation: https://github.com/undera/pylgbst/blob/master/pylgbst/peripherals.py#L163

Diamondback2010 commented 4 years ago

I have the meta-data retrieval completely live at the moment, it works fine, always returns the correct information, it just takes a while upon connection to transfer all the data...

So I'm purely wondering if it's a workable idea to skip this step and just have the relevant data locally available or if we should expect frequent changes to the format of the devices (can the actor/sensor firmware even be updated?)

Diamondback2010 commented 4 years ago

Can you please send an example how you fetch meta data? Because documentation is missing some practical examples: Can be send to marc.rupprath@web.de

Many thanks ;-)

It's fairly straight forward when you actually start using all the data that is available. You start off by handling all the IO messages, after you know all connected devices, send a Mode Info request and a Mode Combination Info request to get all the modes and possible combinations, after that you need to request the mode specific data for each mode. For sensors and motors that adds up to a lot of stuff...

tthiery commented 4 years ago

@Diamondback2010 In my lib I decided for code-based caching the data by hw/sw version of the device. The data of the the relevant messages is static and will not change if Lego adheres to the hw/sw versioning number concept. I mean a device is not suddenly getting new modes or classification changes of the given modes.