ivesdebruycker / maxcube

eQ-3 Max! Cube interface
Other
22 stars 23 forks source link

setTemperature doesnt return #17

Open asantaga opened 7 years ago

asantaga commented 7 years ago

Hey all,

Im a javascript newbie so I might be doing something wrong here but when I call setTemperature it never returns..

My code is

`var MaxCube = require('maxcube'); var myMaxCube = new MaxCube('192.168.0.222', 62910);

myMaxCube.on('connected', function () { console.log('Connected'); myMaxCube.setTemperature('1381f8',21).then( function(success) { if (success) { console.log('Temperature set'); } else { console.log('Error setting Temperature'); } myMaxCube.close(); }); });

myMaxCube.on('closed', function () { console.log('Connection closed'); }); `

Any ideas?

asantaga commented 7 years ago

Just heard back from another github user and apparently waiting a few seconds between connecting and setting the value works fine.. Hopefully we'll have a sample snippet for all to enjoy :-)

sacha2026 commented 7 years ago

Many thanks for the maxcube.js library. Very nice work. I also had the problem of a "hanging" call to setTemperature. A work around is waiting a moment after connected like this:

var MaxCube = require('maxcube'); var myMaxCube = new MaxCube('192.168.18.13', 62910);

myMaxCube.on('connected', function () { console.log('Connected');

setTimeout( () => { console.log('go.....');

 myMaxCube.setTemperature('16a8bf',18).then(function (success) {
     if (success) {
       console.log('Temperature set');
     } else {
       console.log('Error setting temperature');
     }
     myMaxCube.close();
 });

},5000); });

myMaxCube.on('closed', function () { console.log('Connection closed'); });

sacha2026 commented 7 years ago

I see another problem in general. All calls should have a timeout. setTemperature even called at the wrong time or place should return with error or success.