HomeAutomation/MqttDasherService.md
... ...
@@ -2,70 +2,75 @@
2 2
title: MqttDasherService
3 3
---
4 4
5
-Create an mqtt-dasher service. (Debian/Ubuntu distros).
5
+Create an mqtt-dasher service. (Debian/Ubuntu distros).
6 6
7 7
8 8
9 9
mqtt-dasher
10
-: <https://github.com/stjohnjohnson/mqtt-dasher>
10
+: <https://github.com/stjohnjohnson/mqtt-dasher>
11 11
12
-Limits permissions for promiscuous net socket access via libpcap.
12
+Limits permissions for promiscuous net socket access via libpcap.
13 13
14
-This assumes `npm install` without the global flag so uses `/opt/node_modules` instead of `/usr/lib`.
14
+This assumes `npm install` without the global flag so uses `/srv/mqtt-dasher/node_modules` instead of `/usr/lib`.
15 15
16 16
17
+# Pre-Install
17 18
18
-# Install
19
+Install nodejs and npm.
19 20
20
-
21
+Something like:
21 22
22 23
# install nodejs from debsource
23 24
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
24 25
sudo apt-get install -y nodejs
25
-
26
+
27
+# Install
28
+
29
+
26 30
# install mqtt-dasher and libpcap dependency
27 31
sudo apt-get install libpcap-dev
28 32
sudo npm install mqtt-dasher
29
-
33
+
30 34
# add user to run the service, and group to limit access to setcap files
31
- sudo useradd mqtt-dasher -d /opt/node_modules/mqtt-dasher -U
32
-
35
+ sudo useradd mqtt-dasher -d /srv/mqtt-dasher -U
36
+
33 37
# make a copy of nodejs to set privileged net capabilities on
34
- sudo cp `which nodejs` /opt/node_modules/mqtt-dasher/nodejs.setcap
35
-
38
+ sudo cp `which nodejs` /srv/mqtt-dasher/nodejs.setcap
39
+
36 40
# set user and group for mqtt-dasher first
37
- sudo chgrp mqtt-dasher /opt/node_modules/mqtt-dasher/nodejs.setcap
38
- sudo chmod 750 /opt/node_modules/mqtt-dasher/nodejs.setcap
39
-
41
+ sudo chgrp mqtt-dasher /srv/mqtt-dasher/nodejs.setcap
42
+ sudo chmod 750 /srv/mqtt-dasher/nodejs.setcap
43
+
40 44
# allow raw sockets and net admin for promiscuous mode
41
- sudo setcap 'CAP\_NET\_RAW+eip CAP\_NET\_ADMIN+eip' /opt/node_modules/mqtt-dasher/nodejs.setcap
42
-
45
+ sudo setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /srv/mqtt-dasher/nodejs.setcap
46
+
43 47
44 48
45 49
46 50
## Create the Service
47 51
48
-`/etc/systemd/system/mqtt-dasher.service`
49
-
50
- [Unit]
51
- Description=mqtt-dasher service
52
-
53
- [Service]
54
- ExecStart=/opt/node_modules/mqtt-dasher/nodejs.setcap /opt/node_modules/mqtt-dasher/server.js
55
- # WorkingDirectory=/opt/node_modules/mqtt-dasher # Required on some systems
56
- Restart=always
57
- RestartSec=10 # Restart service after 10 seconds if node service crashes
58
- StandardOutput=syslog # Output to syslog
59
- StandardError=syslog # Output to syslog
60
- SyslogIdentifier=mqtt-dasher
61
- User=mqtt-dasher
62
- Group=mqtt-dasher
63
- Environment=CONFIG_DIR=/etc/mqtt-dasher NODE_ENV=production
64
-
65
- [Install]
66
- WantedBy=multi-user.target
67
-
68
-
52
+`/etc/systemd/system/mqtt-dasher.service`:
53
+
54
+```systemd
55
+[Unit]
56
+Description=mqtt-dasher service
57
+
58
+[Service]
59
+ExecStart=/srv/mqtt-dasher/nodejs.setcap /srv/mqtt-dasher/node_modules/mqtt-dasher/server.js
60
+# WorkingDirectory=/srv/mqtt-dasher # Required on some systems
61
+Restart=always
62
+RestartSec=10 # Restart service after 10 seconds if node service crashes
63
+StandardOutput=syslog # Output to syslog
64
+StandardError=syslog # Output to syslog
65
+SyslogIdentifier=mqtt-dasher
66
+User=mqtt-dasher
67
+Group=mqtt-dasher
68
+Environment=CONFIG_DIR=/etc/mqtt-dasher NODE_ENV=production
69
+
70
+[Install]
71
+WantedBy=multi-user.target
72
+```
73
+
69 74
70 75
71 76
... ...
@@ -73,36 +78,35 @@ This assumes `npm install` without the global flag so uses `/opt/node_modules` i
73 78
74 79
sudo mkdir /etc/mqtt-dasher
75 80
76
-[[$[Get Code]]][2]
81
+`/etc/mqtt-dasher/config.yml`:
77 82
78
-`/etc/mqtt-dasher/config.yml`
83
+```yaml
84
+mqtt:
85
+ host: localhost
86
+ ## Preface for the topics $PREFACE/$TOPIC
87
+ ## (not in mqtt-dasher 0.1.0)
88
+ #preface: ha/dash
79 89
80
- mqtt:
81
- host: localhost
82
- ## Preface for the topics $PREFACE/$TOPIC
83
- ## (not in mqtt-dasher 0.1.0)
84
- #preface: ha/dash
85
-
86
- buttons:
87
- ab:cd:ef:12:34:56: ha/dash/listerine
88
-
90
+buttons:
91
+ ab:cd:ef:12:34:56: ha/dash/listerine
89 92
93
+```
90 94
91 95
92 96
93 97
sudo systemctl enable mqtt-dasher
94 98
sudo systemctl start mqtt-dasher
95
-
99
+
96 100
97 101
98 102
99 103
# Home Assistant Switch
100 104
101
-An mqtt switch which:
105
+An mqtt switch which:
102 106
103
-* turns on when the dash button is activated
104
-* turns off when the dash button deactivates
105
-* can be activated and deactivated from HA
107
+* turns on when the dash button is activated
108
+* turns off when the dash button deactivates
109
+* can be activated and deactivated from HA
106 110
107 111
108 112
... ...
@@ -115,21 +119,17 @@ An mqtt switch which:
115 119
  payload_on: 'active'
116 120
  payload_off: 'inactive'
117 121
  retain: false
118
-
119 122
120
-The switch isn't intended to be used in the HA UI, it should be mapped to a script instead.
123
+
124
+The switch isn't intended to be used in the HA UI, it should be mapped to a script instead.
121 125
122 126
123 127
124 128
# To Do
125 129
126
-Compile mqtt-dasher with [nexe][5] so that `nodejs.setcap` can't be so easily abused.
130
+Compile mqtt-dasher with [nexe][1] so that `nodejs.setcap` can't be so easily abused.
127 131
128
- [1]: MqttDasherService?action=sourceblock&num=1
129
- [2]: MqttDasherService?action=sourceblock&num=2
130
- [3]: MqttDasherService?action=sourceblock&num=3
131
- [4]: MqttDasherService?action=sourceblock&num=4
132
- [5]: https://github.com/nexe/nexe
132
+ [1]: https://github.com/nexe/nexe
133 133
134 134
<!--
135 135
vim: filetype=markdown