Skip to content

Instantly share code, notes, and snippets.

@owise1
Created January 9, 2020 20:30
Show Gist options
  • Save owise1/4b7ca5710a4e224fdadea3dca103a055 to your computer and use it in GitHub Desktop.
Save owise1/4b7ca5710a4e224fdadea3dca103a055 to your computer and use it in GitHub Desktop.
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