Logging movement counter

Hi all,

For context, I have been messing around with the Ruuvi Firmware a little bit. I have successfully managed to rename the BLE device, increase the movement/vibration threshold, the basics. I am not an embedded engineer, so I struggle to do anything more than that, but I have a use case for what I would like to do.

I am attempting to use Ruuvi Tags for some low-level asset tracking and the movement counter is an extremely important metric to me. Knowing when was an item the tag is attached to dropped is quite important. Because of that, I would like to log the movement counter value periodically (like the temperature and humidity values), so that I at least have 5 minute windows where I can tell whether the item was dropped or not. I found the app_log.c and app_log.h files and I can see some of the functions, but I am not entirely sure where to start and how to let’s say remove pressure, but have the movement counter cached instead.

Any suggestions or guidance welcome :slight_smile:

Hello,

The code is not really generalised to support any free-form fields, but it should be simple enough to hack the support by replacing pressure with movement counter. Since the code deals with floats it’s easiest to convert the counter to float and accept occasional rounding error.

It might be enough to just change the logging logic to store movement counter: .pressure_pa = rd_sensor_data_parse (sample, RD_SENSOR_PRES_FIELD), -> . pressure_pa = (float)app_sensor_event_count_get(),. This stores the movement counter as it was.

The rest of the code coincidentally should handle the pressure values pretty well, pressure is scaled with factor 1.0 (i.e. not scaled) and the range should be 0… 2^31. It seems to me that if the actual movement counter reaches 2^31 or above you’ll get always 2^31 as the reported value. You can implement graceful roll around by dropping the last bit off the movement counter return value return m_event_counter & 0x7FFFFFFF;

I did not test how the changes would work in practise, but the idea should be good to go. First, change the logged pressure value into movement counter and second read the pressure and handle it as movement in your application.

Let me know how it works

1 Like

Hey.

Sorry about the delayed response!

I somehow missed the notification and in the meantime I went ahead with using the app_sensor_event_count_get() function but forgetting to typecast that left me wondering what is wrong… After reading your response it’s now obvious and your implementation works! I have managed to reliably store the movement counter in the air pressure log field and it does exactly what I wanted! The last bit drop to implement a graceful roll around is quite clever and something I overlooked too, so I really appreciate the level of detail you went into.

Thank you again for solving my problem and again I am happy to say that the tag now does exactly what I need it to :slight_smile:

2 Likes