Skip to content

Commit 6180e2f

Browse files
authored
version 1.3
1 parent 1b8330e commit 6180e2f

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

MMM-Navigate.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ Module.register("MMM-Navigate",{
2020
sendAction: function(description) {
2121
this.show(0,{force: true});
2222

23-
if((description.payload.action == "SHUTDOWN" || description.payload.action == "RESTART" || description.payload.action == "REBOOT") && (vconfirm==0)){
23+
if((description.notification == "SHELLCOMMAND") && (vconfirm==0)){
2424
vconfirm = 1;
25-
this.sendNotification("SHOW_ALERT",{type:"notification",message:"Ausführen von "+ description.payload.action +" bitte durch 2.Klick bestätigen"});
25+
this.sendNotification("SHOW_ALERT",{type:"notification",message:"Ausführen von SHELLCOMMAND "+ description.payload +" bitte durch 2.Klick bestätigen"});
26+
}else if((description.notification == "SHELLCOMMAND") && (vconfirm==1)){
27+
vconfirm = 0;
28+
this.sendSocketNotification(description.notification, description.payload);
2629
}else{
2730
vconfirm = 0;
2831
this.sendNotification(description.notification, description.payload);
@@ -149,6 +152,10 @@ Module.register("MMM-Navigate",{
149152
if(notification === "CW" || notification === "CCW" || notification === "PRESSED"){
150153
this.naviaction({inputtype: ""+ notification +""});
151154
}
155+
156+
if(notification === "SHELLCOMMAND"){
157+
this.sendSocketNotification(notification, payload);
158+
}
152159
},
153160

154161
// socketNotificationReceived from helper
@@ -157,5 +164,4 @@ Module.register("MMM-Navigate",{
157164
this.naviaction(payload);
158165
}
159166
},
160-
161-
});
167+
});

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ To use this module, add it to the modules array in the `config/config.js` file:
4242
Action: [
4343
[{notification:'PAGE_INCREMENT',payload:''},{notification:'PAGE_DECREMENT',payload:''}],//action array, first press locks menu, after this rotation CW/CCW executes, second press release lock mode
4444
[{notification:'ARTICLE_MORE_DETAILS',payload:''},{notification:'ARTICLE_LESS_DETAILS',payload:''}],
45-
{notification: "SHOW_ALERT", payload: {type:"notification",message:"Dies ist eine Testnachricht"}},//single action, execute on press
45+
{notification: 'SHOW_ALERT', payload: {type:'notification',message:'Dies ist eine Testnachricht'}},//single action, execute on press
4646
{notification:'ARTICLE_MORE_DETAILS',payload:''},
4747
{notification:'ARTICLE_LESS_DETAILS',payload:''},
48-
{notification: "REMOTE_ACTION", payload: {action: "RESTART"}},
49-
{notification: "REMOTE_ACTION", payload: {action: "REBOOT"}},
50-
{notification: "REMOTE_ACTION", payload: {action: "SHUTDOWN"}}
48+
{notification: 'SHELLCOMMAND', payload:'pm2 restart mm'},
49+
{notification: 'SHELLCOMMAND', payload:'sudo reboot'},
50+
{notification: 'SHELLCOMMAND', payload:'sudo shutdown -h now'}
5151
],
5252
GPIOPins: [26,20,19]//rotary cw, rotary ccw, rotary press (BCM Numbering)
5353
},
@@ -80,21 +80,30 @@ The following properties can be configured:
8080
<td><code>GPIOPins</code></td>
8181
<td>Array for Definition of GPIO-Pins (BMC) to connect the rotary encoder for the following actions: Clockwise, Counterclockwise and Press</td>
8282
</tr>
83+
<tr>
84+
<td><code>SHELLCOMMAND</code></td>
85+
<td>Executes code in a terminal of you pi, so you can do almost everything you want. Example you want to shutdown your pi; Config: <code>
86+
{notification: 'SHELLCOMMAND', payload:'sudo shutdown -h now'}</code><br>
87+
</td>
88+
</tr>
8389
</table>
84-
Further information:<br>In version 1.1 of the module, i added a 'second click confirmation notification' for the following <code>REMOTE_ACTIONs</code>.<br>
85-
- SHUTDOWN<br>
86-
- RESTART<br>
87-
- REBOOT<br>
88-
This means, if you select one of these entries and press the rotary, you get a notification to do a second press to execute the selected entry.
90+
Further information:<br>In version 1.1 of the module, i added a 'second click confirmation notification' for the following <code>SHELLCOMMAND</code>.<br>
91+
This means, if you are using SHELLCOMMAND and press the rotary, you get a notification to do a second press to execute the selected entry.
8992

9093
## Further options
9194
You can communication with this module also by sending notifications.
9295
Examples:
93-
<code>yourmmip:8080/remote?action=NOTIFICATION&notification=CCW</code> emulates turning rotary counterclockwise
94-
<code>yourmmip:8080/remote?action=NOTIFICATION&notification=CW</code> emulates turning rotary clockwise
95-
<code>yourmmip:8080/remote?action=NOTIFICATION&notification=PRESSED</code> emulates pressing rotary encoder
96+
<code>yourmmip:8080/MMM-Navigate/remote?action=NOTIFICATION&notification=CCW</code> emulates turning rotary counterclockwise
97+
<code>yourmmip:8080/MMM-Navigate/remote?action=NOTIFICATION&notification=CW</code> emulates turning rotary clockwise
98+
<code>yourmmip:8080/MMM-Navigate/remote?action=NOTIFICATION&notification=PRESSED</code> emulates pressing rotary encoder
99+
<code>yourmmip:8080/MMM-Navigate/remote?notification=SHELLCOMMAND&action=sudo%20shutdown%20-h%20now</code> send command to shutdown your pi
96100

97101
## Version
102+
1.3 Changelog:
103+
- added some functions to no longer have a dependency to MMM-Remote-Control
104+
- SHELLCOMMAND
105+
- module is now listening to <code>yourmmip:8080/MMM-Navigate/remote?</code>
106+
98107
1.2 Changelog:
99108
- added lock icon next to navigation alias, if locked
100109
- code cleaned
@@ -104,6 +113,6 @@ The following properties can be configured:
104113
- added ability to send notifications to MMM-Navigate by other modules
105114
- added locked mode, so you can put two(2) actions in one(1) navigation link which belong together (like PAGE_INCREMENT and PAGE_DECREMENT). More details see Configuration options (Action).
106115
- modified css, so locked mode is visual (red frame when locked) in MM
107-
- added second click confirmation notification' for the following REMOTE_ACTIONs (SHUTDOWN, RESTART, REBOOT)
116+
- added second click confirmation notification for SHELLCOMMAND
108117

109118
1.0 initial release

node_helper.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
const Gpio = require('onoff').Gpio;
1313
const moment = require('moment');//needed for time
1414
var NodeHelper = require("node_helper");
15+
const exec = require("child_process").exec;
16+
const url = require("url");
17+
const express = require("express");
1518
//Variables
1619
action = '';
1720
helfer = '';
@@ -23,6 +26,7 @@ module.exports = NodeHelper.create({
2326
start: function() {
2427
var self = this;
2528
this.loaded = false;
29+
this.createRoutes();
2630
},
2731

2832
intializeButtons: function() {
@@ -91,14 +95,26 @@ module.exports = NodeHelper.create({
9195

9296
// Override socketNotificationReceived method.
9397
socketNotificationReceived: function(notification, payload) {
94-
if (notification === 'START') {
95-
console.log("Working notification system. Notification:", notification, "payload: ", payload);
96-
// Send notification
97-
this.sendSocketNotification('MSG', {message: 'test'});
98-
}else if (notification === 'BUTTON_CONFIG') {
98+
if (notification === 'BUTTON_CONFIG') {
9999
this.config = payload.config;
100100
this.intializeButtons();
101101
}
102+
103+
if (notification === 'SHELLCOMMAND') {
104+
console.log("MMM-Navigate, received Shellcommand:", payload);
105+
exec(payload, null);
106+
}
102107
},
103-
104-
});
108+
109+
createRoutes: function() {
110+
var self = this;
111+
112+
this.expressApp.get("/MMM-Navigate/remote", function(req, res) {
113+
var query = url.parse(req.url, true).query;
114+
if(query.notification=='CW' || query.notification=='CCW' || query.notification=='PRESSED'){
115+
self.sendSocketNotification(query.notification,{inputtype: ""+query.notification+""});
116+
}
117+
res.send("MMM-Navigate, data received: "+ JSON.stringify(query));
118+
});
119+
},
120+
});

0 commit comments

Comments
 (0)