Je suis en de train de developper une application iOS (sous Swift) qui doit se connecter a des appareils via BLE (une forme de Bluethooth si j'ai bien compris).
Apres pas mal de recherche, j'ai reussi a me connecter au differentes devises.
J'arrive a recuperer le uuid comme ceci : device.peripheral.identifier
Malheureusement, je n'ai aucune idees de comment recuperer les donnees en tant reel.
Lorsque je fais:
let data = withUnsafePointer(to: device.peripheral.identifier) {
Data(bytes: $0, count: MemoryLayout.size(ofValue: device.peripheral.identifier))
}
Je me demande s'il faut que je renseigne la valeur withServices (qui est un array), le hic c'est que je n'ai aucune idee de ce que je dois mettre (et j'espere que la valeur nil convient).
Pouvez vous me donner des pistes me permettant de recuperer les donnees (meme si elle ne sont pas formates ca me va).
Ce que je cherche a recuperer ce sont ces bytes afin de pouvoir les analyser
En fouillant sur internet et en faisant des test (vraiment au piff en fait), j'ai reussi a acceder aux characteristiques. Voici le code que j'ai cree:
let services = device.peripheral.services
print("====SERVICES====")
for service: CBService in services! {
print("\n=== SERVICE: ")
dump(service)
device.peripheral.discoverCharacteristics(nil, for: service)
let characteristics = service.characteristics
print("\n\n==CHARACTERISTICS:")
dump(characteristics)
for charateristic: CBCharacteristic in characteristics! {
// Une fois ici, je ne sais pas quoi faire
}
}
Voici ce que j'obtiens dans la console de debug:
====SERVICES====
=== SERVICE 1:
- <CBService: 0x1c08764c0, isPrimary = YES, UUID = Device Information> #0
- super: CBAttribute
- super: NSObject
2019-02-15 17:42:03.809860+0900 BLEMultiConnectSample[28298:6951868] [CoreBluetooth] API MISUSE: Discovering characteristics on peripheral <CBPeripheral: 0x1c0108430, identifier = 8B3F06B8-0F71-E202-11FF-CEFD1705521B, name = SensorTag 2.0, state = connected> while delegate is either nil or does not implement peripheral:didDiscoverCharacteristicsForService:error:
==CHARACTERISTICS:
▿ Optional([<CBCharacteristic: 0x1c04a8e80, UUID = System ID, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9960, UUID = Model Number String, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a99c0, UUID = Serial Number String, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9a20, UUID = Firmware Revision String, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9a80, UUID = Hardware Revision String, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9ae0, UUID = Software Revision String, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9b40, UUID = Manufacturer Name String, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9ba0, UUID = IEEE Regulatory Certification, properties = 0x2, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9c00, UUID = PnP ID, properties = 0x2, value = (null), notifying = NO>])
▿ some: 9 elements
- <CBCharacteristic: 0x1c04a8e80, UUID = System ID, properties = 0x2, value = (null), notifying = NO> #0
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9960, UUID = Model Number String, properties = 0x2, value = (null), notifying = NO> #1
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a99c0, UUID = Serial Number String, properties = 0x2, value = (null), notifying = NO> #2
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9a20, UUID = Firmware Revision String, properties = 0x2, value = (null), notifying = NO> #3
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9a80, UUID = Hardware Revision String, properties = 0x2, value = (null), notifying = NO> #4
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9ae0, UUID = Software Revision String, properties = 0x2, value = (null), notifying = NO> #5
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9b40, UUID = Manufacturer Name String, properties = 0x2, value = (null), notifying = NO> #6
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9ba0, UUID = IEEE Regulatory Certification, properties = 0x2, value = (null), notifying = NO> #7
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9c00, UUID = PnP ID, properties = 0x2, value = (null), notifying = NO> #8
- super: CBAttribute
- super: NSObject
=== SERVICE 2:
- <CBService: 0x1c0875880, isPrimary = YES, UUID = F000FFF0-0451-4000-B000-000000000000> #0
- super: CBAttribute
- super: NSObject
2019-02-15 17:42:03.814062+0900 BLEMultiConnectSample[28298:6951868] [CoreBluetooth] API MISUSE: Discovering characteristics on peripheral <CBPeripheral: 0x1c0108430, identifier = 8B3F06B8-0F71-E202-11FF-CEFD1705521B, name = SensorTag 2.0, state = connected> while delegate is either nil or does not implement peripheral:didDiscoverCharacteristicsForService:error:
==CHARACTERISTICS:
▿ Optional([<CBCharacteristic: 0x1c04a8f40, UUID = F000FFF1-0451-4000-B000-000000000000, properties = 0xA, value = (null), notifying = NO>, <CBCharacteristic: 0x1c04a9c60, UUID = F000FFF2-0451-4000-B000-000000000000, properties = 0x12, value = (null), notifying = NO>])
▿ some: 2 elements
- <CBCharacteristic: 0x1c04a8f40, UUID = F000FFF1-0451-4000-B000-000000000000, properties = 0xA, value = (null), notifying = NO> #0
- super: CBAttribute
- super: NSObject
- <CBCharacteristic: 0x1c04a9c60, UUID = F000FFF2-0451-4000-B000-000000000000, properties = 0x12, value = (null), notifying = NO> #1
- super: CBAttribute
- super: NSObject
======
J'ai toujours 2 services qui contiennent leur propre characteristics. J'arrive a faire une boucle sur ces characteristics mais ensuite je ne vois pas quoi faire. En effet, je n'arrive pas a voir ce que je cherche (visuellement parlant).
Je sais que je dois recuperer des paquets. Que 1 paquet contient 20Byte
Il me faudra ensuite analyser les 20 Byte un par un.
Merci pour ton aide. Desole pour le temps de reponse, j'etais vraiment tres tres occupe a cause du boulot.
Pour info, je pense avoir reussi. Je recupere des donnees que les devise m'envoi.
Maintenant je ne sais pas du tout si ce que je recois est correct, donc je vais envoyer un message au client client pour qu'il check si les Bytes que je recois sont corecte ou pas.
J'ai un autre soucis (sur le projet precedent, celui que l'on m'a refile) donc je vais ecrire un autre sujet.
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.