@@ -127,34 +127,27 @@ class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDe
127
127
return
128
128
}
129
129
130
+
130
131
if let characteristics = service. characteristics {
131
- for characteristic in characteristics {
132
- //print("Discovered characteristic: \(characteristic.uuid)")
133
- if let characteristics = service. characteristics {
134
- for c in characteristics {
135
- if c. uuid == CBUUID ( string: " 0001 " ) {
136
- pWriter = c
137
- let max_len = peripheral. maximumWriteValueLength ( for: CBCharacteristicWriteType . withoutResponse)
138
- print ( " Found writer service with max length \( max_len) " )
139
-
140
- }
141
- if c. uuid == CBUUID ( string: " 0002 " ) {
142
- pReader = c
143
- }
144
- }
132
+ for c in characteristics {
133
+ if c. uuid == CBUUID ( string: " 799d485c-d354-4ed0-b577-f8ee79ec275a " ) {
134
+ pWriter = c
135
+ let max_len = peripheral. maximumWriteValueLength ( for: CBCharacteristicWriteType . withoutResponse)
136
+ print ( " Found writer service with max length \( max_len) " )
137
+
138
+ }
139
+ if c. uuid == CBUUID ( string: " 419572a5-9f53-4eb1-8db7-61bcab928867 " ) {
140
+ peripheral. setNotifyValue ( true , for: c) ;
141
+ pReader = c
145
142
}
146
143
}
144
+
147
145
}
148
146
}
149
147
150
148
func peripheral( _ peripheral: CBPeripheral , didWriteValueFor characteristic: CBCharacteristic , error: Error ? ) {
151
- if waitingForInfo {
152
- // Issue read
153
- peripheral. readValue ( for: pReader!)
154
- waitingForInfo = false
155
- }
156
- if let _ = error {
157
- log ( " Failed to write " )
149
+ if let e = error {
150
+ log ( " Failed to write \( e) " )
158
151
return
159
152
}
160
153
acks += 1 ;
@@ -257,7 +250,7 @@ class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDe
257
250
let sz = [ UInt8] ( _: [ 0 , 1 ] ) ;
258
251
let header = cid + cmd + sz;
259
252
let packet = header + [ Character ( " i " ) . asciiValue!] ;
260
- var report = Data ( count: 64 ) ;
253
+ var report = Data ( count: 10 ) ;
261
254
for (i, c) in packet. enumerated ( ) {
262
255
report [ i] = c;
263
256
}
0 commit comments