{"action":"created","issue":{"url":"https://api.github.com/repos/codetheweb/tuyapi/issues/103","repository_url":"https://api.github.com/repos/codetheweb/tuyapi","labels_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/103/labels{/name}","comments_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/103/comments","events_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/103/events","html_url":"https://github.com/codetheweb/tuyapi/issues/103","id":377081539,"node_id":"MDU6SXNzdWUzNzcwODE1Mzk=","number":103,"title":"Connected to device, but getting garbled data","user":{"login":"scognito","id":466004,"node_id":"MDQ6VXNlcjQ2NjAwNA==","avatar_url":"https://avatars0.githubusercontent.com/u/466004?v=4","gravatar_id":"","url":"https://api.github.com/users/scognito","html_url":"https://github.com/scognito","followers_url":"https://api.github.com/users/scognito/followers","following_url":"https://api.github.com/users/scognito/following{/other_user}","gists_url":"https://api.github.com/users/scognito/gists{/gist_id}","starred_url":"https://api.github.com/users/scognito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scognito/subscriptions","organizations_url":"https://api.github.com/users/scognito/orgs","repos_url":"https://api.github.com/users/scognito/repos","events_url":"https://api.github.com/users/scognito/events{/privacy}","received_events_url":"https://api.github.com/users/scognito/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2018-11-03T18:37:18Z","updated_at":"2018-12-18T17:51:09Z","closed_at":null,"author_association":"NONE","body":"I'm using a no brand wifi smart switch bought on Amazon ([this](https://www.amazon.it/gp/product/B07CVC3J8G/ref=oh_aui_detailpage_o08_s00?ie=UTF8&psc=1))\r\nThe switch works, it was connected to the Tuya network, and I got the key and device id using [this tutorial](https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md).\r\nI can telnet to the device on port 6668, so I'm assuming this library should work.\r\n\r\nI'm running a simple test:\r\nconst TuyaDevice = require('tuyapi');\r\n```\r\n\r\nconst device = new TuyaDevice({\r\n  id: 'myid',\r\n  key: 'mykey',\r\n  ip: '192.168.0.142',\r\n  persistentConnection: true});\r\n\r\ndevice.on('connected',() => {\r\n  console.log('Connected to device.');\r\n});\r\n\r\ndevice.on('disconnected',() => {\r\n  console.log('Disconnected from device.');\r\n});\r\n\r\ndevice.on('data', data => {\r\n  console.log('Data from device:', data);\r\n\r\n  const status = data.dps['1'];\r\n\r\n  console.log('Current status:', status);\r\n\r\n  device.set({set: !status}).then(result => {\r\n    console.log('Result of setting status:', result);\r\n  });\r\n});\r\n\r\ndevice.on('error',(err) => {\r\n  console.log('Error: ' + err);\r\n});\r\n\r\ndevice.connect();\r\n\r\n// Disconnect after 10 seconds\r\nsetTimeout(() => { device.disconnect(); }, 10000);\r\n```\r\n\r\nBut the output I get is this:\r\n```\r\nC:\\Users\\scognito\\dev\\nodejs\\tuya>node app.js\r\nConnected to device.\r\nData from device: Î³øSÌÄwÚÌuÛ(ãê(µùLÂe\u000E}ÙàßÅÀ\r\nC:\\Users\\scognito\\dev\\nodejs\\tuya\\app.js:20\r\n  const status = data.dps['1'];\r\n                         ^\r\n\r\nTypeError: Cannot read property '1' of undefined\r\n    at TuyaDevice.device.on.data (C:\\Users\\scognito\\dev\\nodejs\\tuya\\app.js:20:26)\r\n    at TuyaDevice.emit (events.js:182:13)\r\n    at Socket.client.on.data (C:\\Users\\scognito\\dev\\nodejs\\tuya\\node_modules\\tuyapi\\index.js:522:16)\r\n    at Socket.emit (events.js:182:13)\r\n    at addChunk (_stream_readable.js:283:12)\r\n    at readableAddChunk (_stream_readable.js:264:11)\r\n    at Socket.Readable.push (_stream_readable.js:219:10)\r\n    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)\r\n\r\n```\r\nAm I missing something?\r\n\r\nThank you"},"comment":{"url":"https://api.github.com/repos/codetheweb/tuyapi/issues/comments/448309709","html_url":"https://github.com/codetheweb/tuyapi/issues/103#issuecomment-448309709","issue_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/103","id":448309709,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODMwOTcwOQ==","user":{"login":"codetheweb","id":7410405,"node_id":"MDQ6VXNlcjc0MTA0MDU=","avatar_url":"https://avatars2.githubusercontent.com/u/7410405?v=4","gravatar_id":"","url":"https://api.github.com/users/codetheweb","html_url":"https://github.com/codetheweb","followers_url":"https://api.github.com/users/codetheweb/followers","following_url":"https://api.github.com/users/codetheweb/following{/other_user}","gists_url":"https://api.github.com/users/codetheweb/gists{/gist_id}","starred_url":"https://api.github.com/users/codetheweb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codetheweb/subscriptions","organizations_url":"https://api.github.com/users/codetheweb/orgs","repos_url":"https://api.github.com/users/codetheweb/repos","events_url":"https://api.github.com/users/codetheweb/events{/privacy}","received_events_url":"https://api.github.com/users/codetheweb/received_events","type":"User","site_admin":false},"created_at":"2018-12-18T17:51:09Z","updated_at":"2018-12-18T17:51:09Z","author_association":"OWNER","body":"@gunish what's the output when you run your script with `DEBUG=* node app.js`?"}}
{"actor":{"display_login":"codetheweb"}}