thingsboard-client-sdk icon indicating copy to clipboard operation
thingsboard-client-sdk copied to clipboard

Request all shared attributes

Open JellevanKraaij opened this issue 1 year ago • 3 comments

Hello everyone,

Is it possible to request all shared attributes and not just only 1 key?

JellevanKraaij avatar Apr 09 '24 19:04 JellevanKraaij

It is not possible to request all keys, at least to my knowledge.

But this limitation is not from this library, but instead the ThingsBoard API. See the official MQTT Documentaion for more info.

Alternatively, you can use the Shared_Attribute_Subscribe method, which subscribes to any changes or creation of new shared attributes.

For that simply pass the Shared_Attribute_Callback instance, but keep the 2nd parameter empty. Because if no keys are configured you are subscribed to all key changes.

MathewHDYT avatar Apr 09 '24 19:04 MathewHDYT

Yeah i see now, thnx. Shared_Attribute_Subscribe without keys is not very useful right? Because if the device is offline it cant know that it was created to later request it.

JellevanKraaij avatar Apr 10 '24 06:04 JellevanKraaij

Yes that is the case updates in between states of being offline will be lost. I'll check the API again to really ensure if it isn't possible to request all keys, because with REST it is.

But if it were it would be an undocumented feature, which would definetly need to be changed.

Will update this thread once I tested it, but I dont have high hopes.

MathewHDYT avatar Apr 10 '24 07:04 MathewHDYT

@JellevanKraaij Check this example: https://thingsboard.io/docs/pe/devices-library/esp32-dev-kit-v1/

Using Shared_Attributes_Request() method you can request attributes from the server once the device is connected. But you have to set attributes on the callback level.

skokovsergey avatar Jun 14 '24 03:06 skokovsergey

Thanks for tip @skokovsergey, it is unfortunately required to list the attributes, you can't request all attributes without knowing their names

JellevanKraaij avatar Jun 17 '24 12:06 JellevanKraaij