Skip to content

Commit

Permalink
Merge branch 'release/0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
killroyboy committed May 20, 2018
2 parents d9c8144 + 2220355 commit a527240
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 11 deletions.
67 changes: 66 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)!
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit a527240

Please sign in to comment.