Hardware components | ||||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
|
Over 200 million kids around the world are affected by allergic reaction that can be avoided, but are not as there is no friction free simple way to get air quality, allergen information or advice anytime, anywhere. We wanted to change that
We chose ‘Environment’ as the theme and built ‘Breathe’ a far field voice recognition app that collects air quality data from state of the art IoT platforms, meteorological data and more down-to-the street level data, crunches it and provides advice on a range of things including: the quality of air for children with allergies, recommendations for activities based on air quality, air quality levels both indoors and outdoors as well as details on the type of pollutants around,
exports.handler = function(event, context) {
if (event.request.intent) {
if (event.request.intent.name == "FindCity") {
var cityname = event.request.intent.slots.cityname.value;
var http = require('http');
var url = "http://api.breezometer.com/baqi/?key=30a932be434241a4a6e7b25b2564d736&location=" + cityname;
http.get(url, function(response) {
var data = '';
response.on('data', function(x) {
data += x;
});
response.on('end', function() {
data = JSON.parse(data);
var message = data.breezometer_description + ", in ," + cityname;
message += ", Ask me for summary, or recommendations for children, sports, health, or pollutant";
var sessionAttributes = {
airdata : data,
cityname : cityname
};
console.log("CITY NAME " + cityname);
speak(message, context, sessionAttributes);
});
});
} else if (event.request.intent.name == "GetSummary") {
console.log("INTENT IS GET SUMMARY");
getSummary(event, context);
} else if (event.request.intent.name == "GetChildren") {
console.log("INTENT IS GET CHILDREN");
getRecommendationFor(event, context, 'children');
} else if (event.request.intent.name == "GetSports") {
console.log("INTENT IS GET SPORT");
getRecommendationFor(event, context, 'sport');
} else if (event.request.intent.name == "GetHealth") {
console.log("INTENT IS GET HEALTH");
getRecommendationFor(event, context, 'health');
} else if (event.request.intent.name == "GetIndoors") {
console.log("INTENT IS GET INDOORS");
getRecommendationFor(event, context, 'inside');
} else if (event.request.intent.name == "GetOutdoors") {
console.log("INTENT IS GET OUTDOORS");
getRecommendationFor(event, context, 'outside');
} else if (event.request.intent.name == "GetPollutant") {
console.log("INTENT IS GetPollutant");
getRecommendationFor(event, context, 'pollutant');
}
} else {
speak("Ask me for Air quality for a city. For example, Say get details for Santa Clara", context, undefined);
}
};
function handleLaunch(event, context) {
}
function getSummary(event, context) {
if (event.session.attributes) {
data = event.session.attributes.airdata;
cityname = event.session.attributes.cityname;
var message = "In " + cityname + " , " + data.breezometer_description;
message += ", The air quality index is " + data.breezometer_aqi;
message += " , " + getCleanText(data.dominant_pollutant_text.main);
message += ", Possible effects, " + getCleanText(data.dominant_pollutant_text.effects);
message += ", Causes, " + getCleanText(data.dominant_pollutant_text.causes);
message += ", For children, " + getCleanText(data.random_recommendations.children);
message += ", For sports, " + getCleanText(data.random_recommendations.sport);
message += ", For inside, " + getCleanText(data.random_recommendations.inside);
message += ", For health, " + getCleanText(data.random_recommendations.outside);
var sessionAttributes = {
airdata : data,
cityname : cityname
};
speak(message, context, sessionAttributes);
} else
speak("No data in session", context, undefined);
}
function getRecommendationFor(event, context, recType) {
if (event.session.attributes) {
data = event.session.attributes.airdata;
cityname = event.session.attributes.cityname;
var message = "In " + cityname + " for " + recType + "," + data.random_recommendations[recType];
if ('pollutant' == recType) {
message = "The dominant pollutant is , " + getCleanText(data.dominant_pollutant_description);
}
var sessionAttributes = {
airdata : data,
cityname : cityname
};
speak(message, context, sessionAttributes);
} else
speak("No data in session", context, undefined);
}
function getCleanText(inputText) {
if(!inputText){
return "No data available";
}
var cleanText = inputText.replace(/[^a-zA-Z ]/g, "");
cleanText = cleanText.replace(/&/g, "and");
return cleanText;
}
function speak(text, context, sessionAttributes) {
var response = {
outputSpeech : {
type : "PlainText",
text : text
},
card : {
type : "Simple",
title : "IOT",
content : text
},
shouldEndSession : false
};
if (sessionAttributes) {
context.succeed({
response : response,
sessionAttributes : sessionAttributes,
});
} else {
context.succeed({
response : response,
});
}
}
alexa.js
JavaScriptThis is the Lambda function that handles voice commands to get air quality infformation
exports.handler = function(event, context) {
if (event.request.intent) {
if (event.request.intent.name == "FindCity") {
var cityname = event.request.intent.slots.cityname.value;
var http = require('http');
var url = "http://api.breezometer.com/baqi/?key=production-key&location=" + cityname;
http.get(url, function(response) {
var data = '';
response.on('data', function(x) {
data += x;
});
response.on('end', function() {
data = JSON.parse(data);
var message = data.breezometer_description + ", in ," + cityname;
message += ", Ask me for summary, or recommendations for children, sports, health, or pollutant";
var sessionAttributes = {
airdata : data,
cityname : cityname
};
console.log("CITY NAME " + cityname);
speak(message, context, sessionAttributes);
});
});
} else if (event.request.intent.name == "GetSummary") {
console.log("INTENT IS GET SUMMARY");
getSummary(event, context);
} else if (event.request.intent.name == "GetChildren") {
console.log("INTENT IS GET CHILDREN");
getRecommendationFor(event, context, 'children');
} else if (event.request.intent.name == "GetSports") {
console.log("INTENT IS GET SPORT");
getRecommendationFor(event, context, 'sport');
} else if (event.request.intent.name == "GetHealth") {
console.log("INTENT IS GET HEALTH");
getRecommendationFor(event, context, 'health');
} else if (event.request.intent.name == "GetIndoors") {
console.log("INTENT IS GET INDOORS");
getRecommendationFor(event, context, 'inside');
} else if (event.request.intent.name == "GetOutdoors") {
console.log("INTENT IS GET OUTDOORS");
getRecommendationFor(event, context, 'outside');
} else if (event.request.intent.name == "GetPollutant") {
console.log("INTENT IS GetPollutant");
getRecommendationFor(event, context, 'pollutant');
}
} else {
speak("Ask me for Air quality for a city. For example, Say get details for Santa Clara", context, undefined);
}
};
function handleLaunch(event, context) {
}
function getSummary(event, context) {
if (event.session.attributes) {
data = event.session.attributes.airdata;
cityname = event.session.attributes.cityname;
var message = "In " + cityname + " , " + data.breezometer_description;
message += ", The air quality index is " + data.breezometer_aqi;
message += " , " + getCleanText(data.dominant_pollutant_text.main);
message += ", Possible effects, " + getCleanText(data.dominant_pollutant_text.effects);
message += ", Causes, " + getCleanText(data.dominant_pollutant_text.causes);
message += ", For children, " + getCleanText(data.random_recommendations.children);
message += ", For sports, " + getCleanText(data.random_recommendations.sport);
message += ", For inside, " + getCleanText(data.random_recommendations.inside);
message += ", For health, " + getCleanText(data.random_recommendations.outside);
var sessionAttributes = {
airdata : data,
cityname : cityname
};
speak(message, context, sessionAttributes);
} else
speak("No data in session", context, undefined);
}
function getRecommendationFor(event, context, recType) {
if (event.session.attributes) {
data = event.session.attributes.airdata;
cityname = event.session.attributes.cityname;
var message = "In " + cityname + " for " + recType + "," + data.random_recommendations[recType];
if ('pollutant' == recType) {
message = "The dominant pollutant is , " + getCleanText(data.dominant_pollutant_description);
}
var sessionAttributes = {
airdata : data,
cityname : cityname
};
speak(message, context, sessionAttributes);
} else
speak("No data in session", context, undefined);
}
function getCleanText(inputText) {
if(!inputText){
return "No data available";
}
var cleanText = inputText.replace(/[^a-zA-Z ]/g, "");
cleanText = cleanText.replace(/&/g, "and");
return cleanText;
}
function speak(text, context, sessionAttributes) {
var response = {
outputSpeech : {
type : "PlainText",
text : text
},
card : {
type : "Simple",
title : "IOT",
content : text
},
shouldEndSession : false
};
if (sessionAttributes) {
context.succeed({
response : response,
sessionAttributes : sessionAttributes,
});
} else {
context.succeed({
response : response,
});
}
}
Akshay Krishnaiah
1 project • 0 followers
Global Product Head - PayPal Research Labs by day, entrepreneur by night! Warriors Fan Forever!
Comments