0

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(); } 
2
  • Can you try another app like nRF Connect to write your value to the arduino and check if the error also happens there? This could help to pinpoint the source of the error. Commented Feb 2, 2021 at 17:32
  • yes, I tried before but it was the same. Not I'm using the event handler for the characteristic and it works. arduino.cc/en/Reference/… Commented Feb 5, 2021 at 17:14

1 Answer 1

1

Finally I tried using a event handler for the characteristic and now it works.

Before this I tried with apps like LightBlue and nRF Connect but I still receive not more than 4 bytes.

I don't know why with the event handler works...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.