You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, I am afraid this may face the exact same bugs that I had in my original implementation, and then fixed today (as described in my previous post).
Firstly, the pm25 input argument for that function is an integer, and that is then used for some divisions (e.g. pm25 / 20). I believe for the division to work correctly, the pm25 should be float instead.
Similarly, with hardcoded values in other divisions, e.g. “3/2” in line 292 and “21/5” in line 296. The divisions numerators should be float as well (e.g. replace 3 with 3. , and 21 with 21.) to work as expected.
At least these are the things I had to fix to make my implementation work, and seem to be similar in the github arduino code too. I’m not that familiar with C++, and may therefore be overlooking some details in the github implementation though. But I thought it would be worth to report it to you to double check.
PS: After sending it, I noticed there may be at least another issue with the arduino code in particular. For example, line 296 seems to be missing a power of 2 on a pm25 reference:
From our forum:
https://forum.airgradient.com/t/pms5003-cf-1-or-cf-atm-data/2298/6
Hi @Achim_AirGradient just a note here - as I was looking for the newly introduced compensated code in the arduino github repo, I found that you have a recent implementation in here (arduino/src/PMS/PMS.cpp at master · airgradienthq/arduino · GitHub).
However, I am afraid this may face the exact same bugs that I had in my original implementation, and then fixed today (as described in my previous post).
Firstly, the pm25 input argument for that function is an integer, and that is then used for some divisions (e.g. pm25 / 20). I believe for the division to work correctly, the pm25 should be float instead.
Similarly, with hardcoded values in other divisions, e.g. “3/2” in line 292 and “21/5” in line 296. The divisions numerators should be float as well (e.g. replace 3 with 3. , and 21 with 21.) to work as expected.
Finally, the cast of the result back to int may not be rounded properly. For example, the expected result 20.89 for input values of PM2.5=33 and RH=40 would be returned as 20 instead of 21. As discussed here: floating point - C++: How to round a double to an int? - Stack Overflow
At least these are the things I had to fix to make my implementation work, and seem to be similar in the github arduino code too. I’m not that familiar with C++, and may therefore be overlooking some details in the github implementation though. But I thought it would be worth to report it to you to double check.
PS: After sending it, I noticed there may be at least another issue with the arduino code in particular. For example, line 296 seems to be missing a power of 2 on a pm25 reference:
(8.84f * (1.e-4) * pm25* (pm25/50 - 21/5))
@pnt325 please check implementation.
The text was updated successfully, but these errors were encountered: