Updated example
Close the finder when we've found a unit. Request and handle each piece of data in sequence instead of requesting it all at once and then closing when the last expected message comes through. This is potentially slightly slower, but much clearer and 'safer'.
This commit is contained in:
19
example.js
19
example.js
@ -2,21 +2,23 @@ const ScreenLogic = require('./index');
|
||||
|
||||
var finder = new ScreenLogic.FindUnits();
|
||||
finder.on('serverFound', function(server) {
|
||||
finder.close();
|
||||
connect(new ScreenLogic.UnitConnection(server));
|
||||
});
|
||||
|
||||
finder.search();
|
||||
|
||||
// use this instead of the above `finder` logic if you want to use a direct connection
|
||||
//connect(new ScreenLogic.UnitConnection(80, '10.0.0.85'));
|
||||
|
||||
function connect(client) {
|
||||
client.on('loggedIn', function() {
|
||||
this.getVersion();
|
||||
}).on('version', function(version) {
|
||||
this.getPoolStatus();
|
||||
this.getChemicalData();
|
||||
this.getSaltCellConfig();
|
||||
this.getControllerConfig();
|
||||
console.log(" version=" + version.version);
|
||||
}).on('poolStatus', function(status) {
|
||||
this.getChemicalData();
|
||||
console.log(" pool ok=" + status.ok);
|
||||
console.log(" air temp=" + status.airTemp);
|
||||
console.log(" salt ppm=" + status.saltPPM);
|
||||
@ -24,18 +26,17 @@ function connect(client) {
|
||||
console.log(" saturation=" + status.saturation);
|
||||
console.log(" spa active=" + status.isSpaActive());
|
||||
console.log(" pool active=" + status.isPoolActive());
|
||||
}).on('controllerConfig', function(config) {
|
||||
console.log(" controller is in celsius=" + config.degC);
|
||||
client.close();
|
||||
finder.close();
|
||||
}).on('chemicalData', function(chemData) {
|
||||
this.getSaltCellConfig();
|
||||
console.log(" calcium=" + chemData.calcium);
|
||||
console.log(" cyanuric acid=" + chemData.cyanuricAcid);
|
||||
console.log(" alkalinity=" + chemData.alkalinity);
|
||||
}).on('saltCellConfig', function(saltCellConfig) {
|
||||
this.getControllerConfig();
|
||||
console.log(" salt cell installed=" + saltCellConfig.installed);
|
||||
}).on('version', function(version) {
|
||||
console.log(" version=" + version.version);
|
||||
}).on('controllerConfig', function(config) {
|
||||
console.log(" controller is in celsius=" + config.degC);
|
||||
client.close();
|
||||
});
|
||||
|
||||
client.connect();
|
||||
|
Reference in New Issue
Block a user