codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.06k stars 339 forks source link

Tuyapi getter functions work, but setters time out #47

Closed mockballed closed 6 years ago

mockballed commented 6 years ago

I had both getters and setters working before, but now only the getter functions work. I can still control the smart bulb using the android app.

If I run this test script

const TuyaDevice = require( 'tuyapi' );

let tuya = new TuyaDevice({
    id: 'abcdefghij1234567890',
    key: 'abcdef1234567890',
    ip: '192.168.1.120' });

tuya.get().then( status => {
    console.log( 'Status:', status );

    tuya.get( { schema: true } ).then( schema => {
        console.log( 'Schema:', schema );

        tuya.set( { dps: 2, set: 128 } ).then( status => {
            console.log( 'StatSet:', status );
        }).catch( err => { console.log( 'err:', err ) } );
    });
});

It prints:

Status: true Schema: { devId: 'abcdefghij1234567890', dps: { '1': true, '2': 140, '3': 0 } } err: Error: Timeout waiting for response at Timeout._sendTimeout.setTimeout [as _onTimeout] (C:\Users\abc\node_modules\tuyapi\index.js:301:16) at ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5)

I've made sure the android app is not connected to the bulb when running the scripts. I'm rather puzzled. Any ideas what could be wrong?

mockballed commented 6 years ago

I got it working again. It'd seem that the LocalKey changed and that you don't need it for getter functions?

codetheweb commented 6 years ago

@s0ne correct. The localKey isn't needed to get properties, but is needed to set properties.

It changes every time you re-add your device to an app.