/config.yml.dist |
@@ -0,0 +1,28 @@ |
########################################################################### |
## 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: "alexatts.log" |
|
mqtt: |
url: "mqtt://server.tld" |
# The topic to subscribe to. |
topic: "alexatts/#" |
|
language: 'en-US' |
|
# The audio card to use in Alsa format (aplay should work) |
card: 'sysdefault:CARD=audioinjectorpi' |
|
# 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 |
# Alexa remote. |
# ptt - push to talk, this is the top most button |
GPIO: |
ptt: 16 |
|
# This is the name of the Alexa device - the keyword you use to talk to |
# the Alexa device. |
alexa: 'Alexa' |
/main.js |
@@ -9,12 +9,22 @@ |
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'); |
|
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) |
|
// Generate GPIO pins for configuration. |
var COOL = {}; |
var ATTS = {}; |
for(var i in config.GPIO) { |
if(!config.GPIO.hasOwnProperty(i)) |
continue; |
@@ -22,7 +32,7 @@ |
if(config.GPIO[i] === -1) |
continue; |
|
COOL[i] = new Gpio(config.GPIO[i], 'out') |
ATTS[i] = new Gpio(config.GPIO[i], 'out') |
} |
|
// Set up logger. |
@@ -43,31 +53,20 @@ |
// Remove any retained message. |
client.publish(topic, "", {retain: true}) |
|
message. |
message = message.toString() |
winston.info('Received message: ' + 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].write(1, (err) => { |
|
ATTS["ptt"].write(1, (err) => { |
if(err) { |
winston.err('Unable to toggle pin ' + pin + ' error message received is: ' + err.message) |
winston.err('Unable to press push-to-talk button: ' + err.message) |
return; |
} |
|
setTimeout(function() { |
winston.info('Toggled pin ' + pin + ' for ' + message) |
COOL[message].write(0) |
}, 1000) |
|
// 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)); |
}) |
}) |
|