Skip to content

Writing "" to a Characteristic? #930

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

Open
vicatcu opened this issue Apr 3, 2025 · 2 comments
Open

Writing "" to a Characteristic? #930

vicatcu opened this issue Apr 3, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@vicatcu
Copy link

vicatcu commented Apr 3, 2025

I have a characteristic that is a string. If I use nRF Connect and Write value as text, and leave the New value field empty and Send, I get feedback from my write event handler for the characteristic receives a non-blank string:

Serial.print("Characteristic Written: ");
const char * str = pCharacteristic->getValue().c_str();
Serial.println(str);

The value received by the callback happens to be a string that has length 1 and contains just the first letter of the previously initialized value of the characteristic. This seems like new behavior / a bug to me. What do you think?

Incidentally, that's the same result I get from my own app instead of nRF connect, which uses the @capacitor-community/bluetooth-le plugin and does this:

      import { BleClient, RequestBleDeviceOptions, numbersToDataView } from '@capacitor-community/bluetooth-le';
      ...
      // value is a string to be sent
      const bytes: number[] = value.split('').map(v => v.charCodeAt(0));
      const dv = numbersToDataView(bytes);
      await BleClient.write(deviceId, _service, _characteristic, dv, {timeout});

... to be clear, this used to work just fine.

@vicatcu
Copy link
Author

vicatcu commented Apr 4, 2025

My workaround is to change my app to append a null terminator explicitly:

      import { BleClient, RequestBleDeviceOptions, numbersToDataView } from '@capacitor-community/bluetooth-le';
      ...
      // value is a string to be sent
      const bytes: number[] = value.split('').map(v => v.charCodeAt(0));
      bytes.push(0x00); // ADDED THIS LINE
      const dv = numbersToDataView(bytes);
      await BleClient.write(deviceId, _service, _characteristic, dv, {timeout});

@h2zero
Copy link
Owner

h2zero commented Apr 6, 2025

Thanks @vicatcu, I will test this and see what's happening.

@h2zero h2zero added the bug Something isn't working label Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants