IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Android Discussion :

Bluetooth Low Energy Characteristics notification issue


Sujet :

API standards et tierces Android

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    33
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 33
    Points : 20
    Points
    20
    Par défaut Bluetooth Low Energy Characteristics notification issue
    Bonjour à tous,

    je démarre avec BLE sous Android et je rencontre quelques problèmes.
    J'ai 2 services différents avec chacun leur propre caractéristique. (Un GPS et un Accéléromètre)

    lorsque je me connecte a mon périphérique bluetooth et que j'active les notifications pour chacune de ces caractéristiques (voir code enableTXNotification), j'ai régulièrement une des 2 caractéristique pour laquelle je ne reçois pas la notification (voir broadcastUpdate).
    J'admet ne pas en comprendre la raison et je vois pas l'erreur qui m'y conduit.
    Du coup, je m'interroge sur le CCCD, et ne suis pas certain d'avoir compris clairement comment cela fonctionne ... Peut être que la raison est autre ! Je compte sur un œil expert.

    Merci pour vos conseils.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
     
    public void enableTXNotification()
        {
        	BluetoothGattService accService = mBluetoothGatt.getService(ACC_SERVICE_UUID);
            if (accService == null) {
                showMessage("Accelerometer service not found!");
                return;
            }
     
            BluetoothGattCharacteristic TxChar = accService.getCharacteristic(ACC_TX_VALUE_CHAR_UUID);
            if (TxChar == null) {
                showMessage("Accelerometer value characteristic not found!");
                return;
            }
     
            mBluetoothGatt.setCharacteristicNotification(TxChar, true);
     
            BluetoothGattDescriptor descriptor2 = TxChar.getDescriptor(CCCD);
            descriptor2.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mBluetoothGatt.writeDescriptor(descriptor2);
     
        	BluetoothGattService gpsService = mBluetoothGatt.getService(GPS_SERVICE_UUID);
        	if (gpsService == null) {
                showMessage("GPS service not found!");
                return;
            }
        	BluetoothGattCharacteristic gpsTxChar = gpsService.getCharacteristic(GPS_TX_VALUE_CHAR_UUID);
            if (gpsTxChar == null) {
                showMessage("GPS value charateristic not found!");
                return;
            }
     
            mBluetoothGatt.setCharacteristicNotification(gpsTxChar,true);
     
            BluetoothGattDescriptor descriptor = gpsTxChar.getDescriptor(CCCD);
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mBluetoothGatt.writeDescriptor(descriptor);
        }
     
     private void broadcastUpdate(final String action,
                                     final BluetoothGattCharacteristic characteristic) {
            final Intent intent = new Intent(action);
     
            if (GPS_TX_VALUE_CHAR_UUID.equals(characteristic.getUuid())) {
     
                Log.d(TAG, "Received GPS TX");
     
                byte[] data = characteristic.getValue();
                byte[] lat = Arrays.copyOfRange(data, 0, 4);
                byte[] lng = Arrays.copyOfRange(data, 4, 8);
     
                // la flemme de swapper par lot de 4 octet pour gerer tous les float en 1 fois ... !!!!
     
                final FloatBuffer fb = ByteBuffer.wrap(SwapFloatEndian(lat)).asFloatBuffer();
                final float[] dst = new float[fb.capacity()];
                fb.get(dst); // Copy the contents of the FloatBuffer into dst
     
                final FloatBuffer fb1 = ByteBuffer.wrap(SwapFloatEndian(lng) ).asFloatBuffer();
                final float[] dst1 = new float[fb.capacity()];
                fb1.get(dst1); // Copy the contents of the FloatBuffer into dst
     
                intent.putExtra(EXTRA_DATA, String.format("Receipt GPS coordinates " + dst[0] + " - " + dst1[0] ).getBytes()    );
            }
            else if (ACC_TX_VALUE_CHAR_UUID.equals( characteristic.getUuid()) )
            {
                Log.d(TAG, "Received Accelerometer TX");
     
                intent.putExtra( EXTRA_DATA, String.format( "Receipt Giroscopic data " + byteArrayToByteString(characteristic.getValue() ) ).getBytes() );
            }
            else {
                Log.d(TAG, "Unknow receipt");
            }
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        }

  2. #2
    Membre éprouvé Avatar de Drowan
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2014
    Messages
    460
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juin 2014
    Messages : 460
    Points : 1 014
    Points
    1 014
    Par défaut
    Vu ton code, tu semble avoir compris. Le CCCD est l'identifiant du descripteur qui décrit les notifications. S'il vaut 00002902-0000-1000-8000-00805F9B34FB, alors c'est bon de ce coté là.

    Tu réalise deux actions d’écriture consécutivement, le descriptor pour l'accelerometre puis le descriptor pour le GPS. Il est possible que ces deux instructions s’exécute trop rapidement. Le BLE étant incapable de réaliser plusieurs écritures en parallèles, n'en fait qu'une. Donc active les notifications que pour un des deux.
    As-tu un BluetoothGattCallback pour capturer le onDescriptorWrite() de la première écriture avant de réaliser la deuxième ?
    "On sera toujours mieux installé assis en 1ère que debout en 2nde", un illustre inconnu


    Avant de poser une question vérifiez si elle n'a pas déjà une réponse dans les cours et tutoriels
    Si votre problème est pensez à marquer la conversation comme telle
    Si un message est utile, pertinent, et/ou vous êtes d'accord avec, pensez à à l'inverse s'il est inutile, faux ou que vous n'êtes pas d'accord, pensez à

Discussions similaires

  1. Bluetooth Low Energy - lire correctement une caractéristique
    Par oieretxe dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 03/11/2015, 12h12
  2. Bluetooth low energy UUID
    Par cedd70 dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 17/07/2015, 15h19
  3. Bluetooth low energy
    Par cedd70 dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 12/06/2015, 09h10
  4. Communication Bluetooth Low Energy entre Android et iOS
    Par oieretxe dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 10/05/2015, 14h30
  5. Emuler Bluetooth Low Energy depuis Windows : Genymoition, AndyOS?
    Par arbtec dans le forum API standards et tierces
    Réponses: 0
    Dernier message: 23/10/2014, 10h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo