const AmbientWeatherApi = require("ambient-weather-api") // helper function function getName (device) { return device.info.name } const apiKey = '78f9704baaab411a87edeed59052cbb687a4aa7764a44accbaf6447492b0ca8c' const api = new AmbientWeatherApi({ apiKey, applicationKey: '21a439e927a84a25bb79ffe894fdd372b3e9d2e8bcef4167943b52cbe4530d9f' }) 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.disconnect() console.log('Disconnected.') }) api.subscribe(apiKey)
Save on
Powered by
Node 8.11.1
help
Loading…