我只能通过 Flutter Blue 向 Arduino 33 BLE 发送 4 个字节
I can only send to Arduino 33 BLE 4 bytes via Flutter Blue
我正在尝试发送一个电话号码和一个代码(我正在使用解码器在 Arduino 中读取它并知道这个号码是给一个联系人还是其他人,因为我要保存不同的电话号码) 从 Flutter 应用程序到 Arduino 设备(设备:BLE 33)。我正在使用 ArduinoBLE 库和 flutter_blue 库。
为了发送数字,我需要 6 个字节:例如,对于数字 112233445,一个字节用于 11,第二个字节用于 22,第三个字节用于 33,4º 字节 44 和 5º 字节为 5。代码f.e。 4,在另一个字节中。
在 Arduino 中,我用来读取的函数是 settingsCharacteristic.readValue(buffer, size_of_buffer)。而在 Flutter 中是 characteristic.write(List).
我要发送"04112233445" -> 4是代码,其余是号码。
问题是在 Arduino 中我只收到 4 个字节。
颤动代码:
void sendTelephoneNumber(BluetoothCharacteristic characteristic) {
String exampleCode = "01";
characteristic
.write(utf8
.encode(exampleCode + myController.text));
}
(myController 是我写数字的 TextField 的控制器)
Arduino代码:
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();
}
最后我尝试使用 event handler for the characteristic,现在可以了。
在此之前,我尝试使用 LightBlue 和 nRF Connect 等应用程序,但我仍然收到不超过 4 个字节。
我不知道为什么事件处理程序可以工作...
我正在尝试发送一个电话号码和一个代码(我正在使用解码器在 Arduino 中读取它并知道这个号码是给一个联系人还是其他人,因为我要保存不同的电话号码) 从 Flutter 应用程序到 Arduino 设备(设备:BLE 33)。我正在使用 ArduinoBLE 库和 flutter_blue 库。
为了发送数字,我需要 6 个字节:例如,对于数字 112233445,一个字节用于 11,第二个字节用于 22,第三个字节用于 33,4º 字节 44 和 5º 字节为 5。代码f.e。 4,在另一个字节中。
在 Arduino 中,我用来读取的函数是 settingsCharacteristic.readValue(buffer, size_of_buffer)。而在 Flutter 中是 characteristic.write(List).
我要发送"04112233445" -> 4是代码,其余是号码。
问题是在 Arduino 中我只收到 4 个字节。
颤动代码:
void sendTelephoneNumber(BluetoothCharacteristic characteristic) {
String exampleCode = "01";
characteristic
.write(utf8
.encode(exampleCode + myController.text));
}
(myController 是我写数字的 TextField 的控制器)
Arduino代码:
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();
}
最后我尝试使用 event handler for the characteristic,现在可以了。
在此之前,我尝试使用 LightBlue 和 nRF Connect 等应用程序,但我仍然收到不超过 4 个字节。
我不知道为什么事件处理程序可以工作...