bluethoot low energy and bangle js2

Posted on
  • I try to ram my code in my watch with espruino ide but when i connected to nrfconnect to see the service i try to install nothing appear.

    // Fonction pour initialiser les services BLE
    function initBLE() {
      NRF.setServices({
        0x180A: { // UUID du service Device Information
          0x2A56: { // UUID de la caractéristique pour écrire
            value: [0x00], // Valeur initiale
            maxLen: 20,    // Taille maximale des données
            writable: true, // Autoriser l'écriture
            onWrite: function(evt) {
              let data = evt.data;
              console.log("Données reçues : ", data);
              require("Storage").write("config", data);
            }
          },
          0x2A57: { // UUID de la caractéristique pour lire
            value: [0x00], // Valeur initiale
            maxLen: 20,    // Taille maximale des données
            readable: true, // Autoriser la lecture
            onRead: function() {
              let data = require("Storage").read("config") || [0x00];
              console.log("Données lues : ", data);
              return data;
            }
          }
        }
      }, { advertise: ['0x180A'] });
    
      console.log("Bluetooth prêt et services configurés");
    }
    
    // Redémarrer le Bluetooth pour s'assurer qu'il est correctement initialisé
    NRF.restart(function() {
      console.log("Bluetooth redémarré");
      initBLE();
    });
    
  • you should not do the initialization of services inside NRF.restart(), that's meant for code that runs while bluetooth stack is completely disabled

    https://www.espruino.com/Reference#l_NRF_restart

    callback - [optional] A function to be called while the softdevice is uninitialised. Use with caution - accessing console/bluetooth will almost certainly result in a crash.

    you managed to actually do both things advised not to do :-)

  • As @fanoush says - don't use NRF.restart. Just call initBLE directly.

    NRF.restart is really a very low level function, pretty much nobody should ever need to call in normal use.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

bluethoot low energy and bangle js2

Posted by Avatar for user158305 @user158305

Actions