Read the statement by Michael Teeuw here.
Help creating a shutdown button?
-
Hi, I am trying to add a button/switch to my mirror for safe shutdown. I am using RPi3 model B.
I have this: https://www.amazon.com/gp/product/B0170B75EU/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
The problem I am having is with adding the code to make it function as a shutdown button.
Full disclosure: I know absolutely nothing about how to use python.
Any help you can provide would be appreciated.
-
@bez252 I made a module (acutally two) for this, however they are not (very well) documented and I just made them for myself. But if you want, I could upload them.
I have four buttons conncted to the RPi, and one of them shuts down the system on a long press (>3 seconds).
There is also this module, which you can adapt by adding a shutdown command.
-
@Jopyth
That would be awesome, thanks. -
I got one of these for my mirror, still havn’t built or assembled it yet.
https://www.pi-supply.com/product/pi-supply-raspberry-pi-power-switch/
-
@Jopyth So, with the module you linked, would these default settings mean that it activates when pin 5 is grounded? I apologize for all these dumb questions. Iḿ really new to this entire scene. Also, what would I need to change to make it shutdown?
´/* global Module */
/* Magic Mirror
- Module: MMM-Button
- MIT Licensed.
*/
Module.register(‘MMM-Button’,{
defaults: {
buttonPIN: 5,
//time in miliseconds before another button click is recognized
clickDelay: 500,
},
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification === “BUTTON_PRESSED”){
this.sendNotification(notification, payload)
}
},
start: function() {
this.sendSocketNotification(‘BUTTON_CONFIG’, this.config);
Log.info('Starting module: ’ + this.name);
}
});´ -
Also, would these instructions work with the button I have?: http://www.mausberrycircuits.com/pages/setup
Or would they only work with the mausberry circuits buttons that attach to the power cord?
-
@bez252 Actually what they describe might also work for you, based on a quick glance through the setup code.
To shutdown from the
node_helperyou need to change some code in the file(will be inMMM-Button/node_helper.jsin your file system).
Here is an example from my module to shut down the RPi, you can replace theself.sendSocketNotification(...)in thenode_helperwith a similar command:exec('sudo shutdown -h now', null);Also, at the beginning of the file you need to include the
execfunction, like here:const exec = require('child_process').exec;
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