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

Payload used as string, thus "prints" adds garbage #7637

Closed
1 task done
Franck78 opened this issue Dec 28, 2022 · 6 comments · Fixed by #7699
Closed
1 task done

Payload used as string, thus "prints" adds garbage #7637

Franck78 opened this issue Dec 28, 2022 · 6 comments · Fixed by #7699
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Type: Example Issue is related to specific example.

Comments

@Franck78
Copy link

Franck78 commented Dec 28, 2022

Board

ESP32-S3

Device Description

homemade

Hardware Configuration

homemade

Version

latest master (checkout manually)

IDE Name

ARduino IDE

Operating System

linux

Flash frequency

40

PSRAM enabled

no

Upload speed

115200

Description

Hello
v2.0.6

this is the output of the demo program using BLE_client

https://github.com/espressif/arduino-esp32/blob/master/libraries/BLE/examples/BLE_client/BLE_client.ino

We are now connected to the BLE Server.
Notify callback for characteristic 0000ffe1-0000-1000-8000-00805f9b34fb of data length 2
data: AT⸮⸮⸮?�⸮$

The data length is correct, I recognize just an 'AT' command from the HC06.
Line 32 of the demo program uses the payload directly as a string (serial.print) .

Maybe just add a warning for readers: this is a payload interpreted wrongly as a string for simplicity of the demo.

Sketch

bool isNotify) {
    Serial.print("Notify callback for characteristic ");
    Serial.print(pBLERemoteCharacteristic->getUUID().toString().c_str());
    Serial.print(" of data length ");
    Serial.println(length);
    Serial.print("data: ");
    Serial.println((char*)pData);

Debug Message

x

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@Franck78 Franck78 added the Status: Awaiting triage Issue is waiting for triage label Dec 28, 2022
@SuGlider
Copy link
Collaborator

Are you sure that HC-06 can be used as BLE?!
As far as I know HC-06 is Bluetooth v2.0 (classic) only.
Therefore it can't be used as BLE device.

@SuGlider
Copy link
Collaborator

The S3 can only connect using BLE with another BLE device.
You may consider using another ESP32/C3/S3 to connect, or maybe, a BLE module such as the HM-10, instead of HC-06.

@SuGlider SuGlider self-assigned this Dec 28, 2022
@Franck78
Copy link
Author

Franck78 commented Dec 28, 2022

well, I swear to you I'm using my HC06 with the app you pointed me (ble client ino)

May be the bug is line 32 if we say that the 'bluetooth' transports an array of byte and a size for that array.

What I call HC-06 is the small thing from aliexpress .
https://www.aliexpress.com/item/1005002168517770.html
chip is CSR BC417143 (https://www.aliexpress.com/item/32323413263.html)

apparently, original one was bt2.0
https://www.digikey.com/en/products/detail/BC417143B-IRN-E4/BC417143B-IRN-E4DKR-ND/2001050
and probably upgraded with 'core 4.0' as seen on some other datasheet

@SuGlider
Copy link
Collaborator

SuGlider commented Dec 29, 2022

Considering that your HC06 works with BLE, I can tell you that BLE doesn't understand NULL terminated strings.

The sender will send a payload with a defined length.
The receiver side will read the length and then get the payload.

If you want to Serial.print(char *) the payload, you shall add the '\0' at pData[length].

@SuGlider SuGlider added Type: Question Only question and removed Status: Awaiting triage Issue is waiting for triage labels Dec 29, 2022
@Franck78
Copy link
Author

If you want to Serial.print(char *) the payload, you shall add the '\0' at pData[length].

it happens it is your app in need of this zero ;)

@Franck78 Franck78 changed the title missing null terminator for string Payload used as string, thus "prints" adds garbage Dec 29, 2022
@SuGlider
Copy link
Collaborator

I'll add that to the example. Thanks.

@SuGlider SuGlider added Area: BT&Wifi BT & Wifi related issues Type: Example Issue is related to specific example. and removed Type: Question Only question labels Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Type: Example Issue is related to specific example.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants