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

Acaia Lunar fw V1.0.0.16 bug #7

Closed SongKeat2901 closed 3 months ago

SongKeat2901 commented 3 months ago

Acaia Lunar 2021 FW 1.0.0.16 Using ESP32-S3

I had tried the code and it doens't want to update new weight. After some digging i found that these 2 "_read.valueUpdated() && _read.valueLength() == 13 "conditon check always fail. I have no idea on how to get .valueUpdated to turn true but i found that the valueLength is 17 instead of 13. if the device is powered of or disconnected, the valueLength is 6

Wonder did you encounter this before?

SongKeat2901 commented 3 months ago

Acaia Lunar 2021 FW 1.0.0.16 Using ESP32-S3

I had tried the code and it doens't want to update new weight. After some digging i found that these 2 "_read.valueUpdated() && _read.valueLength() == 13 "conditon check always fail. I have no idea on how to get .valueUpdated to turn true but i found that the valueLength is 17 instead of 13. if the device is powered of or disconnected, the valueLength is 6

Wonder did you encounter this before?

I realized if using the bareMinimum, the refresh rate was too fast, the response from the scale is 5Hz, a minimum delay (500) is needed.

As of the valueLength, it is still 17

tatemazer commented 3 months ago

Hi SongKeat, so if I understand correctly, read.valueUpdated() never returns true? What are you seeing on the serial output?

I just tested bareMinimum again with my Pyxis, and confirmed the refresh rate is ok. there is a lot of data other than the 5hz weight-information packets, and there shouldn't be issues with polling the scale for new incoming packets.

SongKeat2901 commented 3 months ago

Hi Tatemazer, in bareMinimum when i tried with ESP32-S3, i think it is checking too frequently, as a reasult read.valueUpdated() unable to return a "true" value. until i slow it down with a delay, then this statement return "true".

The real issue is actually the " _read.valueLength() == 13", after i got pass the valueupdated(), this statement" _read.valueLength() == 13" is not true. I was testing it with the following device.

Acaia Lunar 2021 FW 1.0.0.16 Using ESP32-S3

I ended up do a print to show the value returned on the valuelength after valueupdate was true, it return 17 instead of 13.

Not sure did it even occur on your end, or is it due to the new FW 1.0.0.16. As of now, the code work flawlessly after add in some delay on the BareMinimum and changes the valuelength to 17.

Just wanna open up this topic to help out other fellows when they having issue with the codes.

tatemazer commented 3 months ago

Ok, I see the scale's fw version was released very recently, so maybe this update broke the code. I will get my hands on a scale in the coming days to troubleshoot a permanent solution.

tatemazer commented 3 months ago

@SongKeat2901 I've performed an update on a lunar 2021 and found the update seems to be causing this issue. Unfortunately I don't recall exactly what version I started with, i believe something like 1.0.006 or 1.0.008.

Could you please send me over the exact changes you made to get the code working? either via a pull request or just show me the changes in the code here.

thanks!

tatemazer commented 3 months ago

by the way, I've just added a debug mode in V2.2.0 to help with troubleshooting. set DEBUG to true to enable.

SongKeat2901 commented 3 months ago

@SongKeat2901 I've performed an update on a lunar 2021 and found the update seems to be causing this issue. Unfortunately I don't recall exactly what version I started with, i believe something like 1.0.006 or 1.0.008.

Could you please send me over the exact changes you made to get the code working? either via a pull request or just show me the changes in the code here.

thanks!

Hi Tatemazer,

I just do it by brute force, I printed the value of _read.valueLength() and found it to be 17. So I just changed this statement to “_read.valueLength() == 17”

Yet to come up with more elegant solution for now.

tatemazer commented 3 months ago

@SongKeat2901 I've performed an update on a lunar 2021 and found the update seems to be causing this issue. Unfortunately I don't recall exactly what version I started with, i believe something like 1.0.006 or 1.0.008.

Could you please send me over the exact changes you made to get the code working? either via a pull request or just show me the changes in the code here.

thanks!

Hi Tatemazer,

I just do it by brute force, I printed the value of _read.valueLength() and found it to be 17. So I just changed this statement to “_read.valueLength() == 17”

