CHARACTERISTIC_UUID: UUID = UUID.fromString("0000ffe1-0000- 1000-8000-00805f9b34fb")
, которые, я думаю, являются полной формой FFE0 и FFE1. Я пропустил какой-нибудь шаг?
Код: Выделить всё
override fun onCharacteristicRead(
gatt: BluetoothGatt,
characteristic: BluetoothGattCharacteristic,
status: Int
) {
super.onCharacteristicRead(gatt, characteristic, status)
if (status == BluetoothGatt.GATT_SUCCESS) {
// Read the value from the characteristic
// Update the readValue variable
readValue = characteristic.value
val s = characteristic.value.size
// Log the read status
Log.v("bluetooth", "onCharacteristicRead size: $s")
} else {
// Log if the read operation failed
Log.e("bluetooth", "onCharacteristicRead: failed")
}
}
Код: Выделить всё
#include
SoftwareSerial HC08(2,3);
void setup() {
Serial.begin(9600);
HC08.begin(9600);
}
float value1 = 0;
float value2 = 10;
void loop() {
byte bytes[8]; // Array to hold bytes for two floats
byte *bytePtr = (byte *)&value1;
for (int i = 0; i < 4; i++) {
bytes[i] = bytePtr[i];
}
bytePtr = (byte *)&value2;
for (int i = 0; i < 4; i++) {
bytes[i + 4] = bytePtr[i];
}
// Now, send the bytes array over Bluetooth
Serial.print("Sent data\n");
HC08.write(bytes, sizeof(bytes));
//HC08.write("abc");
value1++;
value2--;
delay(1000);
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... acteristic
Мобильная версия