cool-iot
/trunk/config.yml |
@@ -4,6 +4,8 @@ |
## rights of fair usage, the disclaimer and warranty conditions. ## |
########################################################################### |
|
log: "cool-iot.log" |
|
mqtt: |
url: "mqtt://joey.internal" |
# The topic to subscribe to. |
/trunk/contrib/cool-iot.service |
@@ -0,0 +1,15 @@ |
[Unit] |
Description=Cool IoT |
|
[Service] |
ExecStart=/srv/cool-iot/main.js |
Restart=always |
User=nobody |
# Note RHEL/Fedora uses 'nobody', Debian/Ubuntu uses 'nogroup' |
Group=nobody |
Environment=PATH=/usr/bin:/usr/local/bin |
Environment=NODE_ENV=production |
WorkingDirectory=/srv/cool-iot |
|
[Install] |
WantedBy=multi-user.target |
/trunk/main.js |
@@ -1,3 +1,4 @@ |
#!/usr/bin/env nodejs |
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2018 - License: GNU GPLv3 // |
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
@@ -25,7 +26,7 @@ |
} |
|
// Set up logger. |
winston.add(winston.transports.File, {filename: 'cool-iot.log'}) |
winston.add(winston.transports.File, {filename: config.log}) |
|
// Initiate connection to MQTT. |
const client = mqtt.connect(config.mqtt.url) |
@@ -39,7 +40,7 @@ |
client.on('message', function (topic, message) { |
// message is Buffer |
message = message.toString() |
winston.info('Received request: ' + message) |
winston.info('Received message: ' + message) |
if(!(message in config.GPIO)) { |
winston.warn('Request to toggle unknown GPIO: ' + message) |
return; |