tatemazer / AcaiaArduinoBLE

Acaia Scale Gateway using the ArduinoBLE library for devices such as the esp32 and other Bluetooth-enabled Arduino compatible hardware.
MIT License
40 stars 6 forks source link

Weight calculation wrong for Acaia Lunar from 2019 #2

Closed whitebearded closed 5 months ago

whitebearded commented 6 months ago

I can't thank you enough! Finally, I've a really fast and stable BLE connection to my acaia lunar scale from 2019.

However, it took me a while to get the calculation correct as it was always returning 0.0. https://github.com/tatemazer/AcaiaArduinoBLE/blob/69b21a3f944b5fd5e99a673eed3354172ca84e6f/AcaiaArduinoBLE.cpp#L151

I think this is how it might need to look like:

_currentWeight = (((input[3] & 0xff) << 8) + (input[2] & 0xff)) / pow(10, (input[6])) * ((input[7] & 0x02) == 0x02 ? -1 : 1);

For me this is working like a charm now. So it's using byte input[6] instead of input[5] for the power and I also added a sign check on byte input[7]. This was inspired by the LunarGatewayLibrary. By the way, the sign check seems to be missing for the "new" scale implementation, too.

I hope this may be helpful! Keep up the great work!

tatemazer commented 6 months ago

Hey @whitebearded , thanks so much for reporting this and sorting out the solution. I've fixed the power byte (cbba21b3b8c632649cd4a71444c78a4f7a2d919c) and added the sign to the output (ec1ffae0d2aafb5df5d5e58a9c89ab245b3aaeb1). I've tested it out on my pyxis but don't have a readily available lunar 2019, so it would be very helpful if you could confirm the functionality as well before I create a release. thanks!