if (clicks >= 3) { socket_bri=null; var socket_bri = new TCPSocket(false); socket_bri.myCounter = ++currCounterValue; System.print("counter: " +socket_bri.myCounter); brightness=parseInt(brightness)+5*clicks<=255?parseInt(brightness)+5*clicks:255; var JSON_commande='{"bri":'+brightness+'}'; socket_bri.connect('192.168.0.158', 80, 500);
function setBright(sock,commands) { if (sock.connected) socket_bri.write('PUT /api/newdeveloper/groups/all/action HTTP/1.1\r\nConnection: close\r\nContent-Length: '+commands.length+'\r\n\r\n'+commands); System.print("counter_f: " +socket_bri.myCounter);
} socket_bri.onConnect = function() { setBright(this,JSON_commande); if (this.connected) { try{this.close()}catch(e){} } if (socket_bri === this) { // if what is happening is what I believe, this line will rarely be executed. System.print() will confirm. System.print("It is happening"); System.print(socket_bri.myCounter); socket_bri = null; }