Created
September 6, 2016 14:29
-
-
Save jamesbulpin/8ee829cc918a58a017ffeff68b6397e5 to your computer and use it in GitHub Desktop.
Simple LightwaveRF Octoblu connector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var meshblu = require('meshblu'); | |
var meshbluJSON = require("./meshblu.json"); | |
var LightwaveRF = require("lightwaverf"); | |
// Specifies how you want your message payload to be passed | |
// from Octoblu to your device | |
var MESSAGE_SCHEMA = { | |
type: 'object', | |
properties: { | |
roomNumber: { | |
type: 'string', | |
required: true | |
}, | |
deviceNumber: { | |
type: 'string', | |
required: true | |
}, | |
action: { | |
type: 'string', | |
"enum": ['on', 'off', 'dim' ], | |
required: true | |
}, | |
dimValue: { | |
type: 'number', | |
required: false | |
} | |
} | |
}; | |
var OPTIONS_SCHEMA = { | |
type: 'object', | |
properties: { | |
ipAddress: { | |
type: 'string', | |
required: true | |
} | |
} | |
}; | |
// Not specifying a UUID/Token auto-registers a new device | |
var conn = meshblu.createConnection({ | |
"uuid": meshbluJSON.uuid, | |
"token": meshbluJSON.token, | |
"server": "meshblu.octoblu.com", | |
"port": 80 | |
}); | |
conn.on('notReady', function(data){ | |
console.log('UUID FAILED AUTHENTICATION!'); | |
console.log(data); | |
}); | |
conn.on('ready', function(data){ | |
console.log('UUID AUTHENTICATED!'); | |
console.log(data); | |
conn.update({ | |
"uuid": meshbluJSON.uuid, | |
"token": meshbluJSON.token, | |
"messageSchema": MESSAGE_SCHEMA, | |
"optionsSchema": OPTIONS_SCHEMA | |
}); | |
conn.on('message', function(data){ | |
console.log('message received'); | |
console.log(data); | |
console.log(conn.options); | |
var lw = new LightwaveRF({ip:"10.52.2.118"}); | |
switch (data.payload.action) { | |
case 'on': | |
lw.turnDeviceOn(data.payload.roomNumber, data.payload.deviceNumber); | |
break; | |
case 'off': | |
lw.turnDeviceOff(data.payload.roomNumber, data.payload.deviceNumber); | |
break; | |
case 'dim': | |
lw.setDeviceDim(data.payload.roomNumber, payload.data.deviceNumber, payload.dimValue) | |
break; | |
} | |
}); | |
}); |
Beware the hard-coded LightwaveRF bridge IP
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note this uses the meshblu 1.x API and needs updating for the current npm 2.x packages. ("npm install meshblu@1.34.1" for now)