Haiku Socket Communication Response

snx

Member
I've been experimenting with HH sending commands to an Autelis pool controller and while sending works, I can't seem to script the controllers response.  I'm using the following code for testing:

function onButtonActivate(button) {
if(button.name == 'Y-LIGHT') {
var ds = dateStamp();
var socket = helper.openSocket(controller, '192.168.50.18', 6000);
helper.logToExternalFile('Pool.log', ds + " - " + "Button Pushed: " + button.name + '\r\n');
socket.write('#AUX2\r');
function onSocketBytesAvailable(socket) {
var res = socket.read();
helper.logToExteranlFile('Pool.log', ds + " - " + "AUX2 Triggered: " + res + '\r\n');
socket.close();
}
}
}  
 
This example works (the AUX2 relay is toggled) but the response isn't captured. 
 
Thanks
 
 
 
Just a quick followup-  how would I structure this so an action could be taken given the controllers response?  In other words, a command is sent, the controller responds "PUMP=1", HH sets a flag, etc.  This particular controller is capable of sending unsolicited responses as equipment comes on/off, temp changes (very much like Jandy's serial interface) assuming I keep the socket open.  I may just want to test the status first and then take an action though as I've seen (and other have reported) lockups after keeping a connection open.
 
Thanks again. 
 
Back
Top