Giter Club home page Giter Club logo

Comments (5)

codetheweb avatar codetheweb commented on September 20, 2024

That's strange, have you tried reproducing it by writing a script that calls TuyAPI directly to see if it's an issue with the CLI tool?

My guess is that it's an issue with your device or our parser, as AFAIK two packets with identical payloads should be byte-for-byte identical.

If the same problem occurs when calling TuyAPI directly, please open an issue here.

from cli.

jezzaaa avatar jezzaaa commented on September 20, 2024

Tried this and it's still doing the same thing. The received data is now smaller for some reason.

Script:

#!/usr/local/bin/node

const TuyAPI = require('tuyapi');

const device = new TuyAPI({
    //ip: '192.168.1.88',
    id: '12084540ecfabc449c45',
    key: '80bbc8a7b2a80dda'
});

(async () => {

  await device.find();

  await device.connect();

  let status = await device.get();

  console.log(`Status: ${status}.`);

  device.disconnect();
})();

Output with "ip" commented out as above (also happens if "ip" set to ""):

$ DEBUG='*' ./get-status.js
  TuyAPI Finding missing IP undefined or ID 572757322cf432269a18 +0ms
  TuyAPI Received UDP message. +4s
  TuyAPI UDP data: +13ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.89',
  TuyAPI      gwId: '572757322cf432269a18',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: '4kheilyfiyazqpda',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +1ms
  TuyAPI Connecting to 192.168.1.89... +29ms
  TuyAPI Socket connected. +16ms
  TuyAPI GET Payload: +2ms
  TuyAPI { gwId: '572757322cf432269a18', devId: '572757322cf432269a18' } +2ms
  TuyAPI Received data: 000055aa000000010000000a000000bc00000000fe69584f50dd7df21f8765abd18425e27a3d78dbf479ce5d3ace084aa1132bc9ba849c8af24ae0237ad75028dd11bd4ed7c56cddf42da77b2db53cdaeacf4ccb8b7a8b09204c5c3eeed78dfc1d1db1a1c90cabb671c5bf556719e56b00102bf34a5a924273ba412e6074022c8476360a4b85daeed87ad730859440a79e512e4c5182d7902e58731f7e8ec11aa54dcd2c1acac006eaa0530c1ddec9c419c9da63223dcfd6b378904d1afac9d5548743b4a9c700340000aa55 +34ms
  TuyAPI Parsed: +2ms
  TuyAPI { payload:
  TuyAPI    { devId: '572757322cf432269a18',
  TuyAPI      dps:
  TuyAPI       { '20': true,
  TuyAPI         '21': 'white',
  TuyAPI         '22': 150,
  TuyAPI         '23': 44,
  TuyAPI         '24': '00180389003c',
  TuyAPI         '25': '04464602007803e803e800000000464602007803e8000a00000000' } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +2ms
  TuyAPI GET Payload: +7ms
  TuyAPI { gwId: '572757322cf432269a18', devId: '572757322cf432269a18' } +1ms
  TuyAPI Received data: 000055aa000000020000000a000000bc00000000fe69584f50dd7df21f8765abd18425e27a3d78dbf479ce5d3ace084aa1132bc9ba849c8af24ae0237ad75028dd11bd4ed7c56cddf42da77b2db53cdaeacf4ccb8b7a8b09204c5c3eeed78dfc1d1db1a1c90cabb671c5bf556719e56b00102bf34a5a924273ba412e6074022c8476360a4b85daeed87ad730859440a79e512e4c5182d7902e58731f7e8ec11aa54dcd2c1acac006eaa0530c1ddec9c419c9da63223dcfd6b378904d1afac9d5548743b4833cec1b0000aa55 +22ms
  TuyAPI Parsed: +2ms
  TuyAPI { payload:
  TuyAPI    { devId: '572757322cf432269a18',
  TuyAPI      dps:
  TuyAPI       { '20': true,
  TuyAPI         '21': 'white',
  TuyAPI         '22': 150,
  TuyAPI         '23': 44,
  TuyAPI         '24': '00180389003c',
  TuyAPI         '25': '04464602007803e803e800000000464602007803e8000a00000000' } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 2 } +1ms
Status: undefined.
  TuyAPI Disconnect +9ms
  TuyAPI Socket closed: 192.168.1.89 +4ms

And with the comment removed from the "ip":

$ DEBUG='*' ./get-status.js
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.1.89... +13ms
  TuyAPI Socket connected. +124ms
  TuyAPI GET Payload: +2ms
  TuyAPI { gwId: '572757322cf432269a18', devId: '572757322cf432269a18' } +1ms
  TuyAPI Pinging 192.168.1.89 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +29ms
  TuyAPI Parsed: +8ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms
  TuyAPI Pong from 192.168.1.89 +3ms
  TuyAPI Pinging 192.168.1.89 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +84ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.1.89 +1ms
  TuyAPI Pinging 192.168.1.89 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +76ms
  TuyAPI Parsed: +16ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms
  TuyAPI Pong from 192.168.1.89 +1ms

from cli.

codetheweb avatar codetheweb commented on September 20, 2024

Sorry, should have looked closer at the initial output; I think I know what the issue is.

It looks like your device uses the v3.3 protocol version. When the IP is omitted, TuyAPI automatically changes the protocol version to v3.3 when it receives a broadcast from the device with the ID, IP, and version.

However, if you specify both the IP and ID without including the protocol version it defaults to v3.1.

TL;DR: try changing the protocol version to v3.3 with the CLI flag --protocol-version 3.3 or the constructor option { ... version: 3.3 ... }. Everything should then work as expected.

from cli.

jezzaaa avatar jezzaaa commented on September 20, 2024

Bingo! Adding --protocol-version 3.3 did the trick. Thankyou very much!

from cli.

codetheweb avatar codetheweb commented on September 20, 2024

Glad it hear it's working.

from cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.