• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
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.

Device detection - personalised message

Scheduled Pinned Locked Moved Development
5 Posts 3 Posters 3.0k Views 3 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.
  • M Offline
    mdnz
    last edited by Jul 31, 2016, 4:11 AM

    Hi. I’ve been hacking around with some python code to create a module that can pick up a known device (via MAC address) and if detected push up a message. Having no Python experience it’s been trial and error. It’s working but only just! Two problems are that when it’s publishing the result it appears to be flicking between the MAC detected message and MAC not detected message. Also when Python is calling the ‘import bluetooth’ line it appears to be conflicting with the Pi’s WIFI (as speeds drop to next to nothing). I’m running a Pi3. Appreciate both of these are not core MagicMirror issues - but just throwing them here if of interest to anyone, or someone can help.

    Here’s the module js (athomecheck.js)

    Module.register("athomecheck",{
    
            defaults: {
                    prependString: 'HOME: '
            },
    
            start: function() {
                    this.athome = 'fetching ...';
                    this.sendSocketNotification('CONNECT');
            },
    
            socketNotificationReceived: function(notification, payload) {
                if (notification === 'ATHOMECHECK') {
                    this.athome = payload;
                    this.updateDom();
                }
            },
    
            // Override dom generator.
            getDom: function() {
                    var wrapper = document.createElement("div");
                    wrapper.innerHTML = this.config.prependString + this.athome;
                    return wrapper;
            }
    });
    

    Here’s the node_helper.js

    var NodeHelper = require("node_helper");
    var PythonShell = require('python-shell');
    
    module.exports = NodeHelper.create({
                    start: function function_name () {
                    var self = this;
                    setInterval(function() {
                            self.sendUpdate();
                    }, 1000);
            },
    
            sendUpdate: function() {
                    const self = this;
                    const pyshell = new PythonShell('detect.py', { mode: 'text', scriptPath: 'modules/athomecheck'});
    
                    pyshell.on('message', function(message){
                            console.log(message);
                            self.sendSocketNotification('ATHOMECHECK', message);
    
                    });
            }
    });
    

    and the python script detect.py

    #!/usr/bin/python
    
    import bluetooth
    import time
    import sys
    
    outputa = "x"
    outputb = "y"
    binder = ""
    
    while True:
            result = bluetooth.lookup_name('EX:AM:PL:E1:MA:C2', timeout=5)
            if (result != None):
                    outputa = "Hello Mr SMITH"
            else:
                    outputa = ""
    
            result2 = bluetooth.lookup_name('EX:AM:PL:E1:MA:C3', timeout=5)
            if(result2 != None):
                    outputb = "Hello Mrs SMITH"
            else:
                    outputb = ""
    
            if(result != None and result2 != None):
                    binder = ", "
    
            print outputa + binder + outputb
            break
    
    

    Thanks

    1 Reply Last reply Reply Quote 0
    • M Offline
      mdnz
      last edited by Aug 6, 2016, 6:10 AM

      Hi. FYI I’ve changed the module refresh rate to 30 secs, and also refined the python script:

      #!/usr/bin/python
      import bluetooth
      macs = { "Mr Smith":"EX:AM:PL:E1:MA:C1", "Mrs Smith":"EX:AM:PL:E2:MA:C2" }
      for macname, macnumber in macs.iteritems():
              result = bluetooth.lookup_name(macnumber, timeout=5)
              if (result != None):
                      print macname, "IN",
      

      Still experiencing the Bluetooth / Wifi conflict, but doesn’t seem to be compromising the MagicMirror output too much.

      1 Reply Last reply Reply Quote 0
      • T Offline
        tidus5
        last edited by Nov 17, 2016, 2:32 PM

        Hey guy, are you still on it ?

        S 1 Reply Last reply Nov 17, 2016, 3:40 PM Reply Quote 0
        • S Offline
          strawberry 3.141 Project Sponsor Module Developer @tidus5
          last edited by Nov 17, 2016, 3:40 PM

          @tidus5 https://forum.magicmirror.builders/topic/690/mmm-networkscanner

          Please create a github issue if you need help, so I can keep track

          1 Reply Last reply Reply Quote 0
          • T Offline
            tidus5
            last edited by Nov 17, 2016, 3:50 PM

            :-p thanks :-)

            1 Reply Last reply Reply Quote 0
            • 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