arjenhiemstra / ithowifi

Itho wifi add-on module (ESP32 wifi to itho I2C protocol)
GNU General Public License v3.0
170 stars 29 forks source link

Fix utc time for WPU #236

Closed tomkooij closed 4 months ago

tomkooij commented 4 months ago

Fixes #235

This fixes the UTC time not being show on WPU 5G. (It turn out not be an uint32 being truncated or a JSON serialising thing, but a duplicate key in the WPU statuslables.

This also removes the field uintval in IthoSystem.h type IthoDeviceStatus. The uintval field is actually never used and if used, handling of the value is not implemented.

Handling of int values (signed/unsigned) is probably not 100% bugfree. But at value "in the wild" seem to be handled fine.

arjenhiemstra commented 4 months ago

Thanks! Furthermore, we could also replace all doubles with floats I guess? Is there ever a case where we need more than 7 decimals precision? edit (not than I'm asking you to do it by the way) all do it in a separate commit)

TD-er commented 4 months ago

Typical use case where you easily get to loose decimals is when performing calculations like adding large numbers. (multiplying doesn't really remove decimals) For example:

float a = 1.23456f;
a += 1000000;
float b = a - 1000000;

N.B. Highly dependent on the platform you're using whether you actually loose bits as the compiler may optimize away stuff and if it is still in registers you may see higher internal resolutions like 80-bit for float on x86.

So when changing from double to float, it may become important to look at any calculations you perform to see if you will run into issues due to lost precision. It is not just a matter of how much do you really need, but what you do with the data inbetween collecting it and using it.

arjenhiemstra commented 4 months ago

Typical use case where you easily get to loose decimals is when performing calculations like adding large numbers. (multiplying doesn't really remove decimals) For example:

float a = 1.23456f;
a += 1000000;
float b = a - 1000000;

N.B. Highly dependent on the platform you're using whether you actually loose bits as the compiler may optimize away stuff and if it is still in registers you may see higher internal resolutions like 80-bit for float on x86.

So when changing from double to float, it may become important to look at any calculations you perform to see if you will run into issues due to lost precision. It is not just a matter of how much do you really need, but what you do with the data inbetween collecting it and using it.

thx only a few multiplications and direct use of the values (which seem to have just 2 decimals at most)

TD-er commented 4 months ago

multiplication/division hardly costs any resolution, so you're fine there.