Hallo, ich versuche einen Neey Balancer per Bluetooth BLE über die ArduinoBLE.h auszulesen. Das Geräte antwortet per subcribe/notify, die durch einen write ausgelöst werden. Ich kann mehrere Parameter korrekt abfragen.
Eine Abfrage gibt die Antwort in zwei Paketen zurück. Im Wireshark / BLE Sniffer werden die Pakete auch korrekt angezeigt. Leider liefert die Funktion simpleKeyCharacteristic.valueUpdated() nur das zweite Paket (Frame 372) zurück, das erste Paket (Frame 370) wird übersprungen, obwohl im Header die Info "More Data: true" steht. Hat jemand eine Idee, woran das liegen kann.
Vielen Dank schon mal an alle
Hier der Code, die Ausgabe der Serial und die Paketmitschnitte des Wireshark.
/*
Basis SensorTag Button
*/
#include <ArduinoBLE.h>
uint8_t data[20] = {0xaa, 0x55, 0x11, 0x01, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0xff};
uint8_t result[400];
int l;
void setup() {
Serial.begin(115200);
while (!Serial);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// start scanning for peripheral
BLE.scan();
}
void loop() {
// check if a peripheral has been discovered
BLEDevice peripheral = BLE.available();
if (peripheral) {
// discovered a peripheral, print out address, local name, and advertised service
Serial.print("Found ");
Serial.print(peripheral.address());
Serial.print(" '");
Serial.print(peripheral.localName());
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
// Check if the peripheral is a GW-24S4EB, the local name will be:
if (peripheral.localName() == "GW-24S4EB") {
// stop scanning
BLE.stopScan();
readmydevice(peripheral);
// peripheral disconnected, start scanning again
BLE.scan();
}
}
}
void readmydevice(BLEDevice peripheral) {
// connect to the peripheral
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
return;
}
// discover peripheral attributes
Serial.println("Discovering service 0xffe0 ...");
if (peripheral.discoverService("ffe0")) {
Serial.println("Service discovered");
} else {
Serial.println("Attribute discovery failed.");
peripheral.disconnect();
while (1);
return;
}
// retrieve the simple key characteristic
BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1");
// subscribe to the simple key characteristic
Serial.println("Subscribing to simple key characteristic ...");
if (!simpleKeyCharacteristic) {
Serial.println("no simple key characteristic found!");
peripheral.disconnect();
return;
} else if (!simpleKeyCharacteristic.canSubscribe()) {
Serial.println("simple key characteristic is not subscribable!");
peripheral.disconnect();
return;
} else if (!simpleKeyCharacteristic.subscribe()) {
Serial.println("subscription failed!");
peripheral.disconnect();
return;
} else {
Serial.println("Subscribed");
Serial.println("write to characteristic");
simpleKeyCharacteristic.writeValue(data, sizeof(data),0);
}
while (peripheral.connected()) {
// while the peripheral is connected
// check if the value of the simple key characteristic has been updated
if (simpleKeyCharacteristic.valueUpdated()) {
Serial.println("update");
l = simpleKeyCharacteristic.readValue(result, 400);
printData(result, l);
Serial.println();
}
}
Serial.println("Disconnected!");
}
void printData(const unsigned char data[], int length) {
for (int i = 0; i < length; i++) {
unsigned char b = data[i];
if (b < 16) {
Serial.print("0");
}
Serial.print(b, HEX);
}
}
##################################################
Ausgabe der seriellen Konsole:
15:12:47.375 -> Found 00:e4:4c:21:dc:3f 'GW-24S4EB' ffe0
15:12:47.375 -> Connecting ...
15:12:47.677 -> Connected
15:12:47.677 -> Discovering service 0xffe0 ...
15:12:48.108 -> Service discovered
15:12:48.108 -> Subscribing to simple key characteristic ...
15:12:48.145 -> Subscribed
15:12:48.145 -> write to characteristic
15:12:48.805 -> update
15:12:48.805 -> 00000000000000000000000000000075DA230000000000000000000000000000000000000000000000000000000000000000000000000000000000CAFF
15:12:49.288 -> update
15:12:49.288 -> 00000000000000000000000000000076DA2300000000000000000000000000000000000000000000000000000000000000000000000000000000005CFF
##################################################
Wireshark Mitschnitt. Frame 370 wird nicht ausgegeben.
353 6.723680 Master_0x506562d6 Slave_0x506562d6 ATT 53 Sent Write Request, Handle: 0x000a (Unknown)
354 6.724126 Slave_0x506562d6 Master_0x506562d6 LE LL 26 Empty PDU
355 6.753682 Master_0x506562d6 Slave_0x506562d6 LE LL 26 Empty PDU
356 6.753913 Slave_0x506562d6 Master_0x506562d6 ATT 31 Rcvd Write Response, Handle: 0x000a (Unknown)
357 6.754183 Master_0x506562d6 Slave_0x506562d6 LE LL 26 Empty PDU
358 6.754414 Slave_0x506562d6 Master_0x506562d6 ATT 133 Rcvd Handle Value Notification, Handle: 0x000a (Unknown)
359 6.783682 Master_0x506562d6 Slave_0x506562d6 LE LL 26 Empty PDU
...
369 6.933685 Master_0x506562d6 Slave_0x506562d6 LE LL 26 Empty PDU
370 6.933916 Slave_0x506562d6 Master_0x506562d6 ATT 274 Rcvd Handle Value Notification, Handle: 0x000a (Unknown)
371 6.936130 Master_0x506562d6 Slave_0x506562d6 LE LL 26 Empty PDU
372 6.936361 Slave_0x506562d6 Master_0x506562d6 ATT 92 Rcvd Handle Value Notification, Handle: 0x000a (Unknown)
373 6.963686 Master_0x506562d6 Slave_0x506562d6 LE LL 26 Empty PDU
...
Frame 353: 53 bytes on wire (424 bits), 53 bytes captured (424 bits) on interface COM14-4.2, id 0
Section number: 1
Interface id: 0 (COM14-4.2)
Interface name: COM14-4.2
Interface description: nRF Sniffer for Bluetooth LE COM14
Encapsulation type: nRF Sniffer for Bluetooth LE (186)
Arrival Time: Feb 10, 2024 16:43:21.871672000 Mitteleuropäische Zeit
UTC Arrival Time: Feb 10, 2024 15:43:21.871672000 UTC
Epoch Arrival Time: 1707579801.871672000
[Time shift for this packet: 0.000000000 seconds]
[Time delta from previous captured frame: 0.029770000 seconds]
[Time delta from previous displayed frame: 0.029770000 seconds]
[Time since reference or first frame: 6.723680000 seconds]
Frame Number: 353
Frame Length: 53 bytes (424 bits)
Capture Length: 53 bytes (424 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: nordic_ble:btle:btl2cap:btatt]
nRF Sniffer for Bluetooth LE
Board: 14
Header Version: 3, Packet counter: 38730
Length of payload: 46
Protocol version: 3
Packet counter: 38730
Packet ID: 6
Length of packet: 10
Flags: 0x03
.... ...1 = CRC: Ok
.... ..1. = Direction: Master -> Slave
.... .0.. = Encrypted: No
.... 0... = MIC (not relevant): 0
.000 .... = PHY: LE 1M (0)
0... .... = Reserved: 0
Channel Index: 6
RSSI: -46 dBm
Event counter: 161
Timestamp: 1720154717µs
[Packet time (start to end): 296µs]
[Delta time (end to start): 29690µs]
[Delta time (start to start): 29770µs]
Bluetooth Low Energy Link Layer
Access Address: 0x506562d6
[Master Address: 4a:f9:bd:7e:d9:50 (4a:f9:bd:7e:d9:50)]
[Slave Address: 00:e4:4c:21:dc:3f (00:e4:4c:21:dc:3f)]
Data Header
.... ..10 = LLID: Start of an L2CAP message or a complete L2CAP message with no fragmentation (0x2)
.... .1.. = Next Expected Sequence Number: 1 [ACK]
.... 1... = Sequence Number: 1 [OK]
...0 .... = More Data: False
..0. .... = CTE Info: Not Present
00.. .... = RFU: 0
Length: 27
[L2CAP Index: 11]
[Connection Parameters in: 39]
CRC: 0xed00f5
Bluetooth L2CAP Protocol
Length: 23
CID: Attribute Protocol (0x0004)
Bluetooth Attribute Protocol
Opcode: Write Request (0x12)
0... .... = Authentication Signature: False
.0.. .... = Command: False
..01 0010 = Method: Write Request (0x12)
Handle: 0x000a (Unknown)
Value: aa551101040014000000000000000000000029ff
Frame 356: 31 bytes on wire (248 bits), 31 bytes captured (248 bits) on interface COM14-4.2, id 0
Section number: 1
Interface id: 0 (COM14-4.2)
Interface name: COM14-4.2
Interface description: nRF Sniffer for Bluetooth LE COM14
Encapsulation type: nRF Sniffer for Bluetooth LE (186)
Arrival Time: Feb 10, 2024 16:43:21.901905000 Mitteleuropäische Zeit
UTC Arrival Time: Feb 10, 2024 15:43:21.901905000 UTC
Epoch Arrival Time: 1707579801.901905000
[Time shift for this packet: 0.000000000 seconds]
[Time delta from previous captured frame: 0.000231000 seconds]
[Time delta from previous displayed frame: 0.000231000 seconds]
[Time since reference or first frame: 6.753913000 seconds]
Frame Number: 356
Frame Length: 31 bytes (248 bits)
Capture Length: 31 bytes (248 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: nordic_ble:btle:btl2cap:btatt]
nRF Sniffer for Bluetooth LE
Board: 14
Header Version: 3, Packet counter: 38733
Length of payload: 24
Protocol version: 3
Packet counter: 38733
Packet ID: 6
Length of packet: 10
Flags: 0x01
.... ...1 = CRC: Ok
.... ..0. = Direction: Slave -> Master
.... .0.. = Encrypted: No
.... 0... = MIC (not relevant): 0
.000 .... = PHY: LE 1M (0)
0... .... = Reserved: 0
Channel Index: 17
RSSI: -46 dBm
Event counter: 162
Timestamp: 1720184950µs
[Packet time (start to end): 120µs]
[Delta time (end to start): 151µs]
[Delta time (start to start): 231µs]
Bluetooth Low Energy Link Layer
Access Address: 0x506562d6
[Master Address: 4a:f9:bd:7e:d9:50 (4a:f9:bd:7e:d9:50)]
[Slave Address: 00:e4:4c:21:dc:3f (00:e4:4c:21:dc:3f)]
Data Header
.... ..10 = LLID: Start of an L2CAP message or a complete L2CAP message with no fragmentation (0x2)
.... .1.. = Next Expected Sequence Number: 1 [ACK]
.... 0... = Sequence Number: 0 [OK]
...1 .... = More Data: True
..0. .... = CTE Info: Not Present
00.. .... = RFU: 0
Length: 5
[L2CAP Index: 12]
[Connection Parameters in: 39]
CRC: 0x6e1ce9
Bluetooth L2CAP Protocol
Length: 1
CID: Attribute Protocol (0x0004)
Bluetooth Attribute Protocol
Opcode: Write Response (0x13)
0... .... = Authentication Signature: False
.0.. .... = Command: False
..01 0011 = Method: Write Response (0x13)
[Handle: 0x000a (Unknown)]
[Request in Frame: 353]
Frame 358: 133 bytes on wire (1064 bits), 133 bytes captured (1064 bits) on interface COM14-4.2, id 0
Section number: 1
Interface id: 0 (COM14-4.2)
Interface name: COM14-4.2
Interface description: nRF Sniffer for Bluetooth LE COM14
Encapsulation type: nRF Sniffer for Bluetooth LE (186)
Arrival Time: Feb 10, 2024 16:43:21.902406000 Mitteleuropäische Zeit
UTC Arrival Time: Feb 10, 2024 15:43:21.902406000 UTC
Epoch Arrival Time: 1707579801.902406000
[Time shift for this packet: 0.000000000 seconds]
[Time delta from previous captured frame: 0.000231000 seconds]
[Time delta from previous displayed frame: 0.000231000 seconds]
[Time since reference or first frame: 6.754414000 seconds]
Frame Number: 358
Frame Length: 133 bytes (1064 bits)
Capture Length: 133 bytes (1064 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: nordic_ble:btle:btl2cap:btatt]
nRF Sniffer for Bluetooth LE
Board: 14
Header Version: 3, Packet counter: 38735
Length of payload: 126
Protocol version: 3
Packet counter: 38735
Packet ID: 6
Length of packet: 10
Flags: 0x01
.... ...1 = CRC: Ok
.... ..0. = Direction: Slave -> Master
.... .0.. = Encrypted: No
.... 0... = MIC (not relevant): 0
.000 .... = PHY: LE 1M (0)
0... .... = Reserved: 0
Channel Index: 17
RSSI: -45 dBm
Event counter: 162
Timestamp: 1720185451µs
[Packet time (start to end): 936µs]
[Delta time (end to start): 151µs]
[Delta time (start to start): 231µs]
Bluetooth Low Energy Link Layer
Access Address: 0x506562d6
[Master Address: 4a:f9:bd:7e:d9:50 (4a:f9:bd:7e:d9:50)]
[Slave Address: 00:e4:4c:21:dc:3f (00:e4:4c:21:dc:3f)]
Data Header
.... ..10 = LLID: Start of an L2CAP message or a complete L2CAP message with no fragmentation (0x2)
.... .0.. = Next Expected Sequence Number: 0 [ACK]
.... 1... = Sequence Number: 1 [OK]
...0 .... = More Data: False
..0. .... = CTE Info: Not Present
00.. .... = RFU: 0
Length: 107
[L2CAP Index: 13]
[Connection Parameters in: 39]
CRC: 0x9bcf5f
Bluetooth L2CAP Protocol
Length: 103
CID: Attribute Protocol (0x0004)
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
0... .... = Authentication Signature: False
.0.. .... = Command: False
..01 1011 = Method: Handle Value Notification (0x1b)
Handle: 0x000a (Unknown)
Value: 55aa110104006400100ad7233c0000804014ae57400101021801000099995940000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000caff
Frame 370: 274 bytes on wire (2192 bits), 274 bytes captured (2192 bits) on interface COM14-4.2, id 0
Section number: 1
Interface id: 0 (COM14-4.2)
Interface name: COM14-4.2
Interface description: nRF Sniffer for Bluetooth LE COM14
Encapsulation type: nRF Sniffer for Bluetooth LE (186)
Arrival Time: Feb 10, 2024 16:43:22.081908000 Mitteleuropäische Zeit
UTC Arrival Time: Feb 10, 2024 15:43:22.081908000 UTC
Epoch Arrival Time: 1707579802.081908000
[Time shift for this packet: 0.000000000 seconds]
[Time delta from previous captured frame: 0.000231000 seconds]
[Time delta from previous displayed frame: 0.000231000 seconds]
[Time since reference or first frame: 6.933916000 seconds]
Frame Number: 370
Frame Length: 274 bytes (2192 bits)
Capture Length: 274 bytes (2192 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: nordic_ble:btle:btl2cap:btatt]
nRF Sniffer for Bluetooth LE
Board: 14
Header Version: 3, Packet counter: 38747
Length of payload: 267
Protocol version: 3
Packet counter: 38747
Packet ID: 6
Length of packet: 10
Flags: 0x01
.... ...1 = CRC: Ok
.... ..0. = Direction: Slave -> Master
.... .0.. = Encrypted: No
.... 0... = MIC (not relevant): 0
.000 .... = PHY: LE 1M (0)
0... .... = Reserved: 0
Channel Index: 9
RSSI: -46 dBm
Event counter: 168
Timestamp: 1720364953µs
[Packet time (start to end): 2064µs]
[Delta time (end to start): 151µs]
[Delta time (start to start): 231µs]
Bluetooth Low Energy Link Layer
Access Address: 0x506562d6
[Master Address: 4a:f9:bd:7e:d9:50 (4a:f9:bd:7e:d9:50)]
[Slave Address: 00:e4:4c:21:dc:3f (00:e4:4c:21:dc:3f)]
Data Header
.... ..10 = LLID: Start of an L2CAP message or a complete L2CAP message with no fragmentation (0x2)
.... .0.. = Next Expected Sequence Number: 0 [ACK]
.... 1... = Sequence Number: 1 [OK]
...1 .... = More Data: True
..0. .... = CTE Info: Not Present
00.. .... = RFU: 0
Length: 248
[L2CAP Index: 14]
[Connection Parameters in: 39]
CRC: 0x0f6efa
Bluetooth L2CAP Protocol
Length: 244
CID: Attribute Protocol (0x0004)
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
0... .... = Authentication Signature: False
.0.. .... = Command: False
..01 1011 = Method: Handle Value Notification (0x1b)
Handle: 0x000a (Unknown)
Value [truncated]: 55aa110102002c0110d1674e405d0f4e408a054e40e90c4e40a61b4e40b3a74e401a744e404b5c4f40230e4e40f5984e407a7b4e40c3314e40c4db4d40a0d54d409e814e4081964e400000000000000000000000000000000000000000000000000000000000000000a2470b3ee8
Frame 372: 92 bytes on wire (736 bits), 92 bytes captured (736 bits) on interface COM14-4.2, id 0
Section number: 1
Interface id: 0 (COM14-4.2)
Interface name: COM14-4.2
Interface description: nRF Sniffer for Bluetooth LE COM14
Encapsulation type: nRF Sniffer for Bluetooth LE (186)
Arrival Time: Feb 10, 2024 16:43:22.084353000 Mitteleuropäische Zeit
UTC Arrival Time: Feb 10, 2024 15:43:22.084353000 UTC
Epoch Arrival Time: 1707579802.084353000
[Time shift for this packet: 0.000000000 seconds]
[Time delta from previous captured frame: 0.000231000 seconds]
[Time delta from previous displayed frame: 0.000231000 seconds]
[Time since reference or first frame: 6.936361000 seconds]
Frame Number: 372
Frame Length: 92 bytes (736 bits)
Capture Length: 92 bytes (736 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: nordic_ble:btle:btl2cap:btatt]
nRF Sniffer for Bluetooth LE
Board: 14
Header Version: 3, Packet counter: 38749
Length of payload: 85
Protocol version: 3
Packet counter: 38749
Packet ID: 6
Length of packet: 10
Flags: 0x01
.... ...1 = CRC: Ok
.... ..0. = Direction: Slave -> Master
.... .0.. = Encrypted: No
.... 0... = MIC (not relevant): 0
.000 .... = PHY: LE 1M (0)
0... .... = Reserved: 0
Channel Index: 9
RSSI: -46 dBm
Event counter: 168
Timestamp: 1720367398µs
[Packet time (start to end): 608µs]
[Delta time (end to start): 151µs]
[Delta time (start to start): 231µs]
Bluetooth Low Energy Link Layer
Access Address: 0x506562d6
[Master Address: 4a:f9:bd:7e:d9:50 (4a:f9:bd:7e:d9:50)]
[Slave Address: 00:e4:4c:21:dc:3f (00:e4:4c:21:dc:3f)]
Data Header
.... ..10 = LLID: Start of an L2CAP message or a complete L2CAP message with no fragmentation (0x2)
.... .1.. = Next Expected Sequence Number: 1 [ACK]
.... 0... = Sequence Number: 0 [OK]
...0 .... = More Data: False
..0. .... = CTE Info: Not Present
00.. .... = RFU: 0
Length: 66
[L2CAP Index: 15]
[Connection Parameters in: 39]
CRC: 0x775ca9
Bluetooth L2CAP Protocol
Length: 62
CID: Attribute Protocol (0x0004)
Bluetooth Attribute Protocol
Opcode: Handle Value Notification (0x1b)
0... .... = Authentication Signature: False
.0.. .... = Command: False
..01 1011 = Method: Handle Value Notification (0x1b)
Handle: 0x000a (Unknown)
Value: 00000000000000000000000000fa061c00000000000000000000000000000000000000000000000000000000000000000000000000000000006aff