{"action":"created","issue":{"url":"https://api.github.com/repos/codetheweb/tuyapi/issues/33","repository_url":"https://api.github.com/repos/codetheweb/tuyapi","labels_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/33/comments","events_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/33/events","html_url":"https://github.com/codetheweb/tuyapi/pull/33","id":315658176,"number":33,"title":"Improve packet parsing and avoid stalling","user":{"login":"tjfontaine","id":146447,"avatar_url":"https://avatars3.githubusercontent.com/u/146447?v=4","gravatar_id":"","url":"https://api.github.com/users/tjfontaine","html_url":"https://github.com/tjfontaine","followers_url":"https://api.github.com/users/tjfontaine/followers","following_url":"https://api.github.com/users/tjfontaine/following{/other_user}","gists_url":"https://api.github.com/users/tjfontaine/gists{/gist_id}","starred_url":"https://api.github.com/users/tjfontaine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tjfontaine/subscriptions","organizations_url":"https://api.github.com/users/tjfontaine/orgs","repos_url":"https://api.github.com/users/tjfontaine/repos","events_url":"https://api.github.com/users/tjfontaine/events{/privacy}","received_events_url":"https://api.github.com/users/tjfontaine/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2018-04-18T22:03:22Z","updated_at":"2018-04-21T20:54:38Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/codetheweb/tuyapi/pulls/33","html_url":"https://github.com/codetheweb/tuyapi/pull/33","diff_url":"https://github.com/codetheweb/tuyapi/pull/33.diff","patch_url":"https://github.com/codetheweb/tuyapi/pull/33.patch"},"body":"First commit: I was occasionally hitting an infinite loop in the JSON parsing (re #18),  I didn't spend time trying to debug that logic, instead I simplified the logic to merely strip off the prefix and suffix and attempt to JSON parse the remainder. Ideally we'd be looking for a field that indicates the payload size, which seems like what the 12th byte is, and it appears to scale with the payload but not exactly.\r\n\r\nSecond commit: while I have no evidence of this happening, it's certainly possible though that messages may be split over multiple `data` events, so I've changed the response handling logic to concatenate messages until there's a buffer that starts with the prefix and ends with the suffix.\r\n\r\nWhat's still missing however, is the notion that there may be multiple messages in the stream, which neither `_extractJSON` or the parsing logic in `_send` are prepared to handle.\r\n\r\nThird commit: Add a way to timeout waiting for a response from a device. In the event we have missed a message, it's possible for the state machine to stall (well there's no explicit state machine here, yet) so you'll end up with a potential socket leak, and unresolved promises."},"comment":{"url":"https://api.github.com/repos/codetheweb/tuyapi/issues/comments/383329263","html_url":"https://github.com/codetheweb/tuyapi/pull/33#issuecomment-383329263","issue_url":"https://api.github.com/repos/codetheweb/tuyapi/issues/33","id":383329263,"user":{"login":"codetheweb","id":7410405,"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-04-21T20:54:38Z","updated_at":"2018-04-21T20:54:38Z","author_association":"OWNER","body":"@BillSobel ok.  From your current understanding, is there a way to set WiFi parameters on a device and generate/set a valid localKey without ever touching the cloud API?  Ideally there would be an easy way for users to get this working besides capturing packets or getting cloud API credentials. "}}
{"actor":{"display_login":"codetheweb"}}