Jump to content

Get outdoor weather station identifier

Loïc G.

Recommended Posts

Hello !

I'm trying to get the data from a Outdoor Weather bricklet using the C/C++ bindings from uC.
I want to use `tf_outdoor_weather_get_station_data` instead of the callback methods. For this I first need to get the station identifier using `tf_outdoor_weather_get_station_identifiers` but I'm unable to get it to work.

uint8_t * stations_id;
uint16_t * station_nb;
tf_outdoor_weather_get_station_identifiers(&ow, stations_id, station_nb);
tf_hal_printf("nb: %I16u - station 1: %I16u\n", station_nb, stations_id);

Returns 0 for both the values.
I get correct values when using the callback methods so the communication is working.

Any clue on what I'm doing wrong ?

Link to comment
Share on other sites

On 8/13/2022 at 8:18 PM, Loïc G. said:

I think it can be done in a better way using a pointer instead of a array of 255 uint8_t elements

Nope, you have to pass a buffer with enough space for 256(!) entries. The station IDs are collected in this buffer and the Bricklet can detect up to 256 stations.

Theoretically you cound call

tf_outdoor_weather_get_station_identifiers(&this->ow, nullptr, &station_nb);

first to get the number of stations and then creating a buffer that is large enough, for example with

uint8_t *stations_id = (uint8_t*) malloc(stations_nb * sizeof(uint8_t));

However this is dangerous, as the Bricklet could receive another new station after the call to get the number of stations, but before the second call to get the station IDs. So don't do this!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...