How to use the tuyapi/lib/message-parser.encode function in tuyapi

To help you get started, we’ve selected a few tuyapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TheAgentK / tuya-mqtt / tuyaapi-extended.js View on Github external
debug('Payload:', payload);

    // Encrypt data
    const data = this.device.cipher.encrypt({
        data: JSON.stringify(payload)
    });

    // Create MD5 signature
    const md5 = this.device.cipher.md5('data=' + data +
        '||lpv=' + this.device.version +
        '||' + this.device.key);

    // Create byte buffer from hex data
    const thisData = Buffer.from(this.device.version + md5 + data);
    const buffer = Parser.encode({
        data: thisData,
        commandByte: '07'
    });

    // Send request to change status
    return new Promise((resolve, reject) => {
        this._send(this.device.ip, buffer).then(() => {
            resolve(true);
        }).catch(err => {
            reject(err);
        });
    });
};

tuyapi

An easy-to-use API for devices that use Tuya's cloud services

MIT
Latest version published 2 years ago

Package Health Score

66 / 100
Full package analysis