Last active
June 9, 2020 00:54
-
-
Save bshep/0f900eabe699d141bd4a33d60907037f to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const ScreenLogic = require('../index'); | |
// use this to find and connect to units local to the network this is running on | |
var finder = new ScreenLogic.FindUnits(); | |
finder.on('serverFound', function(server) { | |
finder.close(); | |
connect(new ScreenLogic.UnitConnection(server)); | |
}); | |
finder.search(); | |
// use this if you want to use a direct connection to a known unit | |
// connect(new ScreenLogic.UnitConnection(80, '10.0.0.85')); | |
// use this to remote connect to a system by name (going through the Pentair servers) | |
// const systemName = 'Pentair: xx-xx-xx'; | |
// const password = '1234'; | |
// | |
// var remote = new ScreenLogic.RemoteLogin(systemName); | |
// remote.on('gatewayFound', function(unit) { | |
// remote.close(); | |
// if (unit && unit.gatewayFound) { | |
// console.log('unit ' + remote.systemName + ' found at ' + unit.ipAddr + ':' + unit.port); | |
// connect(new ScreenLogic.UnitConnection(unit.port, unit.ipAddr, password)); | |
// } else { | |
// console.log('no unit found by that name'); | |
// } | |
// }); | |
// | |
// remote.connect(); | |
// generic connection method used by all above examples | |
function connect(client) { | |
client.on('loggedIn', function() { | |
this.getVersion(); | |
}).on('version', function(version) { | |
this.getPoolStatus(); | |
console.log(' version=' + version.version); | |
}).on('poolStatus', function(status) { | |
// this.getChemicalData() | |
this.getControllerConfig(); | |
console.log(' pool ok=' + status.ok); | |
console.log(' spa active=' + status.isSpaActive()); | |
console.log(' pool active=' + status.isPoolActive()); | |
}).on('controllerConfig', function(config) { | |
this.controllerConfig = config; | |
this.getEquipmentConfiguration(); | |
this.getPumpStatus(0); | |
// console.log(' controller is in celsius=', config); | |
}).on('equipmentConfiguration', function(config) { | |
console.log("--------- EQUIPMENT CONFIG ---------"); | |
// console.log(config); | |
for (var i = 0; i < this.controllerConfig.bodyArray.length; i++) { | |
let deviceId = this.controllerConfig.bodyArray[i].deviceId; | |
let circuitName = this.controllerConfig.bodyArray[i].name; | |
console.log('pump 1 ' + circuitName + ' rpm= ' + config.getCircuitRPMs(0, deviceId)); | |
} | |
}).on('getPumpStatus', function(status) { | |
console.log("--------- PUMP STATUS ---------"); | |
// console.log('pump status', status); | |
console.log('pump RPMs = ' + status.pumpRPMs); | |
console.log('pump GPMs = ' + status.pumpGPMs); | |
console.log('pump Watts = ' + status.pumpWatts); | |
for (var i = 0; i < status.pumpSetting.length; i++) { | |
var circuitInfo = this.controllerConfig.getCircuitInfoFromDeviceId(status.pumpSetting[i].circuitId); | |
var deviceId, circuitName; | |
if (status.pumpSetting[i].circuitId != 132 && status.pumpSetting[i].circuitId != 0) { | |
deviceId = circuitInfo.deviceId | |
circuitName = circuitInfo.name; | |
} else if (status.pumpSetting[i].circuitId === 132) { | |
circuitName = "Freeze Mode"; | |
} else if (status.pumpSetting[i].circuitId === 0) { | |
circuitName = "Unassigned"; | |
} | |
console.log('pump 1 ' + circuitName + ' SetPoint= ' + status.pumpSetting[i].pumpSetPoint + ' isRPMs = ' + status.pumpSetting[i].isRPMs); | |
} | |
client.close(); | |
}).on('loginFailed', function() { | |
console.log(' unable to login (wrong password?)'); | |
client.close(); | |
}).on('badParameter', function() { | |
console.log(' badParameter '); | |
client.close(); | |
}); | |
client.connect(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment