Closed Sonnbc closed 3 years ago
Sorry, but i dont see what problem you may have. Logs seems to be correct, no crash, what do you mean by long value?
Sorry, but i dont see what problem you may have. Logs seems to be correct, no crash, what do you mean by long value?
Hi @chegewara,
By long value I mean I send a string that is relatively large in size (80 characters) to the characteristic. You can see in the sketch, the Serial.printf
statement should print
onWrite aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccdddddddddddddddddddd
But instead, it printed
onWrite onWrite aaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccdddddddddddddddddddd
which is incorrect.
As I described in the reproduce part, changing the Serial.printf
line fixes the problem but the two statements should be equivalent and this probably indicates that there is some memory issue here.
PS: I have changed the original post to make it a bit more clear.
I dont think it is issue with ble, it looks like some issue with Serial.printf. To confirm it you can try for loop and print every single character from value. It is strange, because i never got issues like this.
The value is definitely overwritten. I changed the code to:
class BLEManager : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
const char* value = pCharacteristic->getValue().c_str();
Serial.printf("onWrite %s\n", value);
Serial.print("char printing:");
for (int i = 0; i < strlen(value); i++) {
Serial.print(value[i]);
}
Serial.println();
}
};
And here is the log:
onWrite onWrite aaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccdddddddddddddddddddd
char printing:onWrite onWrite aaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccdddddddddddddddddddd
I dont know what to say or how to explain this. I am using BLE in many projects, but never got something like this.
Even in this line it looks like 2 onWrite
is appended in front, but your actual string is still the same (wrong) length:
char printing:onWrite onWrite
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.
Hardware:
Board: ESP32 Dev Module. I have a NodeMCU-32 v1.2 and have tried it with
Node32s
,NodeMCU-32S
andESP32 Dev Module
board options with the same result. Core Installation version: 1.0.4 IDE name: Arduino IDE Flash Frequency: 40Mhz. Also tried with 80Mhz with the same result. PSRAM enabled: no Upload Speed: 115200 Computer OS: Mac OSXDescription:
I'm creating a BLE server on my ESP dev module with 1 characteristic. Writing a long string to this characteristic (for example, with the nRF Connect app on my phone) seems to cause memory corruption on the board.
Reproduce:
aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccdddddddddddddddddddd
(20 characters ofa
,b
,c
,d
each) to the only characteristic on the BLE server.Problem: Arduino IDE console on the server shows wrong output:
the string
onWrite
(8 bytes) is duplicated and written into our long string. Only 12a
s left. This seems like a memory bug.Output:
But why did the original printf statement fail to print correctly?
Sketch:
Debug Messages: