Skip to content
Snippets Groups Projects
Commit d181fed5 authored by Alex Ellis's avatar Alex Ellis
Browse files

Change samples to use get-stdin for brevity.

parent 4573f14f
No related branches found
No related tags found
No related merge requests found
......@@ -4,10 +4,9 @@ let sample = require("./sample.json");
let SendColor = require('./sendColor');
let sendColor = new SendColor("alexellis.io/tree1")
var content = '';
process.stdin.resume();
process.stdin.on('data', function(buf) { content += buf.toString(); });
process.stdin.on('end', function() {
const getStdin = require('get-stdin');
getStdin().then(content => {
let request = JSON.parse(content);
handle(request, request.request.intent);
});
......@@ -20,7 +19,7 @@ function tellWithCard(speechOutput) {
process.exit(0);
}
function handle(request,intent) {
function handle(request, intent) {
let colorRequested = intent.slots.LedColor.value;
let req = {r:0,g:0,b:0};
if(colorRequested == "red") {
......@@ -31,10 +30,10 @@ function handle(request,intent) {
req.g = 255;
}
else {
tellWithCard("I heard "+colorRequested+ " but can only do: red, green, blue.", "I heard "+colorRequested+ " but can only do: red, green, blue.");
return tellWithCard("I heard "+colorRequested+ " but can only do: red, green, blue.", "I heard "+colorRequested+ " but can only do: red, green, blue.");
}
var speechOutput = "OK, "+colorRequested+".";
sendColor.sendColor(req, () => {
tellWithCard(speechOutput);
var speechOutput = "OK, " + colorRequested + ".";
return tellWithCard(speechOutput);
});
}
\ No newline at end of file
......@@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"get-stdin": "^5.0.1",
"mqtt": "^2.0.1"
}
}
......@@ -13,7 +13,7 @@ class Send {
var client = mqtt.connect(ops);
client.on('connect', () => {
console.log("Connected");
let payload = req;
let cb = () => {
done();
......@@ -30,7 +30,7 @@ class Send {
done();
};
client.on('connect', () => {
console.log("Connected");
let payload = req;
client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb);
});
......
......@@ -2,21 +2,24 @@
let fs = require('fs');
let sample = require("./sample.json");
var content = '';
process.stdin.resume();
process.stdin.on('data', function(buf) { content += buf.toString(); });
process.stdin.on('end', function() {
getStdin().then(content => {
let request = JSON.parse(content);
handle(request, request.request.intent);
});
function tellWithCard(speechOutput) {
sample.response.outputSpeech.text = speechOutput
sample.response.card.content = speechOutput
sample.response.card.title = "Hostname";
console.log(JSON.stringify(sample));
process.exit(0);
}
function handle(request, intent) {
fs.readFile("/etc/hostname", "utf8", (err, data) => {
if(err) {
return console.log(err);
}
// console.log(content);
sample.response.outputSpeech.text = "Your hostname is: " + data;
sample.response.card.content = "Your hostname is: "+ data
sample.response.card.title = "Your hostname";
console.log(JSON.stringify(sample));
process.exit(0);
});
});
tellWithCard("Your hostname is " + data);
});
};
......@@ -8,5 +8,8 @@
},
"keywords": [],
"author": "",
"license": "ISC"
"license": "ISC",
"dependencies": {
"get-stdin": "^5.0.1"
}
}
......@@ -13,8 +13,8 @@ import (
func main() {
s := &http.Server{
Addr: ":8080",
ReadTimeout: 500 * time.Millisecond,
WriteTimeout: 1 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
MaxHeaderBytes: 1 << 20,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment