Archive

Archive for July, 2019

Free #Alexa Skill for Air Quality in Northern Ireland – #OpenSource

air-quality

This is a free skill available for Alexa, that you can enable here;

https://smile.amazon.co.uk/Open-Merchant-Account-Ltd-Northern/dp/B07TSRZCMT/ref=sr_1_1

It’s open source, and open to improvements and suggestions by anyone interested in collaborating.

You can ask it questions such as “Alexa, ask air quality northern Ireland what is the level of nitrous oxide in Belfast“, or ask about particulate matter, carbon monoxide, ozone, or sulfur dioxide.

The data itself is courtesty of  the Northern Ireland Department of Environment. via AirQualityNI.

At a high level, this skill runs on the Alexa platform, which hooks into Amazon’s Lambda service, running NodeJS. From there, it connects to an API, which is described here; https://github.com/infiniteloopltd/airquality – Which is hosted on a Windows server, and makes the connection on to the AirQualityNI website, and dynamically converts CSV data to the more readable JSON format.

Here is a run down on the constituent parts

The Alexa interaction model is defined here; https://github.com/infiniteloopltd/AirQuality/blob/master/Alexa/interaction.json

This defines the phrases that can be used with the skill, such as

What is the level of Nitrous oxide in {city}

Where {city} is of type AMAZON.GB_CITY, this is interpreted as the NitrogenOxideIntent, and passed to the Lambda handler at index.js here;

https://github.com/infiniteloopltd/AirQuality/blob/master/Lambda/index.js

This, then checks the intentName, and if it’s equal to NitrogenOxideIntent, then handleNitrogenOxideIntent is called, which then calls airQuality.NitrogenOxide(..), which is defined here:

https://github.com/infiniteloopltd/AirQuality/blob/master/Lambda/airquality.js

The NitrogenOxide() function calls DescribePollutants(), passing a function to filter the data by city, and these three types of Nitrogen-Oxide pollutants; “NO“,”NO₂” and “NOₓ as NO₂“. DescribePollutants() then makes an HTTP request to http://airquality.derrycreativescollective.com/, which returns yesterday’s mean values of air pollutants in Northen Ireland. – It then formats the response into a spoken string, for example, using NamePollutant() to convert chemical formulae like “NO₂” to “Nitrogen Dioxide”. 

Please, feel free to enable the skill on your alexa device, and give it a good rating, also feel free to contact me if you’d like to build upon this skill or API.

 

 

 

 

 

Advertisements
Categories: Uncategorized

Air Quality #API for Northern Ireland

download

AirQuality

This is a simple API based on the data available from http://www.airqualityni.co.uk/ by default, it will return a daily mean of Yesterday’s Automatic Monitoring Data for all pollutants, for all regions in northern ireland.

To specify a specific date, other than yesterday, use a date parameter in the querystring, such as http://airquality.derrycreativescollective.com/?date=01/01/2019

Source: https://github.com/infiniteloopltd/AirQuality

Sample data:

[
 {
  "Date": "03/07/2019",
  "Site": "Armagh Lonsdale Road",
  "Pollutant": "NO",
  "Daily_Mean": "26",
  "Status": "P",
  "Unit": "µg/m³"
 },
 {
  "Date": "03/07/2019",
  "Site": "Armagh Lonsdale Road",
  "Pollutant": "NO₂",
  "Daily_Mean": "17",
  "Status": "P",
  "Unit": "µg/m³"
 },

 

Developed by http://www.derrycreativescollective.com / http://www.infiniteloop.ie

Categories: Uncategorized

#Webcam streamer #app using C#

webcam

This is a bit of a resurrection of an old project http://mobilewebcam.co.uk/ – How it works, is that there is a iOS App available here “https://apps.apple.com/us/app/mobile-webcam/id652758590” which reads images that are posted to a URL via a Windows application that is downloadable here; http://j.mp/webpalm – and there is a Webservice here; http://www.mobilewebcam.co.uk/webcam.asmx

So, bascically, the windows application uploads images contstantly to the service via the webservice, and the mobile application reads the url of where the image should be from the web service, and constantly refreshes the image. If the connection is fast enough, it looks like video – although always a bit jerky.

Is it a great design, no – but to be honest, for me, this was about bringing an old app and website back to life, and I was surprised it still worked, all I did was renew the expired domain name!

You can probably see the age, from the links to Palm and Windows Phone, both of which are obsolete now!

 

 

Categories: Uncategorized

#Unsplash #API using C#

unsplashd

Unsplash is a great source of free photos, that you can use in your websites, and it also offers an API that allows you to integrate free image searches into your app. This might be an easy way to add a splash of colour to features that otherwise might just have a placeholder image.

In order to use their API, you need to register as a developer with them, then create an application, and with that you’ll get your access key and secret key. For this application, I’m only using the access key, since I’m only looking at public data.

So, for those who want to cut right to the code, here is the github repo: https://github.com/infiniteloopltd/unsplash and here is a demo http://unsplash.apixml.net/

The page is written in bootstrap and jquery, with the results rendered using Mustache. The magic happens with a call from the javascript to an ASPX page with this AJAX call;

function callAPI(searchTerm) {
    if (searchTerm === "") {
        bootbox.alert("Please enter a search term");
        return;
    }
    $("#btnSearch").addClass("disabled");
    console.log("searching: " + searchTerm);
    $.getJSON("/search.aspx?searchTerm=" + searchTerm,
        function (data) {
            $("#btnSearch").removeClass("disabled");
            if (data.results.length === 0) {
                bootbox.alert("Sorry, No Results");
            }
            var tpl = $("#tplItem").html();
            var strHtml = Mustache.render(tpl, data);
            $("#divResults").html(strHtml);
        });
}

Then we just proxy the call to the unsplash /search/photos API call as follows;

var searchTerm = Request.QueryString[“searchTerm”];
if (string.IsNullOrEmpty(searchTerm))
{
throw new Exception(“searchTerm is required”);
}
var strUrl = “https://api.unsplash.com/search/photos?”;
strUrl += “client_id=c9492064c857d14c8704afd5e85e22df1413d97f54002f62037313049395b3c9”;
strUrl += “&query=” + searchTerm;
/*
query Search terms.
page Page number to retrieve. (Optional; default: 1)
per_page Number of items per page. (Optional; default: 10)
collections Collection ID(‘s) to narrow search. If multiple, comma-separated.
orientation Filter search results by photo orientation. Valid values are landscape, portrait, and squarish.
*/
var wc = new WebClient();
var strJson = wc.DownloadString(strUrl);
Response.Write(strJson);

Once the json is back, we can render it with the following Mustache template

   {{#results}}
        <a href="{{urls.full}}" class="list-group-item" target="_blank">
            <img src="{{urls.thumb}}" style="width: 100px; height: 100px; padding-right:10px" >{{alt_description}}
            <span class="badge badge-dark">{{likes}} Likes</span>          
        </a>
        {{/results}}

 

Categories: Uncategorized