rbaron / b-parasite

🌱💧 An open source DIY soil moisture sensor
1.93k stars 149 forks source link

Fix battery quantity/size reporting #103

Closed MJDSys closed 1 year ago

MJDSys commented 1 year ago

The API for reporting information requires a pointer to the data value, and cannot deal with a constant directly. The current quantity/size returned by the device are random values from memory.

Instead create a couple constants in the flash memory and return those. The values can be read successfully from Z2M. Attempting to write to the values results in an error to Z2M but does not crash the device.

rbaron commented 1 year ago

Thanks @MJDSys, nice catch.

I would suggest we keep these attributes in the zb_device_ctx struct to be consistent with the other values. We already have a prst_batt_attrs_t there, so we can just extend it with these two values. I think it's okay that they are consts, I would still move them there.

Tks!

MJDSys commented 1 year ago

@rbaron I moved them into the zb_device_ctx struct as requested. I didn't bother to leave them as consts, as that would require some more dramatic changes to the code.

I originally made them const to have them be in flash, but that's not possible if they are in the struct so cost of restructuring the code is probably not there.

rbaron commented 1 year ago

Awesome. Thank you @MJDSys.