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 zu diesem Kommentar
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 zu diesem Kommentar
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.

Gast
Reply to this topic...

×   Du hast formatierten Text eingefügt.   Formatierung jetzt entfernen

  Only 75 emoji are allowed.

×   Dein Link wurde automatisch eingebettet.   Einbetten rückgängig machen und als Link darstellen

×   Dein vorheriger Inhalt wurde wiederhergestellt.   Clear editor

×   Du kannst Bilder nicht direkt einfügen. Lade Bilder hoch oder lade sie von einer URL.

×
×
  • Neu erstellen...