/config.yml |
@@ -0,0 +1,38 @@ |
########################################################################### |
## 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. ## |
########################################################################### |
|
log: "cool-iot.log" |
|
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 |
|
/main.js |
@@ -9,22 +9,12 @@ |
const mqtt = require('mqtt') |
const YAML = require('yamljs'); |
const winston = require('winston') |
const picoSpeaker = require('pico-speaker') |
|
// Load configuration file. |
const config = YAML.load('config.yml') |
|
// Define configuration for pico TTS. |
var picoConfig = { |
AUDIO_DEVICE: config.card, |
LANGUAGE: config.language |
}; |
|
// Initialize with config |
picoSpeaker.init(picoConfig) |
|
const config = YAML.load('config.yml'); |
|
// Generate GPIO pins for configuration. |
var ATTS = {}; |
var COOL = {}; |
for(var i in config.GPIO) { |
if(!config.GPIO.hasOwnProperty(i)) |
continue; |
@@ -32,7 +22,7 @@ |
if(config.GPIO[i] === -1) |
continue; |
|
ATTS[i] = new Gpio(config.GPIO[i], 'out') |
COOL[i] = new Gpio(config.GPIO[i], 'out') |
} |
|
// Set up logger. |
@@ -53,20 +43,31 @@ |
// Remove any retained message. |
client.publish(topic, "", {retain: true}) |
|
message. |
message = message.toString() |
winston.info('Received message: ' + message) |
|
ATTS["ptt"].write(1, (err) => { |
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].write(1, (err) => { |
if(err) { |
winston.err('Unable to press push-to-talk button: ' + err.message) |
winston.err('Unable to toggle pin ' + pin + ' error message received is: ' + err.message) |
return; |
} |
|
// Send the message. |
picoSpeaker.speak(config.alexa + ", Simon says, " + message).then(function() { |
winston.info('Message ' + message + ' sent to Alexa.') |
|
ATTS["ptt"].write(0) |
}.bind(this)); |
|
setTimeout(function() { |
winston.info('Toggled pin ' + pin + ' for ' + message) |
COOL[message].write(0) |
}, 1000) |
}) |
}) |
|