Read the statement by Michael Teeuw here.
MMM-PIR-Sensor Guide with Edits and Updates
-
I recently got the MMM-PIR-Sensor up and going and it’s working flawlessly. I wanted to give a little information as I had to parse this from different sources and some of the info is a bit dated.
I am relatively new to pi in general so definitely point it out if something isn’t right.
Below is a step by step for MMM-PIR-Sensor by paviro.
Navigate to your modules folder at
cd ~/MagicMirror/modules
Executegit clone https://github.com/paviro/MMM-PIR-Sensor.git
Navigate tocd ~/MagicMirror/modules/MMM-PIR-SensorThis is one area I got held up
The guide states to perform annpm installwhere a dated version(2.25) of wiring-pi would be installed.
When issuing the commandgpio -v, I would get an error message “Unable to determine hardware version. I see: Hardware : BCM2835 - expecting BCM2708 or BCM2709. Please report this to project@drogon.net”.Instead use
npm install wiring-piinside your MMM-PIR-Sensor folder. This will install the updated version(2.44) which you can verify withgpio -v.Then issue command
sudo usermod -a -G gpio pi
Thensudo chmod u+s /opt/vc/bin/tvservice && sudo chmod u+s /bin/chvtThe guide says to reboot here but after that, it still wasn’t working for me. Then I stumbled on some excellent advice from the forums here from @JamesMM with @strawberry 3.141 contributing.
Their focus was on the node_helper.js within the module. These are their edits.
First, rename the current file.
mv node_helper.js node_helper_backup.jsNow, create a new file called node_helper.js using
sudo nano node_helper.jsCopy and paste this code
'use strict'; /* Magic Mirror * Module: MMM-PIR-Sensor * * By Paul-Vincent Roll http://paulvincentroll.com * MIT Licensed. */ const NodeHelper = require('node_helper'); const Gpio = require('onoff').Gpio; const exec = require('child_process').exec; module.exports = NodeHelper.create({ start: function() { this.started = false; }, activateMonitor: function() { if (this.config.relayPIN != false) { this.relay.writeSync(this.config.relayOnState); } else if (this.config.relayPIN == false) { // Check if hdmi output is already on exec("/opt/vc/bin/tvservice -s").stdout.on('data', function(data) { if (data.indexOf("0x120002") !== -1) exec("/opt/vc/bin/tvservice --preferred && chvt 6 && chvt 7", null); }); } }, deactivateMonitor: function() { if (this.config.relayPIN != false) { this.relay.writeSync(this.config.relayOffState); } else if (this.config.relayPIN == false) { exec("/opt/vc/bin/tvservice -o", null); } }, // Subclass socketNotificationReceived received. socketNotificationReceived: function(notification, payload) { if (notification === 'CONFIG' && this.started == false) { const self = this; this.config = payload; self.timer = null; self.onState = 0; // Setup value which represent on and off const valueOn = this.config.invertSensorValue ? 0 : 1; const valueOff = this.config.invertSensorValue ? 1 : 0; //Log.info('PIR: ' + this.name); //Setup pins this.pir = new Gpio(this.config.sensorPIN, 'in', 'both'); if (this.config.relayPIN) { this.relay = new Gpio(this.config.relayPIN, 'out'); this.relay.writeSync(this.config.relayOnState); exec("/opt/vc/bin/tvservice --preferred && sudo chvt 6 && sudo chvt 7", null); } //Detected movement this.pir.watch(function(err, value) { if (value == 1) { clearTimeout(self.timer); if (self.onState != 1) { self.sendSocketNotification("USER_PRESENCE", true); if (self.config.powerSaving) { self.activateMonitor(); self.onState = 1; } } } else if (value == 0) { if (self.onState != 0) { self.timer = setTimeout(function(){ self.sendSocketNotification("USER_PRESENCE", false); if (self.config.powerSaving) { self.deactivateMonitor(); self.onState = 0; } }, self.config.offDelay); } } }); this.started = true; } else if (notification === 'SCREEN_WAKEUP') { this.activateMonitor(); } } });This creates a new config called offDelay and it is in configurable in milliseconds.
Reboot your pi.Then add the modules configuration to MM’s config.js. I used this but obviously adjust it to your own needs.
{ module: 'MMM-PIR-Sensor', config: { sensorPIN: 22, powerSaving: true, offDelay: 30000, } }The offDelay of 30000 is 30 seconds.
-
I like people who write guides! I don’t use a PIR sensor but I do appreciate the time and effort you put in on everyone’s behalf.
-
Thanks!
-
I followed your guide but i still get version 2.25 when i use npm install wiring-pi.
Any ideas why? -
This post is deleted! -
This post is deleted! -
@StacheEnthusiast @DavA Hey, I just decided to try and install MMM-PIR-Sensor but am running into the same issue.
I was wondering if you ever did get this working as the directions have stated… -
shit, this killed my MM build…it’s all blank…crap
-
@msherwood Hey FYI I just got my lastest build (from scratch yesterday) working with MMM-PIR-Sensor:
I also found that
npm install wiring-piinstalled the old (2.25) version for me. I found a newer library:npm install wiring-pi-2019which installs version 2.5 (this one works on my pi4!).
I also found that the location of the
tvservicebinary has changed, so I just used the following bash commands:sudo chmod u+s `which tvservice` sudo chmod u+s `which chvt`It then worked for me (Note, I did not modify the
node_helper.jsscript at all.) -
Hi all, unfortunately I’m not too familiar with coding but had this module failed to update today having followed the steps above which worked fine with the previous version.
Has anyone else experienced this?
Thanks
-
@dubalda can you elaborate more detailed the failure, e.g, error message or similar?
-
I am curious to know if there is a benefit by using the MM-Module for the PIR vs. the executable script which can be autostarted with pm2 (as per this tutorial). Can anyone help?
-
@Fozi thank you for coming back to me. Here are the error messages I’m getting…apologies if it’s quite long! I unfortunately wasn’t able to upload the log file.
pi@pi:~/MagicMirror/modules/MMM-PIR-Sensor $ git pull
Updating be81cf0…d4831f2
Fast-forward
README.md | 14 ++++++++++++++
node_helper.js | 46 ++++++++++++++++++++++++++++++++++++++++++++±
2 files changed, 59 insertions(+), 1 deletion(-)
pi@pi:~/MagicMirror/modules/MMM-PIR-Sensor $ npm installMagic-Mirror-Module-PIR-Sensor@1.1.0 postinstall /home/pi/MagicMirror/modules/MMM-PIR-Sensor
electron-rebuild -e …/…/node_modules/electronâ Rebuild Failed
An unhandled error occurred inside electron-rebuild
make: Entering directory ‘/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/wiring-pi-2019/build’
CXX(target) Release/obj.target/wiringPi/src/addon.o
In file included from /home/pi/.electron-gyp/6.1.7/include/node/v8-internal.h:14,
from /home/pi/.electron-gyp/6.1.7/include/node/v8.h:25,
from …/src/addon.h:4,
from …/src/addon.cc:1:
/home/pi/.electron-gyp/6.1.7/include/node/v8config.h:326:49: warning: ‘MicrotasksCompletedCallback’ is deprecated [-Wdeprecated-declarations]
declarator attribute((deprecated(message)))
^
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:8205:3: note: in expansion of macro ‘V8_DEPRECATE_SOON’
V8_DEPRECATE_SOON("Use WithData version.",
^~~~~~~~~~~~~~~~~
/home/pi/.electron-gyp/6.1.7/include/node/v8config.h:326:49: warning: ‘MicrotasksCompletedCallback’ is deprecated [-Wdeprecated-declarations]
declarator attribute((deprecated(message)))
^
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:8214:3: note: in expansion of macro ‘V8_DEPRECATE_SOON’
V8_DEPRECATE_SOON("Use WithData version.",
^~~~~~~~~~~~~~~~~
In file included from …/src/addon.cc:1:
…/src/addon.h:12:28: error: ‘Handle’ is not a member of ‘v8’
bool HasInstance(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:12:44: error: expected primary-expression before ‘>’ token
bool HasInstance(v8::Handlev8::Value val);
^
…/src/addon.h:12:46: error: ‘val’ was not declared in this scope
bool HasInstance(v8::Handlev8::Value val);
^~~
…/src/addon.h:13:28: error: redefinition of ‘bool node::Buffer::HasInstance’
bool HasInstance(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:12:12: note: ‘bool node::Buffer::HasInstance’ previously defined here
bool HasInstance(v8::Handlev8::Value val);
^~~~~~~~~~~
…/src/addon.h:13:28: error: ‘Handle’ is not a member of ‘v8’
bool HasInstance(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:13:45: error: expected primary-expression before ‘>’ token
bool HasInstance(v8::Handlev8::Object val);
^
…/src/addon.h:13:47: error: ‘val’ was not declared in this scope
bool HasInstance(v8::Handlev8::Object val);
^~~
…/src/addon.h:14:22: error: ‘Handle’ is not a member of ‘v8’
char Data(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:14:38: error: expected primary-expression before ‘>’ token
char Data(v8::Handlev8::Value val);
^
…/src/addon.h:14:40: error: ‘val’ was not declared in this scope
char* Data(v8::Handlev8::Value val);
^~~
…/src/addon.h:15:22: error: redefinition of ‘char* node::Buffer::Data’
char* Data(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:14:13: note: ‘char* node::Buffer::Data’ previously defined here
char* Data(v8::Handlev8::Value val);
^~~~
…/src/addon.h:15:22: error: ‘Handle’ is not a member of ‘v8’
char* Data(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:15:39: error: expected primary-expression before ‘>’ token
char* Data(v8::Handlev8::Object val);
^
…/src/addon.h:15:41: error: ‘val’ was not declared in this scope
char* Data(v8::Handlev8::Object val);
^~~
…/src/addon.h:16:25: error: ‘Handle’ is not a member of ‘v8’
size_t Length(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:16:41: error: expected primary-expression before ‘>’ token
size_t Length(v8::Handlev8::Value val);
^
…/src/addon.h:16:43: error: ‘val’ was not declared in this scope
size_t Length(v8::Handlev8::Value val);
^~~
…/src/addon.h:17:25: error: redefinition of ‘size_t node::Buffer::Length’
size_t Length(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:16:14: note: ‘size_t node::Buffer::Length’ previously defined here
size_t Length(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:17:25: error: ‘Handle’ is not a member of ‘v8’
size_t Length(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:17:42: error: expected primary-expression before ‘>’ token
size_t Length(v8::Handlev8::Object val);
^
…/src/addon.h:17:44: error: ‘val’ was not declared in this scope
size_t Length(v8::Handlev8::Object val);
^~~
…/src/addon.cc: In function ‘void throw_error(v8::Isolate*, const char*, …)’:
…/src/addon.cc:35:90: error: no matching function for call to ‘v8::Exception::Error(v8::MaybeLocalv8::String)’
isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, buffer)));
^
In file included from …/src/addon.h:4,
from …/src/addon.cc:1:
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:6538:23: note: candidate: ‘static v8::Localv8::Value v8::Exception::Error(v8::Localv8::String)’
static Local Error(Local message);
^~~~~
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:6538:23: note: no known conversion for argument 1 from ‘v8::MaybeLocalv8::String’ to ‘v8::Localv8::String’
make: *** [wiringPi.target.mk:147: Release/obj.target/wiringPi/src/addon.o] Error 1
make: Leaving directory ‘/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/wiring-pi-2019/build’
gyp ERR! build error
gyp ERR! stack Error:makefailed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.19.118-v7l+
gyp ERR! command “/usr/bin/node” “/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/.bin/node-gyp” “rebuild” “–target=6.1.7” “–arch=arm” “–dist-url=https://www.electronjs.org/headers” “–build-from-source”
gyp ERR! cwd /home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/wiring-pi-2019
gyp ERR! node -v v10.21.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not okFailed with exit code: 1
Error: make: Entering directory ‘/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/wiring-pi-2019/build’
CXX(target) Release/obj.target/wiringPi/src/addon.o
In file included from /home/pi/.electron-gyp/6.1.7/include/node/v8-internal.h:14,
from /home/pi/.electron-gyp/6.1.7/include/node/v8.h:25,
from …/src/addon.h:4,
from …/src/addon.cc:1:
/home/pi/.electron-gyp/6.1.7/include/node/v8config.h:326:49: warning: ‘MicrotasksCompletedCallback’ is deprecated [-Wdeprecated-declarations]
declarator attribute((deprecated(message)))
^
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:8205:3: note: in expansion of macro ‘V8_DEPRECATE_SOON’
V8_DEPRECATE_SOON("Use WithData version.",
^~~~~~~~~~~~~~~~~
/home/pi/.electron-gyp/6.1.7/include/node/v8config.h:326:49: warning: ‘MicrotasksCompletedCallback’ is deprecated [-Wdeprecated-declarations]
declarator attribute((deprecated(message)))
^
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:8214:3: note: in expansion of macro ‘V8_DEPRECATE_SOON’
V8_DEPRECATE_SOON("Use WithData version.",
^~~~~~~~~~~~~~~~~
In file included from …/src/addon.cc:1:
…/src/addon.h:12:28: error: ‘Handle’ is not a member of ‘v8’
bool HasInstance(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:12:44: error: expected primary-expression before ‘>’ token
bool HasInstance(v8::Handlev8::Value val);
^
…/src/addon.h:12:46: error: ‘val’ was not declared in this scope
bool HasInstance(v8::Handlev8::Value val);
^~~
…/src/addon.h:13:28: error: redefinition of ‘bool node::Buffer::HasInstance’
bool HasInstance(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:12:12: note: ‘bool node::Buffer::HasInstance’ previously defined here
bool HasInstance(v8::Handlev8::Value val);
^~~~~~~~~~~
…/src/addon.h:13:28: error: ‘Handle’ is not a member of ‘v8’
bool HasInstance(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:13:45: error: expected primary-expression before ‘>’ token
bool HasInstance(v8::Handlev8::Object val);
^
…/src/addon.h:13:47: error: ‘val’ was not declared in this scope
bool HasInstance(v8::Handlev8::Object val);
^~~
…/src/addon.h:14:22: error: ‘Handle’ is not a member of ‘v8’
char Data(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:14:38: error: expected primary-expression before ‘>’ token
char Data(v8::Handlev8::Value val);
^
…/src/addon.h:14:40: error: ‘val’ was not declared in this scope
char* Data(v8::Handlev8::Value val);
^~~
…/src/addon.h:15:22: error: redefinition of ‘char* node::Buffer::Data’
char* Data(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:14:13: note: ‘char* node::Buffer::Data’ previously defined here
char* Data(v8::Handlev8::Value val);
^~~~
…/src/addon.h:15:22: error: ‘Handle’ is not a member of ‘v8’
char* Data(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:15:39: error: expected primary-expression before ‘>’ token
char* Data(v8::Handlev8::Object val);
^
…/src/addon.h:15:41: error: ‘val’ was not declared in this scope
char* Data(v8::Handlev8::Object val);
^~~
…/src/addon.h:16:25: error: ‘Handle’ is not a member of ‘v8’
size_t Length(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:16:41: error: expected primary-expression before ‘>’ token
size_t Length(v8::Handlev8::Value val);
^
…/src/addon.h:16:43: error: ‘val’ was not declared in this scope
size_t Length(v8::Handlev8::Value val);
^~~
…/src/addon.h:17:25: error: redefinition of ‘size_t node::Buffer::Length’
size_t Length(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:16:14: note: ‘size_t node::Buffer::Length’ previously defined here
size_t Length(v8::Handlev8::Value val);
^~~~~~
…/src/addon.h:17:25: error: ‘Handle’ is not a member of ‘v8’
size_t Length(v8::Handlev8::Object val);
^~~~~~
…/src/addon.h:17:42: error: expected primary-expression before ‘>’ token
size_t Length(v8::Handlev8::Object val);
^
…/src/addon.h:17:44: error: ‘val’ was not declared in this scope
size_t Length(v8::Handlev8::Object val);
^~~
…/src/addon.cc: In function ‘void throw_error(v8::Isolate*, const char*, …)’:
…/src/addon.cc:35:90: error: no matching function for call to ‘v8::Exception::Error(v8::MaybeLocalv8::String)’
isolate->ThrowException(v8::Exception::Error(v8::String::NewFromUtf8(isolate, buffer)));
^
In file included from …/src/addon.h:4,
from …/src/addon.cc:1:
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:6538:23: note: candidate: ‘static v8::Localv8::Value v8::Exception::Error(v8::Localv8::String)’
static Local Error(Local message);
^~~~~
/home/pi/.electron-gyp/6.1.7/include/node/v8.h:6538:23: note: no known conversion for argument 1 from ‘v8::MaybeLocalv8::String’ to ‘v8::Localv8::String’
make: *** [wiringPi.target.mk:147: Release/obj.target/wiringPi/src/addon.o] Error 1
make: Leaving directory ‘/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/wiring-pi-2019/build’
gyp ERR! build error
gyp ERR! stack Error:makefailed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.19.118-v7l+
gyp ERR! command “/usr/bin/node” “/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/.bin/node-gyp” “rebuild” “–target=6.1.7” “–arch=arm” “–dist-url=https://www.electronjs.org/headers” “–build-from-source”
gyp ERR! cwd /home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/wiring-pi-2019
gyp ERR! node -v v10.21.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not okFailed with exit code: 1
at SafeSubscriber._error (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/spawn-rx/lib/src/index.js:267:84)
at SafeSubscriber.__tryOrUnsub (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:205:16)
at SafeSubscriber.error (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:156:26)
at Subscriber._error (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:92:26)
at Subscriber.error (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:72:18)
at MapSubscriber.Subscriber._error (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:92:26)
at MapSubscriber.Subscriber.error (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:72:18)
at SafeSubscriber._next (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/spawn-rx/lib/src/index.js:242:65)
at SafeSubscriber.__tryOrUnsub (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:205:16)
at SafeSubscriber.next (/home/pi/MagicMirror/modules/MMM-PIR-Sensor/node_modules/rxjs/internal/Subscriber.js:143:22)
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! Magic-Mirror-Module-PIR-Sensor@1.1.0 postinstall:electron-rebuild -e ../../node_modules/electron
npm ERR! Exit status 255
npm ERR!
npm ERR! Failed at the Magic-Mirror-Module-PIR-Sensor@1.1.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2020-07-16T09_45_07_608Z-debug.log
[0_1595277021862_PIR-Sensor Error logs.txt](Uploading 100%) -
I‘d delete the module and re-install it. Obviously you haven’t changed any code (no info on stashing in the log). Your configuration will not be affected when you delete the module, it‘ll persist in config. js.
- stop all processes with entering pm2 stop all.
- cd to the module folder and enter: sudo rm -R MMM-PIR-Sensor. This will recursively remove the MMM-PIR-Sensor folder and it’s contents.
- Re-install the module as described on GitHub. The installation build process should run through without errors.
- Reboot
-
@Fozi rm -rf foldername will recursively remove all folders and content from foldername
-
@sdetweil looks like the wrong compiler level being used for the recompile.
-
Thanks guys, sorry for the late response! It’s the summer holidays so I’ve been doing daddy day care. I’ll try removing the module and reinstalling it. I’ll keep you posted.
-
@Feedy88
Works with out any problems, much better solution then MMM-PIR-Sensor.
Thanks -
Please no ads of any of my modules
If no one respect this rules. I will make private it -
@bugsounet my apologies. I have deleted the post.
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