Humidity tag support in custom firmware

Hi,
I want to add support for humidity tag in my custom firmware, but I realized there are multiple revisions of the tag. As I use this firmware as generic for multiple devices, I want to support all tag revisions.

SDK docs (Firmware SDK: twr_tag_humidity) are not very helpful, there are no examples and no information about how to detect tag revision. In generic firmware (https://github.com/hardwario/bcf-generic-node/blob/master/app/sensors.c) is each revision handled like individual tag on low level which I don’t like.

So, how can I detect humidity tag presence and revision using twr_tag_humidity? And some example how to implement publishing measures would be nice too. :slight_smile:

Thanks for help.
Mixi

You can go through all the I2C addresses and read a register from the sensor. If you get ACK message, you are sure there is some sensor. However not every time this is true since some I2C sensors have the same address. Here comes handy the WHOAMI / WHO_AM_I / MANUFACTURER ID registers which contains fixed unique numbers you can use to detect the correct chip.

Current system in generic is not bad (by the C language meaning), since it tries more than reading a single value from a sensor - it starts the complete driver and looks if there is an communication error, then it tries another sensor.

I asked colleague who wrote generic FW and humidity drivers and I might add some update soon.

HTS221

HDC2080

SHT20

Here is serial number which could have comon prefix that can be used to confirm that you are talking to this chip
image

Well, probing manually I2C and checking devide ids is someting I really want to avoid. So that when you start selling R5 humidity tag, I ideally just want to update sdk and recompile the FW. :smiley:

I was thinking about calling twr_tag_humidity_init() for each revision and try to read value, but from SDK source code it seems that neither init, nor measure will fail out when sensor is not present. So I’m kind of lost here, as I wanted to avoid copy-paste sensor detection from generic FW when there is higher level abstraction in SDK.

There is no other way to reliably do that, we would do the same thing in the SDK.

We can help you to add it to the SDK. If you create such function that checks for humidity and share the code with us, we could test it and implement it. The best would be if you add it to the SDK and create a pull-request, however if it sounds complicated, plain C function would be also helpful. However I do not have all the versions at hand, so not sure who will test that for all revisions.

I thought that it emits errors. In the generic FW there are events which has to work so it clears the structure and tries another sensor. See TWR_HTS221_EVENT_ERROR, TWR_HDC2080_EVENT_ERROR and TWR_SHT20_EVENT_ERROR. Are you sure they are not triggered when the sensor is not connected?

note: to support the most peripherals including LCD and LED strip Core Module struggles with RAM. So we have universal sensor item using union and from this sensor pool the drivers tries to initialize the sensors. If it fails, then it deinitilizes sensor/peripherals, clears a single sensor_t from the pool and tries another sensor in the table.
https://github.com/hardwario/bcf-generic-node/blob/master/app/sensors.h#L58

There is no other way to reliably do that, we would do the same thing in the SDK.

We can help you to add it to the SDK. If you create such function that checks for humidity and share the code with us, we could test it and implement it. The best would be if you add it to the SDK and create a pull-request, however if it sounds complicated, plain C function would be also helpful. However I do not have all the versions at hand, so not sure who will test that for all revisions.

Thanks for info. I don’t have much time right now, so I guess easiest way is to copy detection code from generic firmware. I’d like to see it in SDK though, so if I have time later, I might try to make it more generic and create pull request to SDK. Do you have some contribution rules / guideline written?

To be honest, I’m not very sure about this, due to asynchronous implementation it is not very obvious and I looked at the code rather briefly. I’ll try to check it more throuroughly.

Not written yet, since there is not much PRs from outside. Just follow the style/naming you feel from the current code and we fix/help with the rest. Focus on the functionality.

We use .editorconfig file which describes tabs/spaces, so you can use in your IDE (vscode has plugin)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.