I'm trying to send a telephone number and a code (I'm using de code to read it in Arduino and know if this number is for one contact or other, because I'm gonna save different telephone numbers) vía ble from a Flutter app to a Arduino device (device: BLE 33). I'm using the ArduinoBLE library and the flutter_blue library.
For sending the number I need 6 bytes: for example for the number 112233445 one byte is for 11, second byte is for 22, third byte is for 33, 4º byte 44 and 5º byte is 5. And the code f.e. 4, is in another byte.
In Arduino, the function that I'm using to read is settingsCharacteristic.readValue(buffer, size_of_buffer). And in Flutter is characteristic.write(List).
I would like to send "04112233445" -> 4 is the code and the rest is the number.
The problem is that in Arduino I only receive 4 bytes.
Flutter code:
void sendTelephoneNumber(BluetoothCharacteristic characteristic) { String exampleCode = "01"; characteristic .write(utf8 .encode(exampleCode + myController.text)); } (myController is the controller for a TextField where I write the number)
Arduino code:
void t5Callback() { BLEDevice central = BLE.central(); if (central && central.connected()) { if (settingsCharacteristic.written()) { byte buffer[6]; settingsCharacteristic.readValue(buffer, 6); for (int i = 0; i < 6; i++) { Serial.println(buffer[i]); } int code = buffer[0]; unsigned long telephone = 0; telephone = (buffer[1] + 512 << 32) | (buffer[2] << 24) | (buffer[3] << 16) | (buffer[4] << 8) | (buffer[5]); Serial.printf("Code: %d\n", code); Serial.printf("Telephone: %lu\n", telephone); switch (code) { case 7: saveTelephone1(telephone); break; case 8: saveTelephone2(message); break; default: //todo break; } } } yield(); }