diff --git a/README.md b/README.md index b0ade36..4d9c82b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,67 @@ # ambient2pwsweather -Pull weather data from AmbientWeather.net and push to PWSWeather + +Summary +--------------- +*ambient2pwsweather* is an open source Node.js project providing a software bridge between Ambient Weather Stations (through AmbientWeather.net) and PWS Weather. + +Requirements +--------------- +- Node.js 6.x +- [AmbientWeather.net account](https://ambientweather.net) +- [PWSWeather.com account](https://www.pwsweather.com) + + +Installation +--------------- +To use *ambient2pwsweather*, you must first install [Node.js](https://nodejs.org/en/download/). After Node is installed, download and unzip the latest [release](https://github.com/killroyboy/ambient2pwsweather/releases) into any given directory. + +Customize the configuration by copying the `config/default.json` file to `config/local.json` and then editing your settings. If you edit default.json directly, it is likely that future versions of *ambient2pwsweather* will overwrite your customizations. Alternatively, you can use environment variables to override specific configuration variables. + +Open a command line window (`terminal` on MacOS or follow [these instructions](https://www.lifewire.com/command-prompt-2625840) for Windows) and issue the following commands within the yts-downloader directory: + +```js +npm install +``` +```js +node index.js +``` + +The first command will install all the prerequisites and the second starts *ambient2pwsweather*. You will need to keep this window and process running in order to allow it to continue to retrieve data from AmbientWeather.net. There are tools available (like [forever](https://www.npmjs.com/package/forever)) to ensure the process runs in the background. + + +Configuration +--------------- +Below is the default configuration. You can easily customize and override any setting by copying the `config/default.json` file to `config/local.json` and then change any settings you desire. + +```js +{ + "ambient" : { + "api_key" : "", + "app_key" : "" + }, + "pwsweather" : { + "station_id" : "", + "password" : "" + }, + "log_level" : "info", + "pws_base_url" : "http://www.pwsweather.com/pwsupdate/pwsupdate.php" +} +``` +Alternatively, the following environment variables can be used to override configurations. +- AMBIENT_API_KEY - (Obtained from your AmbientWeather.net profile page) +- AMBIENT_APP_KEY - (Obtained by requesting from AmbientWeather support) +- PWD_STATION_ID - (From your PWS Weather account) +- PWD_PASSWORD - (From your PWS Weather account) +- LOG_LEVEL - (debug, info, warn, error) + +Author +--------------- +Dan Wilson ([@killroyboy](https://twitter.com/killroyboy) / [Web](https://www.codeality.com)) + +License +--------------- +MIT + +Contributing +--------------- +Code contributions are greatly appreciated, please submit a new [pull request](https://github.com/killroyboy/ambient2pwsweather/pull/new/master)! \ No newline at end of file diff --git a/index.js b/index.js index 1526291..630eaa8 100644 --- a/index.js +++ b/index.js @@ -33,21 +33,26 @@ if (!appKey || !apiKey || !pwsStation || !pwsPassword) { process.exit(); } +// instantiate the API const api = new AmbientAPI({ apiKey : apiKey, applicationKey : appKey }); -logger.debug('Connecting to AmbientWeather.net...'); -api.connect(); -api.on('connect', () => logger.debug('Connected to Ambient Weather Realtime API')); +// On connect, we subscribe (this will also re-subscribe when the connection fails and reconnects) +api.on('connect', () => { + logger.debug('Connected to Ambient Weather Realtime API') + api.subscribe(apiKey); +}); + api.on('subscribed', data => { logger.debug('Subscribed to device:', data.devices[0].info.name); + logger.debug(data.devices[0].lastData.date + ' - ' + data.devices[0].info.name + ' current outdoor temperature is: ' + data.devices[0].lastData.tempf + '°F'); }); -var params = {}, url = ''; -// http://www.pwsweather.com/pwsupdate/pwsupdate.php?ID=STATIONID&PASSWORD=password&dateutc=2000-12-01+15%3A20%3A01&winddir=225&windspeedmph=0.0&windgustmph=0.0&tempf=34.88&rainin=0.06&dailyrainin=0.06&monthrainin=1.02&yearrainin=18.26&baromin=29.49&dewptf=30.16&humidity=83&weather=OVC&solarradiation=183&UV=5.28&softwaretype=Examplever1.1&action=updateraw +var params = {}; +// On data, package it up for PWSweather.com and send it over api.on('data', data => { logger.debug(data.date + ' - ' + data.device.info.name + ' current outdoor temperature is: ' + data.tempf + '°F'); @@ -82,13 +87,15 @@ api.on('data', data => { got(config.pws_base_url, {query: params}).then(response => { if (response.statusCode === 200) { logger.debug('Success', response.statusMessage); - // logger.debug('Body', response.body); } else { - logger.debug('Failed', response.statusMessage); + logger.error('Failed', response.statusMessage); } }).catch(reason => { - logger.error('pwsweather failed', reason); + logger.error('PWSweather request failed', reason); }); }); -api.subscribe(apiKey); + +// Let's start the connection +logger.debug('Connecting to AmbientWeather.net...'); +api.connect(); diff --git a/package.json b/package.json index 3a01034..60f870e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ambient2pwsweather", - "version": "0.0.2", + "version": "0.0.3", "description": "Pull weather data from AmbientWeather.net and push to PWSWeather", "main": "index.js", "scripts": {