Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth mesh: Generic Battery Client parser does not correctly parse Generic Battery Status Messages (IDFGH-14593) #15349

Open
3 tasks done
connyhald opened this issue Feb 6, 2025 · 0 comments
Assignees
Labels
Status: Opened Issue is new Type: Bug bugs in IDF

Comments

@connyhald
Copy link

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.4 and git master

Espressif SoC revision.

ESP32-C3

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

Development Kit.

Seeed Studio XIAO ESP32C3

Power Supply used.

USB

What is the expected behavior?

I'm sending Generic Battery Status messages from a Generic Battery Server model to a Generic Battery Client model.

I would expect the parameters for time_to_discharge and time_to_charge to be the same on the receiver side then they have been on the sender side. See: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/bluetooth/esp-ble-mesh.html#_CPPv436esp_ble_mesh_gen_battery_status_cb_t

What is the actual behavior?

What I receive is something different then what I did send.

Steps to reproduce.

  1. Implement a Generic Battery Server on device A
  2. Implement a Generic Battery Client on device A
  3. Provision both devices (I did use the nRF Mesh app from Nordic)
  4. Setup publication on the Generic Battery Server model to publish to group X
  5. Setup subscription on the Generic Battery Client model to subscribe to group X
  6. Observe what gets send by the server and what gets received by the client - e.g. by logging the values
  7. Also use the nRF Mesh Sniffer app to sniff the traffic between the two nodes

Debug Logs.


More Information.

The following screenshot shows how the message looks like when sniffed and how it is (correctly I think) interpreted. Please focus on Time to Discharge and Time to Charge and ignore Battery Flags (there seems to be an issue on the Nordic side).
Image

On the receiver side we log the following for the same mesh message.

I (1304601) Client -- Received Generic Battery Status
I (1304601) Client -- Battery Level: 100
I (1304601) Client -- Time to Discharge: 1576960
I (1304611) Client -- Time to Charge: 8656384
I (1304611) Client -- Flags: 0x00

Note that Battery Level is fine but Time to Discharge and Time to Charge is wrong.

I think the issue can be found here:

uint32_t value = 0;
value = net_buf_simple_pull_le32(buf);
status->battery_level = (uint8_t)value;
status->time_to_discharge = (value >> 8);
value = net_buf_simple_pull_le32(buf);
status->time_to_charge = (value & 0xffffff);
status->flags = (uint8_t)(value >> 24);

Please see the following screenshot that shows the expected and the actual value. Please note how similar the bit pattern is. I think there is an error in the above code that leads to some bits being shifted wrongly.
Image

@connyhald connyhald added the Type: Bug bugs in IDF label Feb 6, 2025
@github-actions github-actions bot changed the title Bluetooth mesh: Generic Battery Client parser does not correctly parse Generic Battery Status Messages Bluetooth mesh: Generic Battery Client parser does not correctly parse Generic Battery Status Messages (IDFGH-14593) Feb 6, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants