Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static IP #7

Merged
merged 5 commits into from
Mar 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@ to control your Harmony Hub, so your control is just a simple HTTP request away.

script/bootstrap

## Settings

Harmony API can discover your hub automatically. You can optionally provide an
IP address for your hub and avoid the discovery process. Add a line to your
`config.json` file to provide the IP address.

```json
{
"hub_ip": "192.168.1.106"
}
```

## Running It
Get up and running immediatly with `script/server`.
Get up and running immediately with `script/server`.

Harmony API will run on port `8282` by default. Use the `PORT` environment
variable to use your own port.
Expand Down
41 changes: 23 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,34 @@ discover.on('online', function(hubInfo) {
console.log('Stopping discovery.')
discover.stop()

harmony(hubInfo.ip).then(function(harmonyClient) {
console.log('Harmony client created.')

harmonyHubClient = harmonyClient

// update the list of activities
updateActivities()
// then do it on the set interval
clearInterval(harmonyActivityUpdateTimer)
harmonyActivityUpdateTimer = setInterval(function(){ updateActivities() }, harmonyActivityUpdateInterval)

// update the list of activities on the set interval
clearInterval(harmonyStateUpdateTimer)
harmonyStateUpdateTimer = setInterval(function(){ updateState() }, harmonyStateUpdateInterval)
})
harmony(hubInfo.ip).then(startProcessing)
}

})

if (config['hub_ip']) {
// Connect to hub:
console.log('Connecting to Harmony hub at ' + config['hub_ip'])
harmony(config['hub_ip']).then(startProcessing)
}else{
// Look for hubs:
console.log('Starting discovery.')
discover.start()
}

function startProcessing(harmonyClient){
harmonyHubClient = harmonyClient

// Look for hubs:
console.log('Starting discovery.')
discover.start()
// update the list of activities
updateActivities()
// then do it on the set interval
clearInterval(harmonyActivityUpdateTimer)
harmonyActivityUpdateTimer = setInterval(function(){ updateActivities() }, harmonyActivityUpdateInterval)

// update the list of activities on the set interval
clearInterval(harmonyStateUpdateTimer)
harmonyStateUpdateTimer = setInterval(function(){ updateState() }, harmonyStateUpdateInterval)
}

function updateActivities(){
if (!harmonyHubClient) { return }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harmony-api",
"version": "0.4.1",
"version": "0.5.0",
"description": "A simple server providing a RESTful service for controlling a Harmony Hub.",
"scripts": {
"start": "node app.js"
Expand Down