Yet to come up with more elegant solution for now.

Ah. So you found that adding a delay somewhere was actually not necessary?

SongKeat2901 commented 3 months ago

Yes. the delay is no longer necessary, it was part of artifact when i tried to debug the conditions. Explained below.

the old code for lunar is this "if (NEW == _type && _read.valueUpdated() && _read.valueLength() == 13 && _read.readValue(input,13) && input[4] == 0x05)"

(due to the bug in 13 and 17 in the valueLength (FW bug))when i tried to troubleshoot i think my approach was check the condition one by one. such as checking the below idividually. _read.valueUpdated() _read.valueLength()

That is when i ran into the issue where the 5Hz matters. If i just trying to print the bool result of the _read.valueUpdated(), is very hard to capture the "true" becuase it happened to fast and get flooded with subsequent falses.

i saw you had updated the code below, which should mitigate the issued i had encouter previously.

// the read.value will turn true evey 5hz and allow the data to get grabbed. if(_read.valueUpdated()){ byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0}; int l = _read.valueLength();

SongKeat2901 commented 3 months ago

currently my code look as below: bool AcaiaArduinoBLE::newWeightAvailable()

{
    byte input[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    if (NEW == _type && _read.valueUpdated() && _read.valueLength() == 17 && _read.readValue(input,13) && input[4] == 0x05)
    {
        // Grab weight bytes (5 and 6)
        //  apply scaling based on the unit byte (9)
        //  get sign byte (10)
        _currentWeight = (((input[6] & 0xff) << 8) + (input[5] & 0xff)) / pow(10, input[9]) * ((input[10] & 0x02) ? -1 : 1);

        return true;
    }

i had only replace 13 with 17.

tatemazer commented 3 months ago

@SongKeat2901 great thanks, happy to hear that's all it takes. I just need to be able to identify this requirement so I know whether to read for 13 or 17 bytes. could you please run the code with debug-mode enabled so I can see if there are any identifiers?

SongKeat2901 commented 3 months ago

The test output as below

Scale Interface test Found d2:f0:ec:30:7a:3f 'Loc' Found 60:8a:10:58:1c:b4 'LUNAR-581CB4' Connecting ... Connected Discovering attributes ... Attributes discovered

Device name: LUNAR- Appearance: 0x0

Service 1800 Characteristic 2a00, properties 0x2, value 0x4C4C55554E4E414152522D2D Service 49535343-c9d0-cc83-a44a-6fe238d06d33 Characteristic 49535343-aca3-481c-91ec-d85e28a60318, properties 0x18 Descriptor 2902, value 0x000000 Service 49535343-fe7d-4ae5-8fa9-9fafd205e455 Characteristic 49535343-1e4d-4bd9-ba61-23c647249616, properties 0x18 Descriptor 2902, value 0x000000 Descriptor 2803, value 0x Descriptor 9bb3, value 0x Descriptor 43f4, value 0x Descriptor 5b01, value 0x Characteristic 49535343-8841-43f4-a8d4-ecbe34729bb3, properties 0xC Descriptor 2803, value 0x Descriptor 3b7e, value 0x Descriptor 39b3, value 0x Descriptor 5b01, value 0x Characteristic 49535343-4c8a-39b3-2f49-511cff073b7e, properties 0x1C Descriptor 2902, value 0x000000 Service 180a Characteristic 2a29, properties 0x2, value 0x4D4D434348485050 Descriptor 2803, value 0x Descriptor 2a24, value 0x42424D4D37373030 Characteristic 2a24, properties 0x2, value 0x42424D4D37373030 Descriptor 2803, value 0x Descriptor 2a25, value 0x3030303030303030 Characteristic 2a25, properties 0x2, value 0x3030303030303030 Descriptor 2803, value 0x Descriptor 2a27, value 0x353535353030353520203131303032325F5F4C4C4545535344444B4B Characteristic 2a27, properties 0x2, value 0x353535353030353520203131303032325F5F4C4C4545535344444B4B Descriptor 2803, value 0x Descriptor 2a26, value 0x303030303939303031313030 Characteristic 2a26, properties 0x2, value 0x303030303939303031313030 Descriptor 2803, value 0x Descriptor 2a28, value 0x3030303030303030 Characteristic 2a28, properties 0x2, value 0x3030303030303030 Descriptor 2803, value 0x Descriptor 2a23, value 0x000000000000000000000000 Characteristic 2a23, properties 0x2, value 0x000000000000000000000000 Descriptor 2803, value 0x Descriptor 2a2a, value 0x000000000000011000000000 Characteristic 2a2a, properties 0x2, value 0x000000000000011000000000 New version Acaia Detected subscribed! identify write successful notification request write successful tare write successful tare write successful

not showing the scale weight if using the below code if (NEW == _type && l == 17 && input[4] == 0x05) sometime it show 3: 0x0221414077 3: 0x0221414077 12: 0xEFEFDDDD0CC0CC055000000000000011000077 5: 0x0000000221414077 3: 0xEFEFDDDD0CC 5: 0xEFEFDDDD0CC0CC055 12: 0x0000000000000110000770000000221414077 1: 0xEFEF 1: 0xEFEF 6: 0xEFEFDDDD0CC0CC055000 11: 0x0000000000110000770000000221414077 10: 0xEFEFDDDD0CC0CC055000000000000011 7: 0x0000770000000221414077

also not working if i only change the l equal to 17 if (NEW == _type && l == 17 && input[4] == 0x05)

only work if i used the old code as below: if (NEW == _type && _read.valueLength() == 17 && _read.readValue(input,13) && input[4] == 0x05)

Screenshot 2024-05-18 at 19 15 27 Screenshot 2024-05-18 at 19 16 32
SongKeat2901 commented 3 months ago

i did some modification on the debug the "14" is battery parameter that i try to get.

Scale Interface test Found 60:8a:10:58:1c:b4 'LUNAR-581CB4' Connecting ... Connected Discovering attributes ... Attributes discovered

Device name: LUNAR- Appearance: 0x0

Service 1800 Characteristic 2a00, properties 0x2, value 0x [0]:4C [1]:55 [2]:4E [3]:41 [4]:52 [5]:2D Service 49535343-c9d0-cc83-a44a-6fe238d06d33 Characteristic 49535343-aca3-481c-91ec-d85e28a60318, properties 0x18 Descriptor 2902, value 0x [0]:00 [1]:00 Service 49535343-fe7d-4ae5-8fa9-9fafd205e455 Characteristic 49535343-1e4d-4bd9-ba61-23c647249616, properties 0x18 Descriptor 2902, value 0x [0]:00 [1]:00 Descriptor 2803, value 0x Descriptor 9bb3, value 0x Descriptor 43f4, value 0x Descriptor 5b01, value 0x Characteristic 49535343-8841-43f4-a8d4-ecbe34729bb3, properties 0xC Descriptor 2803, value 0x Descriptor 3b7e, value 0x Descriptor 39b3, value 0x Descriptor 5b01, value 0x Characteristic 49535343-4c8a-39b3-2f49-511cff073b7e, properties 0x1C Descriptor 2902, value 0x [0]:00 [1]:00 Service 180a Characteristic 2a29, properties 0x2, value 0x [0]:4D [1]:43 [2]:48 [3]:50 Descriptor 2803, value 0x Descriptor 2a24, value 0x [0]:42 [1]:4D [2]:37 [3]:30 Characteristic 2a24, properties 0x2, value 0x [0]:42 [1]:4D [2]:37 [3]:30 Descriptor 2803, value 0x Descriptor 2a25, value 0x [0]:30 [1]:30 [2]:30 [3]:30 Characteristic 2a25, properties 0x2, value 0x [0]:30 [1]:30 [2]:30 [3]:30 Descriptor 2803, value 0x Descriptor 2a27, value 0x [0]:35 [1]:35 [2]:30 [3]:35 [4]:20 [5]:31 [6]:30 [7]:32 [8]:5F [9]:4C [10]:45 [11]:53 [12]:44 [13]:4B Characteristic 2a27, properties 0x2, value 0x [0]:35 [1]:35 [2]:30 [3]:35 [4]:20 [5]:31 [6]:30 [7]:32 [8]:5F [9]:4C [10]:45 [11]:53 [12]:44 [13]:4B Descriptor 2803, value 0x Descriptor 2a26, value 0x [0]:30 [1]:30 [2]:39 [3]:30 [4]:31 [5]:30 Characteristic 2a26, properties 0x2, value 0x [0]:30 [1]:30 [2]:39 [3]:30 [4]:31 [5]:30 Descriptor 2803, value 0x Descriptor 2a28, value 0x [0]:30 [1]:30 [2]:30 [3]:30 Characteristic 2a28, properties 0x2, value 0x [0]:30 [1]:30 [2]:30 [3]:30 Descriptor 2803, value 0x Descriptor 2a23, value 0x [0]:00 [1]:00 [2]:00 [3]:00 [4]:00 [5]:00 [6]:00 [7]:00 Characteristic 2a23, properties 0x2, value 0x [0]:00 [1]:00 [2]:00 [3]:00 [4]:00 [5]:00 [6]:00 [7]:00 Descriptor 2803, value 0x Descriptor 2a2a, value 0x [0]:00 [1]:00 [2]:00 [3]:00 [4]:01 [5]:00 [6]:00 [7]:00 Characteristic 2a2a, properties 0x2, value 0x [0]:00 [1]:00 [2]:00 [3]:00 [4]:01 [5]:00 [6]:00 [7]:00 New version Acaia Detected subscribed! identify write successful notification request write successful tare write successful tare write successful 14: 0x [0]:EF [1]:DD [2]:08 [3]:09 [4]:30 [5]:02 [6]:02 [7]:01 [8]:00 [9]:01 [10]:01 [11]:01 [12]:0E [13]:33 Battery : 48 14: 0x [0]:EF [1]:DD [2]:08 [3]:09 [4]:30 [5]:02 [6]:02 [7]:01 [8]:00 [9]:01 [10]:01 [11]:01 [12]:0E [13]:33 9: 0x [0]:EF [1]:DD [2]:0C [3]:0C [4]:05 [5]:00 [6]:00 [7]:00 [8]:00 8: 0x [0]:01 [1]:00 [2]:07 [3]:00 [4]:00 [5]:02 [6]:14 [7]:07 13: 0x [0]:EF [1]:DD [2]:0C [3]:0C [4]:05 [5]:00 [6]:00 [7]:00 [8]:00 [9]:01 [10]:00 [11]:07 [12]:00 4: 0x [0]:00 [1]:02 [2]:14 [3]:07 19: 0x [0]:EF [1]:DD [2]:0C [3]:0E [4]:05 [5]:00 [6]:00 [7]:00 [8]:00 [9]:01 [10]:00 [11]:06 [12]:30 [13]:07 [14]:00 [15]:00 [16]:02 [17]:1C [18]:37

SongKeat2901 commented 3 months ago

My result

14: 0x | Pycia Payload Number |   -- | -- | -- [0]:EF | Header 1 |   [1]:DD | Header 2 |   [2]:08 | Command / Message Type | 8  == Setting parameter [3]:09 | 0 \| Number of byte Length |   [4]:30 | 1 | &07F to get Battery Value [5]:02 | 2 | 2 == gram \| 5 == ounces [6]:02 | 3 |   [7]:01 | 4 | Self off duration = payload * 5 [8]:00 | 5 |   [9]:01 | 6 | Beep sound On/off 1= On [10]:01 | 7 |   [11]:01 | 8 |   [12]:0E | 9 \| Checksum 1 |   [13]:33 | 10 \| Checksum 2 |  

SongKeat2901 commented 3 months ago

Occasionally i get message with 19 length as well, just to compare

17: 0x | Pycia Payload Number |   | 19: 0x |   -- | -- | -- | -- | -- [0]:EF | Header 1 |   | [0]:EF |   [1]:DD | Header 2 |   | [1]:DD |   [2]:0C | Command / Message Type | 0C == 12 | [2]:0C |   [3]:0C | Packet Length | 12 | [3]:0E | 14 [4]:05 | 5 == Weight |   | [4]:08 |   [5]:01 | Weight Data |   | [5]:08 |   [6]:00 | Weight Data |   | [6]:05 |   [7]:00 |   |   | [7]:05 |   [8]:00 |   |   | [8]:00 |   [9]:01 | Weight Unit | unit=  weight_payload[4] & 0xFF;     if (unit == 1): value /= 10.0  elif (unit == 2): value /= 100.0  elif (unit == 3): value /= 1000.0  elif (unit == 4): value /= 10000.0 | [9]:00 |   [10]:03 | Weight Sign | If bit 2 = true, result is negative | [10]:00 |   [11]:07 |   |   | [11]:01 |   [12]:00 |   |   | [12]:01 |   [13]:00 |   |   | [13]:07 |   [14]:02 |   |   | [14]:00 |   [15]:15 |   |   | [15]:00 |   [16]:0A |   |   | [16]:02 |     |   |   | [17]:23 |     |   |   | [18]:10 |  

tatemazer commented 3 months ago

@SongKeat2901 Great notes! thats helpful documentation.

I've just pushed 32f6a7d46e2bab31dbd9a156933716f0b0401427 which I think should be logically equivalent to your fix, along with still working with the other scales. If you'd be so kind as to test out this fix to confirm on your end, that'd be super helpful, thanks!

tatemazer commented 3 months ago

https://github.com/tatemazer/AcaiaArduinoBLE/commit/32f6a7d46e2bab31dbd9a156933716f0b0401427 Tested on a lunar 2021 with fw v1.0.0.16. closing out

Found 60:8a:10:4d:b2:49 'LUNAR-4DB249' Connecting ... Connected Discovering attributes ... Attributes discovered

Device name: LUNAR- Appearance: 0x0

Service 1800 Characteristic 2a00, properties 0x2, value 0x4C554E41522D Service 49535343-c9d0-cc83-a44a-6fe238d06d33 Characteristic 49535343-aca3-481c-91ec-d85e28a60318, properties 0x18 Descriptor 2902, value 0x0000 Service 49535343-fe7d-4ae5-8fa9-9fafd205e455 Characteristic 49535343-1e4d-4bd9-ba61-23c647249616, properties 0x18 Descriptor 2902, value 0x0000 Descriptor 2803, value 0x Descriptor 9bb3, value 0x Descriptor 43f4, value 0x Descriptor 5b01, value 0x Characteristic 49535343-8841-43f4-a8d4-ecbe34729bb3, properties 0xC Descriptor 2803, value 0x Descriptor 3b7e, value 0x Descriptor 39b3, value 0x Descriptor 5b01, value 0x Characteristic 49535343-4c8a-39b3-2f49-511cff073b7e, properties 0x1C Descriptor 2902, value 0x0000 Service 180a Characteristic 2a29, properties 0x2, value 0x4D434850 Descriptor 2803, value 0x Descriptor 2a24, value 0x424D3730 Characteristic 2a24, properties 0x2, value 0x424D3730 Descriptor 2803, value 0x Descriptor 2a25, value 0x30303030 Characteristic 2a25, properties 0x2, value 0x30303030 Descriptor 2803, value 0x Descriptor 2a27, value 0x35353035203130325F4C4553444B Characteristic 2a27, properties 0x2, value 0x35353035203130325F4C4553444B Descriptor 2803, value 0x Descriptor 2a26, value 0x303039303130 Characteristic 2a26, properties 0x2, value 0x303039303130 Descriptor 2803, value 0x Descriptor 2a28, value 0x30303030 Characteristic 2a28, properties 0x2, value 0x30303030 Descriptor 2803, value 0x Descriptor 2a23, value 0x0000000000000000 Characteristic 2a23, properties 0x2, value 0x0000000000000000 Descriptor 2803, value 0x Descriptor 2a2a, value 0x0000000001000000 Characteristic 2a2a, properties 0x2, value 0x0000000001000000 New version Acaia Detected subscribed! identify write successful notification request write successful 17: 0xEFDD0C0C05E701000001020700712AF5C8 -48.70 17: 0xEFDD0C0C05E701000001020700712AF5C8 -48.70 17: 0xEFDD0C0C05E701000001020700712AF5C8 -48.70 17: 0xEFDD0C0C05E701000001020700712AF5C8 -48.70