cool-iot

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 1  →  ?path2? @ 2
File deleted
/main.js
/trunk/config.yml
@@ -0,0 +1,36 @@
###########################################################################
## Copyright (C) Wizardry and Steamworks 2018 - License: GNU GPLv3 ##
## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ##
## rights of fair usage, the disclaimer and warranty conditions. ##
###########################################################################
 
mqtt:
url: "mqtt://joey.internal"
# The topic to subscribe to.
topic: "cool-1/#"
 
# The GPIO configuration maps the remote control buttons to GPIO pins as
# they are cabled between the device that the software runs on and the
# universal remote control.
# search - the button for discovering the air conditioner frequency
# switch - the on/off button
# up - the button that turns up the heat
# down - the button that turns down the heat
# cooling - the colling button
# heating - the heating button
# mode - the mode button
# swing - the swing button
# swipe - the swipe button
# fan - the fan button
GPIO:
search: 16
switch: 20
up: -1
down: -1
cooling: -1
heating: -1
mode: -1
swing: -1
swipe: -1
fan: -1
 
/trunk/main.js
@@ -0,0 +1,60 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2018 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
const Gpio = require('onoff').Gpio
const mqtt = require('mqtt')
const YAML = require('yamljs');
const winston = require('winston')
 
// Load configuration file.
const config = YAML.load('config.yml');
 
// Generate GPIO pins for configuration.
var COOL = {};
for(var i in config.GPIO) {
if(!config.GPIO.hasOwnProperty(i))
continue;
 
if(config.GPIO[i] === -1)
continue;
 
COOL[i] = new Gpio(config.GPIO[i], 'out')
}
 
// Set up logger.
winston.add(winston.transports.File, {filename: 'cool-iot.log'})
 
// Initiate connection to MQTT.
const client = mqtt.connect(config.mqtt.url)
 
client.on('connect', function () {
winston.info('Connected to MQTT server')
client.subscribe(config.mqtt.topic)
//client.publish('presence', 'Hello mqtt')
})
 
client.on('message', function (topic, message) {
// message is Buffer
message = message.toString()
winston.info('Received request: ' + message)
if(!(message in config.GPIO)) {
winston.warn('Request to toggle unknown GPIO: ' + message)
return;
}
 
var pin = config.GPIO[message]
if(pin === -1) {
winston.warn('GPIO pin for "' + message + '" is not configured')
return;
}
 
winston.info('Toggling pin ' + pin + ' for ' + message)
COOL[message].writeSync(1)
setTimeout(function() {
winston.info('Toggled pin ' + pin + ' for ' + message)
COOL[message].writeSync(0)
}, 1000)
})
/trunk/package.json
@@ -0,0 +1,26 @@
{
"name": "cool-iot",
"version": "1.0.0",
"description": "Air conditioning automation",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"air",
"conditioning",
"automation"
],
"repository" : {
"type" : "svn",
"url" : "http://svn.grimore.org/cool-iot/trunk"
},
"author": "Wizardry and Steamworks (office@grimore.org)",
"license": "GPL-3.0-only",
"dependencies": {
"mqtt": "^2.17.0",
"onoff": "^3.0.1",
"winston": "^2.4.1",
"yamljs": "^0.3.0"
}
}