MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Bluetooth connectivity using Raspberry pi3

    Scheduled Pinned Locked Moved Troubleshooting
    1 Posts 1 Posters 1.0k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N Offline
      nitz.j2412
      last edited by yawns

      Hello Everyone,
      Great to be a part of this community. A big thanks to all the contributors and developers.
      I built a custom module to connect Adafruit Bluetooth module nrf8001 with the MM2. I am not seeing anything on the mirror and can’t figure out the issue. Please find attached the module files:

      node_helper.js

      var nrfuart = require('./index.js');	
      module.exports = NodeHelper.create({
        start: function () {
          console.log('BLE helper started ...');
      },
      
      socketNotificationReceived: function(notification, payload) {
              if (notification === 'TEMP') {
                  console.log('Notification TEMP in ' + this.name + ' received');
                this.sendNotificationTest(this.anotherFunction());	
              }
      	else
      	{
      	console.log('ERRRRROR');
      	}
      },
      
      sendNotificationTest:function(payload){
      this.sendSocketNotification('TEMPER',payload);
      },
      
      anotherFunction: function(){
      	nrfuart.discoverAll(function(ble_uart) {
          	'use strict';
          	ble_uart.on('disconnect', function() {});
          	ble_uart.connectAndSetup(function() {
              	var writeCount = 0;
              	ble_uart.readDeviceName(function(devName) {});
              	ble_uart.on('data', function(data) {
      		var x = data.toString();
      		var con = x.substring(0,2);
      		var dec = x.substring(2,4);
      		con = con.concat('.');
      		con = con.concat(dec);
      		console.log(con);
      		return con;		 		
      });
              setInterval(function() {}, 3000);
          });
      });
      }	
      
      });
      

      index.js

      /*
       * Adafruit nRF8001 breakout in UART mode. This might also work for other
       * nRF8001 boards but has only been tested with the Adafruit board.
       */
      
      var NobleDevice = require('noble-device');
      var events = require('events');
      var util = require('util');
      
      var NRFUART_SERVICE_UUID = '6e400001b5a3f393e0a9e50e24dcca9e';
      var NRFUART_NOTIFY_CHAR  = '6e400003b5a3f393e0a9e50e24dcca9e';
      var NRFUART_WRITE_CHAR   = '6e400002b5a3f393e0a9e50e24dcca9e';
      
      var nrfuart = function(peripheral) {
          // call nobles super constructor
          NobleDevice.call(this, peripheral);
      
          // setup or do anything else your module needs here
      };
      
      // tell Noble about the service uuid(s) your peripheral advertises (optional)
      nrfuart.SCAN_UUIDS = [NRFUART_SERVICE_UUID];
      
      util.inherits(nrfuart, events.EventEmitter);
      
      // and/or specify method to check peripheral (optional)
      nrfuart.is = function(peripheral) {
          'use strict';
          //return (peripheral.advertisement.localName === 'UART');
          return true;
      };
      
      // inherit noble device
      NobleDevice.Util.inherits(nrfuart, NobleDevice);
      
      // Receive data using the 'data' event.
      nrfuart.prototype.onData = function(data) {
          'use strict';
          this.emit("data", data);
      };
      
      // Send data like this
      // nrfuart.write('Hello world!\r\n', function(){...});
      // or this
      // nrfuart.write([0x02, 0x12, 0x34, 0x03], function(){...});
      nrfuart.prototype.write = function(data, done) {
          'use strict';
          if (typeof data === 'string') {
              this.writeDataCharacteristic(NRFUART_SERVICE_UUID, NRFUART_WRITE_CHAR, new Buffer(data), done);
          }
          else {
              this.writeDataCharacteristic(NRFUART_SERVICE_UUID, NRFUART_WRITE_CHAR, data, done);
          }
      };
      
      nrfuart.prototype.connectAndSetup = function(callback) {
          'use strict';
          var self = this;
      
          NobleDevice.prototype.connectAndSetup.call(self, function() {
              self.notifyCharacteristic(NRFUART_SERVICE_UUID,
                  NRFUART_NOTIFY_CHAR, true, self.onData.bind(self), callback);
          });
      };
      
      // export device
      module.exports = nrfuart;
      

      bleEchoTst.js

      Module.register("bleEchoTst",{
      	temper: '999',
      	defaults: {
      	text: '100'
      	},
      
      	start: function() {
      	this.temper = this.config.text;
      	this.sendSocketNotification('TEMP',this.config);
      	},
      
      	socketNotificationReceived: function(notification,payload)
      	{
      	if(notification === 'TEMPER')
      	{
      	this.temper = payload;
      	//this.temper = '999';
      	this.updateDom();
      	}
      	},
      
              // Override dom generator.
      	getDom: function() {
      		var wrapper = document.createElement("div");
      		wrapper.innerHTML = this.temper;
      		return wrapper;
      	}
      
      });
      

      Any help is appreciated.
      Thanks

      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post
      Enjoying MagicMirror? Please consider a donation!
      MagicMirror created by Michael Teeuw.
      Forum managed by Sam, technical setup by Karsten.
      This forum is using NodeBB as its core | Contributors
      Contact | Privacy Policy