weatherbit - How does rain function works?

https://github.com/sparkfun/pxt-weather … it.ts#L187

Hi all, I’m questioning about the weatherbit.rain() function, after many attempts I’ve not come up with a solution, yet.

I’ve not understood how that function works, when the variable numRainDumps is cleared?

Let me explain: every 5 minutes I get new data from the various sensors in the weaterbit, and if the function rain() returns a value greater than 0 I save this value in a variable “fallingRain”. Imagine it rains for 20 minutes, it correctly save the value. But, after some minutes rain ends, the rain() function doesn’t returns the previous falling rain, but it returns 0 again… Even if in the code in the link there’s no time where the variabile numRainDumps is cleared, so how it’s possible that rain() returns 0? Ans if it’s so, how can I save the value and clear it manually only at midnight? Thanks a lot for helping!

We aren’t truly equipped to handle issues with the coding side of things, but I’ll do my best here: I think it’s because the function is being called as an ‘init’, and being set back to ‘0’ each time

Try adding your ‘fallingRain’ to a new variable, something like “totalRainToday”, then saved as a separate file?

This is interesting… You’re probably right! Yeah, I’ve considered that option, but I wasn’t sure it was the right way… So the ‘init’ is called everytime che function “start rain monitoring()” is called? So, everytime i call start rain monitoring, ‘rain()’ returns 0 unless it’s raining?

Thanks very much! If this is correct now I’ll be able to get the correct value of daily raining.