Created
January 9, 2020 20:30
-
-
Save owise1/4b7ca5710a4e224fdadea3dca103a055 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AmbientWeatherApi = require('ambient-weather-api') | |
// helper function | |
function getName (device) { | |
return device.info.name | |
} | |
const apiKey = process.env.AMBIENT_WEATHER_API_KEY || 'Put your AW apiKey here' | |
const api = new AmbientWeatherApi({ | |
apiKey, | |
applicationKey: process.env.AMBIENT_WEATHER_APPLICATION_KEY || 'Put your AW applicationKey here' | |
}) | |
api.connect() | |
api.on('connect', () => console.log('Connected to Ambient Weather Realtime API!')) | |
api.on('subscribed', data => { | |
console.log('Subscribed to ' + data.devices.length + ' device(s): ') | |
console.log(data.devices.map(getName).join(', ')) | |
}) | |
api.on('data', data => { | |
console.log(data.date + ' - ' + getName(data.device) + ' current outdoor temperature is: ' + data.tempf + '°F') | |
}) | |
api.subscribe(apiKey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment