vinodsr / node-red-contrib-tuya-smart-device

a node-red module for managing tuya smart devices
https://flows.nodered.org/node/node-red-contrib-tuya-smart-device
MIT License
47 stars 15 forks source link

4.1.0 issues #64

Closed msillano closed 3 years ago

msillano commented 3 years ago

I found a grave problem testing the ver. 4.1.0, setting the device ON/OFF: the transition OFF => ON is OK, but the transition ON => OFF generates any time a "Unhandled promise " error that requires node-red restart.

Trace case OFF => ON, runs OK

I tested it 'in the project', where it is implemented a 'dynamic timeout'. Don't care about it.

2 Jun 20:36:11 - [info] Node-RED version: v1.2.6
2 Jun 20:36:11 - [info] Node.js  version: v14.15.1
2 Jun 20:36:11 - [info] Windows_NT 10.0.18363 x64 LE
..... omissis
//--------------- note: this info still too many data
2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Recieved the config {"id":"cb0e33e6.f0a6b","type":"tuya-smart-device","z":"173260fb.d021ff","deviceName":"WiFi plug","deviceId":"bf94066e80b*******","deviceKey":"ddfd532e9*******","deviceIp":"","retryTimeout":"100003","findTimeout":"100019","tuyaVersion":"3.1","eventMode":"event-both","x":1180,"y":700,"wires":[["2ec83963.a7d146","3396211c.9a5dee"],["35577170.232cde","572ec9e9.c41048"]],"info":"CUSTOMIZATION\n\n  - duplicate for any new device\n  - set proprties: deviceId (or IP), key, retry timeout (1000 ms), find timeout (5000 ms).","disableAutoStart":false}

2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true
2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Auto start probe on connect...
2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Cleaning up the state
2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Clearing the find timeout handler

// ===============  Wifi Plug is OFF
2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba*******","key":"ddfd532e99*******","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  100019 , retryTimeout:  100003

//  ==============  dynamic findTimeout: every  failed  re-trying, the  find timeout grows (random): min 2s, max 60s
2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1382},"_msgid":"d9e5ec31.7424c"}
2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1382

2 Jun 20:36:26 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:36:27 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:36:27 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1383},"_msgid":"dabd6913.ba3c98"}
2 Jun 20:36:27 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1383

2 Jun 20:36:37 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:36:39 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:36:39 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1509},"_msgid":"54aa03b5.fbba4c"}
2 Jun 20:36:39 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1509

2 Jun 20:36:49 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:36:50 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:36:50 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba060*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1581},"_msgid":"1d396d62.c551a3"}
2 Jun 20:36:50 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1581

2 Jun 20:37:00 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:37:02 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:37:02 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1752},"_msgid":"7b8143d8.cd795c"}
2 Jun 20:37:02 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1752

2 Jun 20:37:12 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:37:14 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:37:14 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba060*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":2150},"_msgid":"daf869b9.51f598"}
2 Jun 20:37:14 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :2150

2 Jun 20:37:24 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:37:26 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:37:26 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":2364},"_msgid":"d75eb566.8364d8"}
2 Jun 20:37:26 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :2364

2 Jun 20:37:36 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 20:37:38 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:37:38 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba060*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":3092},"_msgid":"be7a2d8.50048d"}
2 Jun 20:37:38 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :3092
..... omissis

// =============== WiFi plug ON at 20:44:50 (via power strip)
2 Jun 20:44:50 - [info] [tuya-smart-device:power strip] Data from device  [event:data]: {"devId":"3613666124a*******","dps":{"1":true,"2":true,"3":true,"4":true,"5":true},"t":1622659489}
2 Jun 20:45:06 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 20:45:06 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":67377},"_msgid":"ae11a06a.06fa1"}
2 Jun 20:45:06 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :67377

// ======= connected, so find timeout back to min: 2000
2 Jun 20:45:11 - [info] [tuya-smart-device:WiFi plug] Connected to device! bf94066e80ba0*******i
2 Jun 20:45:11 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":2000},"_msgid":"416b6595.f2823c"}
2 Jun 20:45:11 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :2000
..... omissis

Trace case ON => OFF, fatal error

2 Jun 21:07:40 - [info] Node-RED version: v1.2.6
..... omissis
2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Recieved the config {"id":"cb0e33e6.f0a6b","type":"tuya-smart-device","z":"173260fb.d021ff","deviceName":"WiFi plug","deviceId":"bf94066e80ba0*******","deviceKey":"ddfd532e9*******","deviceIp":"","retryTimeout":"100003","findTimeout":"100019","tuyaVersion":"3.1","eventMode":"event-both","x":1180,"y":700,"wires":[["2ec83963.a7d146","3396211c.9a5dee"],["35577170.232cde","572ec9e9.c41048"]],"info":"CUSTOMIZATION\n\n  - duplicate for any new device\n  - set proprties: deviceId (or IP), key, retry timeout (1000 ms), find timeout (5000 ms).","disableAutoStart":false}
2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true
2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Auto start probe on connect...
2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Cleaning up the state
2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Clearing the find timeout handler
..... omissis
2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba060a04vmxi","key":"ddfd532e9962d0a8","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  100019 , retryTimeout:  100003
2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1380},"_msgid":"f3c13e33.9b875"}
2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1380
..... omissis
2 Jun 21:07:50 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1439},"_msgid":"577b10ae.d6573"}
2 Jun 21:07:50 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1439
2 Jun 21:07:51 - [info] [tuya-smart-device:WiFi plug] Connected to device! bf94066e80ba*******
..... omissis

// =============== WiFi plug OFF at 21:12:13 (via power strip)
2 Jun 21:12:13 - [info] [tuya-smart-device:power strip] Data from device  [event:data]: {"devId":"3613666124a1600db127","dps":{"1":false,"2":false,"3":false,"4":false,"5":false},"t":1622661132}
2 Jun 21:12:23 - [info] [tuya-smart-device:WiFi plug] Disconnected from tuyaDevice.

2 Jun 21:14:03 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0*******","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1630},"_msgid":"4f618be1.8e3f84"}
2 Jun 21:14:03 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1630

(node:16444) UnhandledPromiseRejectionWarning: Error: connection timed out
    at Socket.<anonymous> (d:\node-red\flow-1984\node_modules\tuyapi\index.js:446:18)
    at Object.onceWrapper (events.js:421:28)
    at Socket.emit (events.js:315:20)
    at Socket._onTimeout (net.js:483:8)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:16444) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:16444) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

// ============ WiFi plug:  no re-trying...
// =============== WiFi plug ON at 21:26:09 (via power strip)
2 Jun 21:26:09 - [info] [tuya-smart-device:power strip] Data from device  [event:data]: {"devId":"3613666124a160*******","dps":{"1":true,"2":true,"3":true,"4":true,"5":true},"t":1622661968}
// ======== WiFi plug dead, requires node-red restart

A question about timeouts

What is the mind of retryTimeout? It is used only on data RX?

..... omissis
2 Jun 21:51:22 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba0*******","key":"ddfd532e99*******","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  2000 , retryTimeout:  2000
2 Jun 21:51:22 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
..... omissis
// ===== using: findTimeout :  2000 , retryTimeout:  2000 I get  2s and 10s delays
2 Jun 21:51:32 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 21:51:34 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 21:51:44 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 21:51:46 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 21:51:56 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 21:51:58 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
..... omissis
2 Jun 21:59:04 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba*******","key":"ddfd532e99*******","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  3000 , retryTimeout:  5000
..... omissis
// ===== using: findTimeout :  3000 , retryTimeout:  5000 I get  3s and still 10s delays
2 Jun 21:59:27 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 21:59:30 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 21:59:40 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...
2 Jun 21:59:43 - [info] [tuya-smart-device:WiFi plug] Initiating the find command
2 Jun 21:59:53 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...

So I use only findTimeout to control the connection retry period.

note on COMMAND implementation. The chosen implementation works good, but presents some drawback that reduces the bandwidth:

I found also in output some problems: e.g. the 'CONNECTED' state is repeated several times in vain, I had to add a filter.

Best regards m.s.

vinodsr commented 3 years ago

Two things

  1. Is it happening always for all devices ?
  2. When you get the error, a reconnect message helps in connecting again ?

Thanks for pointing out the timeout issues I will fix it soon.

On Thu, 3 Jun, 2021, 2:06 pm Marco Sillano, @.***> wrote:

I found a grave problem testing the ver. 4.1.0, setting the device ON/OFF: the transition OFF => ON is OK, but the transition ON => OFF generates any time a "Unhandled promise " error that requires node-red restart. Trace case OFF => ON, runs OK

I tested it 'in the project', where it is implemented a 'dynamic timeout'. Don't care about it.

2 Jun 20:36:11 - [info] Node-RED version: v1.2.6 2 Jun 20:36:11 - [info] Node.js version: v14.15.1 2 Jun 20:36:11 - [info] Windows_NT 10.0.18363 x64 LE ..... omissis 2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Recieved the config {"id":"cb0e33e6.f0a6b","type":"tuya-smart-device","z":"173260fb.d021ff","deviceName":"WiFi plug","deviceId":"bf94066e80b","deviceKey":"ddfd532e9","deviceIp":"","retryTimeout":"100003","findTimeout":"100019","tuyaVersion":"3.1","eventMode":"event-both","x":1180,"y":700,"wires":[["2ec83963.a7d146","3396211c.9a5dee"],["35577170.232cde","572ec9e9.c41048"]],"info":"CUSTOMIZATION\n\n - duplicate for any new device\n - set proprties: deviceId (or IP), key, retry timeout (1000 ms), find timeout (5000 ms).","disableAutoStart":false} 2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true 2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Auto start probe on connect... 2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Cleaning up the state 2 Jun 20:36:15 - [info] [tuya-smart-device:WiFi plug] Clearing the find timeout handler

// =============== Wifi Plug is OFF 2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba","key":"ddfd532e99","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout : 100019 , retryTimeout: 100003

// ============== dynamic findTimeout: every failed re-trying, the find timeout grows (random): min 2s, max 60s 2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1382},"_msgid":"d9e5ec31.7424c"} 2 Jun 20:36:16 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1382

2 Jun 20:36:26 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:36:27 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:36:27 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1383},"_msgid":"dabd6913.ba3c98"} 2 Jun 20:36:27 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1383

2 Jun 20:36:37 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:36:39 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:36:39 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1509},"_msgid":"54aa03b5.fbba4c"} 2 Jun 20:36:39 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1509

2 Jun 20:36:49 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:36:50 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:36:50 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba060***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1581},"_msgid":"1d396d62.c551a3"} 2 Jun 20:36:50 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1581

2 Jun 20:37:00 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:37:02 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:37:02 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1752},"_msgid":"7b8143d8.cd795c"} 2 Jun 20:37:02 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1752

2 Jun 20:37:12 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:37:14 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:37:14 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba060***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":2150},"_msgid":"daf869b9.51f598"} 2 Jun 20:37:14 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :2150

2 Jun 20:37:24 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:37:26 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:37:26 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":2364},"_msgid":"d75eb566.8364d8"} 2 Jun 20:37:26 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :2364

2 Jun 20:37:36 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 20:37:38 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:37:38 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba060***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":3092},"_msgid":"be7a2d8.50048d"} 2 Jun 20:37:38 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :3092 ..... omissis

// =============== WiFi plug ON at 20:44:50 (via power strip) 2 Jun 20:44:50 - [info] [tuya-smart-device:power strip] Data from device [event:data]: {"devId":"3613666124a","dps":{"1":true,"2":true,"3":true,"4":true,"5":true},"t":1622659489} 2 Jun 20:45:06 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 20:45:06 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":67377},"_msgid":"ae11a06a.06fa1"} 2 Jun 20:45:06 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :67377

// ======= connected, so find timeout back to min: 2000 2 Jun 20:45:11 - [info] [tuya-smart-device:WiFi plug] Connected to device! bf94066e80ba0i 2 Jun 20:45:11 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":2000},"_msgid":"416b6595.f2823c"} 2 Jun 20:45:11 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :2000 ..... omissis

Trace case ON => OFF, fatal error

2 Jun 21:07:40 - [info] Node-RED version: v1.2.6 ..... omissis 2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Recieved the config {"id":"cb0e33e6.f0a6b","type":"tuya-smart-device","z":"173260fb.d021ff","deviceName":"WiFi plug","deviceId":"bf94066e80ba0","deviceKey":"ddfd532e9","deviceIp":"","retryTimeout":"100003","findTimeout":"100019","tuyaVersion":"3.1","eventMode":"event-both","x":1180,"y":700,"wires":[["2ec83963.a7d146","3396211c.9a5dee"],["35577170.232cde","572ec9e9.c41048"]],"info":"CUSTOMIZATION\n\n - duplicate for any new device\n - set proprties: deviceId (or IP), key, retry timeout (1000 ms), find timeout (5000 ms).","disableAutoStart":false} 2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true 2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Auto start probe on connect... 2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Cleaning up the state 2 Jun 21:07:44 - [info] [tuya-smart-device:WiFi plug] Clearing the find timeout handler ..... omissis 2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba060a04vmxi","key":"ddfd532e9962d0a8","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout : 100019 , retryTimeout: 100003 2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1380},"_msgid":"f3c13e33.9b875"} 2 Jun 21:07:45 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1380 ..... omissis 2 Jun 21:07:50 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1439},"_msgid":"577b10ae.d6573"} 2 Jun 21:07:50 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1439 2 Jun 21:07:51 - [info] [tuya-smart-device:WiFi plug] Connected to device! bf94066e80ba*** ..... omissis

// =============== WiFi plug OFF at 21:12:13 (via power strip) 2 Jun 21:12:13 - [info] [tuya-smart-device:power strip] Data from device [event:data]: {"devId":"3613666124a1600db127","dps":{"1":false,"2":false,"3":false,"4":false,"5":false},"t":1622661132} 2 Jun 21:12:23 - [info] [tuya-smart-device:WiFi plug] Disconnected from tuyaDevice.

2 Jun 21:14:03 - [info] [tuya-smart-device:WiFi plug] Recieved input : {"toDev":"bf94066e80ba0***","payload":{"operation":"CONTROL","action":"SET_FIND_TIMEOUT","value":1630},"_msgid":"4f618be1.8e3f84"} 2 Jun 21:14:03 - [info] [tuya-smart-device:WiFi plug] Setting new find timeout :1630

(node:16444) UnhandledPromiseRejectionWarning: Error: connection timed out at Socket. (d:\node-red\flow-1984\node_modules\tuyapi\index.js:446:18) at Object.onceWrapper (events.js:421:28) at Socket.emit (events.js:315:20) at Socket._onTimeout (net.js:483:8) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7) (Use node --trace-warnings ... to show where the warning was created) (node:16444) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:16444) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

// ============ WiFi plug: no re-trying... // =============== WiFi plug ON at 21:26:09 (via power strip) 2 Jun 21:26:09 - [info] [tuya-smart-device:power strip] Data from device [event:data]: {"devId":"3613666124a1600db127","dps":{"1":true,"2":true,"3":true,"4":true,"5":true},"t":1622661968} // ======== WiFi plug dead, requires node-red restart


A question about timeouts

What is the mind of retryTimeout?

..... omissis 2 Jun 21:51:22 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba060a04vmxi","key":"ddfd532e9962d0a8","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout : 2000 , retryTimeout: 2000 2 Jun 21:51:22 - [info] [tuya-smart-device:WiFi plug] Initiating the find command ..... omissis // ===== using: findTimeout : 2000 , retryTimeout: 2000 I get 2s and 10s delays 2 Jun 21:51:32 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 21:51:34 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 21:51:44 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 21:51:46 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 21:51:56 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 21:51:58 - [info] [tuya-smart-device:WiFi plug] Initiating the find command ..... omissis 2 Jun 21:59:04 - [info] [tuya-smart-device:WiFi plug] Connecting to Tuya with params {"id":"bf94066e80ba060a04vmxi","key":"ddfd532e9962d0a8","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout : 3000 , retryTimeout: 5000 ..... omissis // ===== using: findTimeout : 3000 , retryTimeout: 5000 I get 3s and still 10s delays 2 Jun 21:59:27 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 21:59:30 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 21:59:40 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying... 2 Jun 21:59:43 - [info] [tuya-smart-device:WiFi plug] Initiating the find command 2 Jun 21:59:53 - [info] [tuya-smart-device:WiFi plug] Cannot find the device, re-trying...

So I use only findTimeout.`

Best regards m.s.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/64, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6OAKQKJ5VAAJBBVJ6N3TQ45IZANCNFSM46AJN5IQ .

vinodsr commented 3 years ago

@msillano I had fixed the timeouts and the multiple states emitted errors. Now the state is emitted only when it is changed. hence no duplicates.

You can check the changes in the branch feature/fix-timeouts

I am still looking in to the unhandled exception case.

msillano commented 3 years ago

Ok, good job. After more test, in compact form dashboard:

// ----- regular start, device Wifi plug ON, OK
3/6/2021, 18:02:22node: STATE "DISCONNECTED"
3/6/2021, 18:02:22node: STATE "DISCONNECTED"
3/6/2021, 18:02:23node: STATE "CONNECTING"
3/6/2021, 18:02:23node: STATE "CONNECTING"
3/6/2021, 18:02:23node: STATE "CONNECTED"
3/6/2021, 18:02:24node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2702 }
3/6/2021, 18:02:24node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 3261 }
3/6/2021, 18:02:25node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2000 }
// ------------  now set OFF (via power strip)
3/6/2021, 18:09:27 power strip : { dps: "2", set: false }
3/6/2021, 18:09:35node: STATE "DISCONNECTED"
3/6/2021, 18:09:40node: STATE"CONNECTING"
3/6/2021, 18:09:40node: { operation: "CONTROL", action: "SET_F"CONNECTING"IND_TIMEOUT", value: 2502 }
//  -----------  note: after the "CONNECTING" non more re-try !
// ------------  now set ON device (via power strip) don't change the drive block
3/6/2021, 18:14:21 power strip : { dps: "2", set: true }
// ------------  no retry, also if auto-connect is true
// ------------  but If I send a COMMAND CONNECT: retry OK
3/6/2021, 18:16:44node: { operation: "CONTROL", action: "CONNECT" }
3/6/2021, 18:16:44node: "DISCONNECTED"
3/6/2021, 18:16:45node: "CONNECTING"
3/6/2021, 18:16:45node: "CONNECTING"
3/6/2021, 18:16:45node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2535 }
3/6/2021, 18:16:45node: "CONNECTED"
3/6/2021, 18:16:45node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 3403 }
3/6/2021, 18:16:45node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2000 }

// ------- now restart flows, and device OFF
3/6/2021, 18:19:56node: "DISCONNECTED"
3/6/2021, 18:19:57node: "CONNECTING"
3/6/2021, 18:19:58node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2500 }
3/6/2021, 18:20:07node: "ERROR"  //  ???
3/6/2021, 18:20:10node: "CONNECTING"  (time + 13 (10+ 2.5))
3/6/2021, 18:20:10node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2536 }
3/6/2021, 18:20:20node: "ERROR"
3/6/2021, 18:20:22node: "CONNECTING"  (time + 12 (10+2.5))
3/6/2021, 18:20:22node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 3331 }
3/6/2021, 18:20:32node: "ERROR"
3/6/2021, 18:20:36node: "CONNECTING"  (time + 14 (10+3.3))
3/6/2021, 18:20:36node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 3907 }
3/6/2021, 18:20:46node: "ERROR"
.... omissis
3/6/2021, 18:24:20node: "CONNECTING"
3/6/2021, 18:24:20node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 25996 }
3/6/2021, 18:24:30node: "ERROR"
3/6/2021, 18:24:56node: "CONNECTING" (time + 36 (10+25.9)) OK
3/6/2021, 18:24:56node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 30393 }
// --------- also with "ERROR" (??) the findTimeout works, OK
..... omissis
// ------   device Wifi plug ON (via power strip), OK
3/6/2021, 18:30:28node: power strip : { dps: "2", set: true }
3/6/2021, 18:31:29node: "CONNECTING"
3/6/2021, 18:31:30node: "CONNECTING"
3/6/2021, 18:31:31node: "CONNECTED"
3/6/2021, 18:31:31node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2000 } OK
// ------- test COMMANDS CONNECT/DISCONNECT
3/6/2021, 18:39:05node: { operation: "CONTROL", action: "DISCONNECT" }
3/6/2021, 18:39:05node: "DISCONNECTED"
3/6/2021, 18:39:05node: "DISCONNECTED"
... nothing
3/6/2021, 18:39:24node: { operation: "CONTROL", action: "CONNECT" }
3/6/2021, 18:39:24node: "DISCONNECTED"
3/6/2021, 18:39:25node: "CONNECTING"
3/6/2021, 18:39:25node: "CONNECTING"
3/6/2021, 18:39:25node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2638 }
3/6/2021, 18:39:25node: "CONNECTED"
3/6/2021, 18:39:25node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2728 }
3/6/2021, 18:39:26node: { operation: "CONTROL", action: "SET_FIND_TIMEOUT", value: 2000 }
// -------- works as expected, OK

It is like an 'auto-connect' problem: if device OFF => ON the 'auto-connect' don't starts, but the COMMAND CONNECT does. The errors are a problem apart: the UnhandledPromiseRejectionWarning (systematic when the device goes ON => OFF) and the msg state 'ERROR'. (??)

PS: 'ERROR' is OK, is the catch of 'tuyAPY Error: find() timed out.' . It is sent at any retry... maybe superfluous? It is normal in a retry loop waiting for a connection to have it... it is a signal, not an ERROR. But it is not a problem, just ignore it.

I'm using the 4.1 with all devices, (I updated the project) but the tests are done with the 'wifi plug' because it is easy to turn it ON/OFF using a second device 'power strip' so I have records of times.

Best regards m.s.

vinodsr commented 3 years ago

In my case if i turn off the light , i will get a connection timeout and then it starts to retry.

  TuyAPI Error event from socket. 192.168.1.71 Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read'
} +9s
3 Jun 22:29:08 - [info] [tuya-smart-device:Tv Light] Retrying reconnect after 1001 milliseconds
  TuyAPI Socket closed: 192.168.1.71 +3ms
3 Jun 22:29:08 - [info] [tuya-smart-device:Tv Light] Disconnected from tuyaDevice.
3 Jun 22:29:08 - [info] [tuya-smart-device:Tv Light] Retrying reconnect after 1001 milliseconds
  TuyAPI Connecting to 192.168.1.71... +1s

Regarding the UnhandledPromiseRejectionWarning, the tuya API is not giving error event in such cases. Only when the error is emitted, the node tries to reconnect.

msillano commented 3 years ago

You cannot overload tuyaAPI to catch also this event/promise?

vinodsr commented 3 years ago

Nope .

as per your log the error occurred at line 446

(node:16444) UnhandledPromiseRejectionWarning: Error: connection timed out
    at Socket.<anonymous> (d:\node-red\flow-1984\node_modules\tuyapi\index.js:446:18)
    at Object.onceWrapper (events.js:421:28)
    at Socket.emit (events.js:315:20)

which is


          // Periodically send heartbeat ping
          this.pingpongTimeout = setInterval(async () => {
            await this._sendPing();
          }, this._pingPongPeriod * 1000);

so error is thrown from this await, but sadly it is there inside a setInterval, hence i cannot handle it. TuyaAPI has to handle it.

vinodsr commented 3 years ago

But in my case after some time 10 secs or so, Tuya sends a error event.

vinodsr commented 3 years ago

In your case can you please confirm after the error is shown in the log, what is the status in the dashboard ? Is it showing still connected ?

msillano commented 3 years ago

Open an Issue on tuyapi ISSUE#477. About in the dashboard ? Not, after error thr device is dead. see @3/6/2021, 18:09:40

vinodsr commented 3 years ago

The status shown in the node red editor (web) for the device node (connected, disconnected ,error)

On Thu, 3 Jun, 2021, 11:14 pm Marco Sillano, @.***> wrote:

Open an Issue on tuyapi ISSUE#477 https://github.com/codetheweb/tuyapi/issues/477#issue-910713113. About in the dashboard ? Not, after error thr device is dead. see @3/6/2021, 18:09:40

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/64#issuecomment-854059617, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6ODUXGJNHXTV74UMCILTQ65PRANCNFSM46AJN5IQ .

msillano commented 3 years ago

I confirm, the 'more test, in compact form' is from dashboard.

This is a trace of a try with a different device 'switch module#1'.

Exactly same behavior seen before:

... omissis
3 Jun 19:55:25 - [info] [tuya-smart-device:switch module#1] Recieved the config {"id":"3db1955********","type":"tuya-smart-device","z":"173260fb.d021ff","deviceName":"switch module#1","disableAutoStart":false,"deviceId":"bfa355aa196********","deviceKey":"10ad2960f******","deviceIp":"","retryTimeout":"100193","findTimeout":"100207","tuyaVersion":"3.1","eventMode":"event-both","x":1270,"y":1660,"wires":[["2ec83963.a7d146"],["668d3a7b.f2a8e4","2523b8e2.0abbf8"]],"info":"CUSTOMIZATION\n\n  - duplicate for any new device\n  - set proprties: deviceId (or IP), key, retry timeout (1000 ms), find timeout (5000 ms)."}
3 Jun 19:55:25 - [info] [tuya-smart-device:switch module#1] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true
3 Jun 19:55:25 - [info] [tuya-smart-device:switch module#1] Auto start probe on connect...
3 Jun 19:55:25 - [info] [tuya-smart-device:switch module#1] Cleaning up the state
3 Jun 19:55:25 - [info] [tuya-smart-device:switch module#1] Clearing the find timeout handler
... omissis
3 Jun 19:55:26 - [info] [tuya-smart-device:switch module#1] Connecting to Tuya with params {"id":"bfa355aa196********","key":"10ad2960f********","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  100207 , retryTimeout:  100193
3 Jun 19:55:26 - [info] [tuya-smart-device:switch module#1] Initiating the find command
... omissis
3 Jun 19:55:30 - [info] [tuya-smart-device:switch module#1] Connected to device! bfa355aa196********
... omissis
// --------------------- at 19:56, Power OFF to switch
3 Jun 19:56:32 - [info] [tuya-smart-device:switch module#1] Disconnected from tuyaDevice.
(node:13800) UnhandledPromiseRejectionWarning: Error: connection timed out
    at Socket.<anonymous> (d:\node-red\flow-1984\node_modules\tuyapi\index.js:446:18)
    at Object.onceWrapper (events.js:421:28)
    at Socket.emit (events.js:315:20)
    at Socket._onTimeout (net.js:483:8)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:13800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
... omissis
// ------------  the device is dead
msillano commented 3 years ago

more tests

The feature/fix-timeouts is with many problems:

1) THE COMMANDs looks don't work: The test was done using your example flow, a little modified Start: device ON, dashboard after a 'restart flow' :

!! missed the initial STATE (CONNECTED|DISCONNECTED)

5/6/2021, 11:26:26node: Device INPUT
msg.payload : Object { dps: 1, set: true }
5/6/2021, 11:26:26node: Device Data
msg.payload.data.dps : object 1: true
------ OK  swtch ON

5/6/2021, 11:28:07node: Device INPUT
msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" }
!! No STATE change

5/6/2021, 11:28:14node: Device INPUT
msg.payload : Object { dps: 1, set: false }
5/6/2021, 11:28:14node: Device Data
msg.payload.data.dps : Object 1: false
!!  switch change OFF

5/6/2021, 11:28:23node: Device INPUT
msg.payload : Object { operation: "CONTROL", action: "RECONNECT" }
!! No STATE change

5/6/2021, 11:28:23node: Device INPUT
msg.payload : Object { operation: "CONTROL", action: "CONNECT" }
!! No STATE change

Same but now starting with device OFF

5/6/2021, 11:41:26node: e63245d0.e6cdc8
msg : error
"Error: find() timed out. Is the device powered on and the ID or IP correct?"
5/6/2021, 11:41:27node: e63245d0.e6cdc8
!! Not catch by node,
!! No STATE ERROR
msg : error
"Error: find() timed out. Is the device powered on and the ID or IP correct?"
5/6/2021, 11:41:37node: e63245d0.e6cdc8
msg : error
"Error: find() timed out. Is the device powered on and the ID or IP correct?"

----------------  Turned ON by hand
5/6/2021, 11:41:38node: e63245d0.e6cdc8
msg : error
"Error: find() timed out. Is the device powered on and the ID or IP correct?"
5/6/2021, 11:41:45node: Device Data
--------- on flow the status change to green-connected
!!  no STATE CHANGE, no error tcatch

msg.payload.data.dps : Object
{ 1: true, 9: 0 }
!! Unrequested SCHEMA - not all dps: see (http://localhost/tuyadaemontoolkit/crud_devicedpoints.php?dName=Wifi_Plug)

5/6/2021, 11:42:38node: Device INPUT
msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" }
!! CONTROL without consequences
----------------  Turned OFF by hand
!! any consequence

5/6/2021, 11:52:44node: Device INPUT
msg.payload : Object  { operation: "CONTROL", action: "CONNECT" }
--------- on flow the status change to yellow-connecting
!!  Don't change from jellow.... until:

--------- sending a SET request:
5/6/2021, 11:53:07node: Device INPUT
msg.payload : Object { dps: 1, set: true }
5/6/2021, 11:53:07node: Device Data
msg.payload.data.dps : Object { 1: true }
!! not CONNECTED, but accepts data
!! now the flow status change to green-connected
!!  no STATE CHANGE

More notes on version 4:

The test was done using your example flow, a little modified Start: device ON, dashboard after a 'restart flow

!! device looks disconnected (red, disconnected)

5/6/2021, 12:17:50node: Node State
msg.payload : Object { state: "DISCONNECTED" }
5/6/2021, 12:17:51node: Node State
msg.payload : Object { state: "DISCONNECTED" }
--- OK status at start, but why 2?
!! ---- no more retry for auto-connect
------ sending  COMMAND 'CONNECT' 
5/6/2021, 12:18:24node: Device INPUT
msg.payload : Object { operation: "CONTROL", action: "CONNECT" }
5/6/2021, 12:18:24node: Node State
msg.payload : Object { state: "DISCONNECTED" }
5/6/2021, 12:18:25node: Node State
msg.payload : Object { state: "CONNECTING" }
5/6/2021, 12:18:29node: Node State
msg.payload : Object { state: "CONNECTING" }
5/6/2021, 12:18:29node: Node State
msg.payload : Object { state: "CONNECTED" }

---- for test, a SET
5/6/2021, 12:18:48node: Device INPUT
msg.payload : Object{ dps: 1, set: true }
5/6/2021, 12:18:49node: Node State
msg.payload : Object{ state: "CONNECTED" }
!! -- ??
5/6/2021, 12:18:49node: Device Data
msg.payload.data.dps : Object { 1: true }
---- OK, data SET

---- sending COMMAND 'CONNECT' to an already  connected device
5/6/2021, 12:18:56node: Device INPUT
msg.payload : Object{ operation: "CONTROL", action: "CONNECT" }
5/6/2021, 12:18:56node: Node State
msg.payload : Object { state: "DISCONNECTED" }
5/6/2021, 12:18:56node: Node State
msg.payload : Object { state: "DISCONNECTED" }
5/6/2021, 12:18:57node: Node State
msg.payload : Object{ state: "CONNECTING" }
5/6/2021, 12:18:57node: Node State
msg.payload : Object{ state: "CONNECTING" }
5/6/2021, 12:18:57node: Node State
msg.payload : Object{ state: "CONNECTED" }
!! ------- all redundant messages: nothing to do

---------------- now sending :  COMMAND 'DISCONNECT'
5/6/2021, 12:19:11node: Device INPUT
msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" }

5/6/2021, 12:19:11node: Node State
msg.payload : Object{ state: "DISCONNECTED" }
5/6/2021, 12:19:11node: Node State
msg.payload : Object{ state: "DISCONNECTED" }

------ sending SET to a 'DISCONNECTED' device:
5/6/2021, 12:19:16node: Device INPUT
msg.payload : Object { dps: 1, set: false }
5/6/2021, 12:19:17node: Node State
msg.payload : Object { state: "CONNECTED" }
!! -- ??
5/6/2021, 12:19:17node: Node State
msg.payload : Object { state: "CONNECTED" }
5/6/2021, 12:19:17node: Device Data
msg.payload.data.dps : Object{ 1: false }

5/6/2021, 12:19:21node: Node State
msg.payload : Object{ state: "CONNECTED" }
5/6/2021, 12:19:21node: Device Data
msg.payload.data.dps : Object { 18: 60, 19: 52, 20: 2287 }
!! ----- data PUSH from 'DISCONNECTED' device

5/6/2021, 12:19:23node: Node StateNotes:
5/6/2021, 12:19:23node: Device Data
msg.payload.data.dps : Object{ 18: 0, 19: 0 }
!! ----- data PUSH from 'DISCONNECTED' device

Notes

Best regards

m.s.

vinodsr commented 3 years ago

Auto connect featured is used to connect to the device on node red restart or start.

Instead of custom logs can you please share unmodified logs for a particular scenario.

This is working for me. I need to see if I omit any scenarios

On Sat, 5 Jun 2021 at 4:22 PM, Marco Sillano @.***> wrote:

more tests

The feature/fix-timeouts is with many problems:

  1. THE COMMANDs looks don't work: The test was done using your example flow, a little modified Start: device ON, dashboard after a 'restart flow' :

!! missed the initial STATE (CONNECTED|DISCONNECTED)

5/6/2021, 11:26:26node: Device INPUT msg.payload : Object { dps: 1, set: true } 5/6/2021, 11:26:26node: Device Data msg.payload.data.dps : object 1: true ------ OK swtch ON

5/6/2021, 11:28:07node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" } !! No STATE change

5/6/2021, 11:28:14node: Device INPUT msg.payload : Object { dps: 1, set: false } 5/6/2021, 11:28:14node: Device Data msg.payload.data.dps : Object 1: false !! switch change OFF

5/6/2021, 11:28:23node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "RECONNECT" } !! No STATE change

5/6/2021, 11:28:23node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "CONNECT" } !! No STATE change

Same but now starting with device OFF

5/6/2021, 11:41:26node: e63245d0.e6cdc8 msg : error "Error: find() timed out. Is the device powered on and the ID or IP correct?" 5/6/2021, 11:41:27node: e63245d0.e6cdc8 !! Not catch by node, !! No STATE ERROR msg : error "Error: find() timed out. Is the device powered on and the ID or IP correct?" 5/6/2021, 11:41:37node: e63245d0.e6cdc8 msg : error "Error: find() timed out. Is the device powered on and the ID or IP correct?"

---------------- Turned ON by hand 5/6/2021, 11:41:38node: e63245d0.e6cdc8 msg : error "Error: find() timed out. Is the device powered on and the ID or IP correct?" 5/6/2021, 11:41:45node: Device Data --------- on flow the status change to green-connected !! no STATE CHANGE, no error tcatch

msg.payload.data.dps : Object { 1: true, 9: 0 } !! Unrequested SCHEMA - not all dps: see (http://localhost/tuyadaemontoolkit/crud_devicedpoints.php?dName=Wifi_Plug)

5/6/2021, 11:42:38node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" } !! CONTROL without consequences ---------------- Turned OFF by hand !! any consequence

5/6/2021, 11:52:44node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "CONNECT" } --------- on flow the status change to yellow-connecting !! Don't change from jellow.... until:

--------- sending a SET request: 5/6/2021, 11:53:07node: Device INPUT msg.payload : Object { dps: 1, set: true } 5/6/2021, 11:53:07node: Device Data msg.payload.data.dps : Object { 1: true } !! not CONNECTED, but accepts data !! now the flow status change to green-connected !! no STATE CHANGE


More notes on version 4:

The test was done using your example flow, a little modified Start: device ON, dashboard after a 'restart flow

!! device looks disconnected (red, disconnected)

5/6/2021, 12:17:50node: Node State msg.payload : Object { state: "DISCONNECTED" } 5/6/2021, 12:17:51node: Node State msg.payload : Object { state: "DISCONNECTED" } --- OK status at start, but why 2? !! ---- no more retry for auto-connect ------ sending COMMAND 'CONNECT' 5/6/2021, 12:18:24node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "CONNECT" } 5/6/2021, 12:18:24node: Node State msg.payload : Object { state: "DISCONNECTED" } 5/6/2021, 12:18:25node: Node State msg.payload : Object { state: "CONNECTING" } 5/6/2021, 12:18:29node: Node State msg.payload : Object { state: "CONNECTING" } 5/6/2021, 12:18:29node: Node State msg.payload : Object { state: "CONNECTED" }

---- for test, a SET 5/6/2021, 12:18:48node: Device INPUT msg.payload : Object{ dps: 1, set: true } 5/6/2021, 12:18:49node: Node State msg.payload : Object{ state: "CONNECTED" } !! -- ?? 5/6/2021, 12:18:49node: Device Data msg.payload.data.dps : Object { 1: true } ---- OK, data SET

---- sending COMMAND 'CONNECT' to an already connected device 5/6/2021, 12:18:56node: Device INPUT msg.payload : Object{ operation: "CONTROL", action: "CONNECT" } 5/6/2021, 12:18:56node: Node State msg.payload : Object { state: "DISCONNECTED" } 5/6/2021, 12:18:56node: Node State msg.payload : Object { state: "DISCONNECTED" } 5/6/2021, 12:18:57node: Node State msg.payload : Object{ state: "CONNECTING" } 5/6/2021, 12:18:57node: Node State msg.payload : Object{ state: "CONNECTING" } 5/6/2021, 12:18:57node: Node State msg.payload : Object{ state: "CONNECTED" } !! ------- all redundant messages: nothing to do

---------------- now sending : COMMAND 'DISCONNECT' 5/6/2021, 12:19:11node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" }

5/6/2021, 12:19:11node: Node State msg.payload : Object{ state: "DISCONNECTED" } 5/6/2021, 12:19:11node: Node State msg.payload : Object{ state: "DISCONNECTED" }

------ sending SET to a 'DISCONNECTED' device: 5/6/2021, 12:19:16node: Device INPUT msg.payload : Object { dps: 1, set: false } 5/6/2021, 12:19:17node: Node State msg.payload : Object { state: "CONNECTED" } !! -- ?? 5/6/2021, 12:19:17node: Node State msg.payload : Object { state: "CONNECTED" } 5/6/2021, 12:19:17node: Device Data msg.payload.data.dps : Object{ 1: false }

5/6/2021, 12:19:21node: Node State msg.payload : Object{ state: "CONNECTED" } 5/6/2021, 12:19:21node: Device Data msg.payload.data.dps : Object { 18: 60, 19: 52, 20: 2287 } !! ----- data PUSH from 'DISCONNECTED' device

5/6/2021, 12:19:23node: Node StateNotes: 5/6/2021, 12:19:23node: Device Data msg.payload.data.dps : Object{ 18: 0, 19: 0 } !! ----- data PUSH from 'DISCONNECTED' device

Notes

  • The command COMMAND 'DISCONNECT|CONNECT|RECONNECT' MUST prevail on any GET/SET automatisms, if state DISCONNECTED the request SET/GET MUST be ignored.
  • The COMMAND CONNECT on an already connected device and the COMMAND DISCONNECT on an already disconnected device MUST be ignored,
  • At the start, the absence of auto-connect is a BUG.
  • At the start, the absence of any STATE msq, is a BUG
  • After power OFF and sequential power ON the COMMAND CONNECT works OK, but not the auto-connect: it is a BUG.
  • Why the output2 msg is not the standard 'status' (e.g. msg.status:{fill:"green",shape:"ring",text:"node-red:common.status.connected"}) but a custom 'msg.payload.strate' ?
  • Maybe also for the 'state' is better to use "node-red:common.status.connected" in place of the constant "CONNECTED", etc...

Best regards

m.s.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/64#issuecomment-855221564, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6OCIESVNJZ7IFSYWQUDTRH6VXANCNFSM46AJN5IQ .

-- Vinod Surendran R tenthsone.com tenthsone.com/adspot (new) tenthsone.com/junk talk.tenthstone.com [beta]

msillano commented 3 years ago

"Auto connect featured is used to connect to the device on node red restart or start. "

OK, but also if the device goes OFF, must do continue retry, and when the device goes back ON it must connect., This is not the case.

"Instead of custom logs can you please share unmodified logs for a particular scenario."

I confirm you that the last traces are unmodified debug pad log, using only your example circuit, to eliminate any interference.

If it is more convenient for you, I can try to put the various scenarios in a more schematic, and, I hope, reproducible way. Let me know.

Best regards m.s.

vinodsr commented 3 years ago

I had updated the code with some more logs. Can you please try your not working scenario for reconnection. can share me the compete logs ( the server logs)

msillano commented 3 years ago

A test

start conditions: debug trace: ON, device: ON, node-red: Deploy/restart flows

6 Jun 16:50:02 - [info] Stopped flows
6 Jun 16:50:02 - [info] Starting flows
6 Jun 16:50:02 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
  TuyAPI Finding missing IP undefined or ID device5-id**** +5ms
6 Jun 16:50:02 - [info] Started flows
  socket.io-parser encoding packet {"type":2,"data":["ui-controls",{"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}},"theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#2a8e93","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"},"themeState":{"base-color":{"default":"#097479","value":"#2a8e93","edited":true},"page-titlebar-backgroundColor":{"value":"#2a8e93","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#41c2c9","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#2a8e93","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"menu":[],"globals":[]}],"nsp":"/"} +1m
  socket.io-parser encoded {"type":2,"data":["ui-controls",{"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}},"theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#2a8e93","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"},"themeState":{"base-color":{"default":"#097479","value":"#2a8e93","edited":true},"page-titlebar-backgroundColor":{"value":"#2a8e93","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#41c2c9","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#2a8e93","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"menu":[],"globals":[]}],"nsp":"/"} as 2["ui-controls",{"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}},"theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#2a8e93","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"},"themeState":{"base-color":{"default":"#097479","value":"#2a8e93","edited":true},"page-titlebar-backgroundColor":{"value":"#2a8e93","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#41c2c9","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#2a8e93","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"menu":[],"globals":[]}] +0ms
  TuyAPI Socket closed: 192.168.1.17 +8ms
  TuyAPI Received UDP message. +278ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.12',
  TuyAPI     gwId: 'device18-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'rqxvfakd',
  TuyAPI     version: '3.3',
  TuyAPI     lan_cap: 500,
  TuyAPI     lan_seq: 11
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +0ms
  TuyAPI Received UDP message. +1s
  TuyAPI UDP data: +2ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.7',
  TuyAPI     gwId: 'device24-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyf9fsmuufeywsr',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +816ms
  TuyAPI UDP data: +2ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.10',
  TuyAPI     gwId: 'device19-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'key7axydcvmea3x9',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
  TuyAPI Received UDP message. +218ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.16',
  TuyAPI     gwId: 'device17-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keys83qyuhuqrdn7',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +285ms
  TuyAPI UDP data: +2ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.20',
  TuyAPI     gwId: 'device23-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'key5nck4tavy43jp',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
  TuyAPI Received UDP message. +135ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.15',
  TuyAPI     gwId: 'device15-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keys83qyuhuqrdn7',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +63ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.14',
  TuyAPI     gwId: 'device10-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keya4gvchmtapm8n',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
  TuyAPI Received UDP message. +300ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.17',
  TuyAPI     gwId: 'device5-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keym9qkuywghyrvs',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Connecting to 192.168.1.17... +4ms
  TuyAPI Socket connected. +82ms
6 Jun 16:50:05 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +32ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +60ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms
  TuyAPI Pong from 192.168.1.17 +1ms
............... omissis

note:


B test

start conditions: debug trace: ON, device: OFF, node-red: Deploy/restart flows

............. omissis
  TuyAPI     gwId: 'device17-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keys83qyuhuqrdn7',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +3ms
  TuyAPI Received UDP message. +414ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.15',
  TuyAPI     gwId: 'device15-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keys83qyuhuqrdn7',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +46ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.6',
  TuyAPI     gwId: 'device6-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyf9fsmuufeywsr',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
  TuyAPI Received UDP message. +292ms
  TuyAPI UDP data: +2ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.10',
  TuyAPI     gwId: 'device19-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'key7axydcvmea3x9',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +4ms
  TuyAPI Received UDP message. +112ms
  TuyAPI UDP data: +4ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.5',
  TuyAPI     gwId: 'device27-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'c0nh3LmEk0NDebrq',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +407ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.14',
  TuyAPI     gwId: 'device10-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keya4gvchmtapm8n',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +6ms
  TuyAPI Received UDP message. +301ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.11',
  TuyAPI     gwId: 'device20-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyfa7hya4gfa7g9',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
6 Jun 17:25:28 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
6 Jun 17:25:28 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying...
6 Jun 17:25:29 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
  TuyAPI Finding missing IP undefined or ID device5-id**** +2s
  TuyAPI Received UDP message. +762ms
  TuyAPI UDP data: +2ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.20',
  TuyAPI     gwId: 'device23-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'key5nck4tavy43jp',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +658ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.16',
  TuyAPI     gwId: 'device17-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keys83qyuhuqrdn7',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +413ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.15',
  TuyAPI     gwId: 'device15-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keys83qyuhuqrdn7',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +46ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.6',
  TuyAPI     gwId: 'device6-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyf9fsmuufeywsr',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +296ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.10',
  TuyAPI     gwId: 'device19-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'key7axydcvmea3x9',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +109ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.5',
  TuyAPI     gwId: 'device27-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'c0nh3LmEk0NDebrq',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +3ms
  TuyAPI Received UDP message. +415ms
  TuyAPI UDP data: +0ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.14',
  TuyAPI     gwId: 'device10-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keya4gvchmtapm8n',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
  TuyAPI Received UDP message. +306ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.11',
  TuyAPI     gwId: 'device20-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyfa7hya4gfa7g9',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +3ms
  TuyAPI Received UDP message. +1s
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.7',
  TuyAPI     gwId: 'device24-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyf9fsmuufeywsr',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +61ms
  TuyAPI UDP data: +2ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.13',
  TuyAPI     gwId: 'device16-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'ds0dztbnkfwlnhrk',
  TuyAPI     version: '3.3',
  TuyAPI     token: true
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms
  TuyAPI Received UDP message. +358ms
  TuyAPI UDP data: +0ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.12',
  TuyAPI     gwId: 'device18-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'rqxvfakd',
  TuyAPI     version: '3.3',
  TuyAPI     lan_cap: 500,
  TuyAPI     lan_seq: 11
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +1ms
............... omissis

note: -. test ok, but why the test to other devices? (all flows are disabled)

ERROR: no 'state' message from device-node. Expected many state messages: initial "DISCONNECTED", then many "CONNECTING", then "DISCONNECTED" ERROR: the "find() timed out." is sent as an error and not as STATE msg (in 4.1 state msgs are sent).


C test

start conditions: debug trace: ON, device: ON, node-red: Deploy/restart flows

 ............... omissis.... like A test
  TuyAPI Received UDP message. +227ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.6',
  TuyAPI     gwId: 'device6-id****',
  TuyAPI     active: 2,
  TuyAPI     ability: 0,
  TuyAPI     mode: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keyf9fsmuufeywsr',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +2ms

............  here I turn OFF the device

  TuyAPI Received UDP message. +97ms
  TuyAPI UDP data: +1ms
  TuyAPI {
  TuyAPI   payload: {
  TuyAPI     ip: '192.168.1.17',
  TuyAPI     gwId: 'device5-id****',
  TuyAPI     active: 2,
  TuyAPI     ablilty: 0,
  TuyAPI     encrypt: true,
  TuyAPI     productKey: 'keym9qkuywghyrvs',
  TuyAPI     version: '3.3'
  TuyAPI   },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0
  TuyAPI } +3ms
  TuyAPI Connecting to 192.168.1.17... +3ms
  TuyAPI Socket connected. +112ms
6 Jun 17:03:11 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +5ms
  TuyAPI Parsed: +0ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +66ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Disconnect +2s
6 Jun 17:03:43 - [info] [tuya-smart-device:e63245d0.e6cdc8] Disconnected from tuyaDevice.
  TuyAPI Socket closed: 192.168.1.17 +4ms
  TuyAPI Connecting to 192.168.1.17... +1s
(node:14400) UnhandledPromiseRejectionWarning: Error: connection timed out
    at Socket.<anonymous> (d:\node-red\flow-1984\node_modules\tuyapi\index.js:442:18)
    at Object.onceWrapper (events.js:421:28)
    at Socket.emit (events.js:315:20)
    at Socket._onTimeout (net.js:483:8)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14400) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:14400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  TuyAPI Socket closed: 192.168.1.17 +5s

note:

ERROR: no 'state' message from device-node. Expected state messages: "DISCONNECTED", then many: "CONNERCTING", "DISCONNECTED". ERROR: impossible to reconnect: the condition of test B is not restored.


D test

start conditions: debug trace: ON, device: ON, node-red: Deploy/restart flows

............... omissis 
6 Jun 17:57:33 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +33ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +58ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms
  TuyAPI Pong from 192.168.1.17 +0ms

 //---------  sending DISCONNECT

  express:router dispatching POST /inject/1991e72.c15c719 +23s
  express:router query  : /inject/1991e72.c15c719 +1ms
  express:router expressInit  : /inject/1991e72.c15c719 +3ms
  express:router mounted_app  : /inject/1991e72.c15c719 +1ms
  express:router dispatching POST /inject/1991e72.c15c719 +0ms
  express:router query  : /inject/1991e72.c15c719 +1ms
  express:router expressInit  : /inject/1991e72.c15c719 +0ms
  express:router corsMiddleware  : /inject/1991e72.c15c719 +1ms
  express:router jsonParser  : /inject/1991e72.c15c719 +1ms
  body-parser:json content-type undefined +23s
  body-parser:json skip parsing +1ms
  express:router urlencodedParser  : /inject/1991e72.c15c719 +1ms
  body-parser:urlencoded content-type undefined +1ms
  body-parser:urlencoded skip parsing +1ms
  express:router mounted_app  : /inject/1991e72.c15c719 +2ms
  express:router dispatching POST /inject/1991e72.c15c719 +1ms
  express:router query  : /inject/1991e72.c15c719 +0ms
  express:router expressInit  : /inject/1991e72.c15c719 +8ms
  express:router serveStatic  : /inject/1991e72.c15c719 +1ms
  express:router mounted_app  : /inject/1991e72.c15c719 +1ms
  express:router dispatching POST /inject/1991e72.c15c719 +0ms
  express:router query  : /inject/1991e72.c15c719 +1ms
  express:router expressInit  : /inject/1991e72.c15c719 +0ms
  express:router mounted_app  : /inject/1991e72.c15c719 +1ms
  express:router dispatching POST /inject/1991e72.c15c719 +1ms
  express:router query  : /inject/1991e72.c15c719 +0ms
  express:router expressInit  : /inject/1991e72.c15c719 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +9ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +6ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +329ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +56ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms
  TuyAPI Pong from 192.168.1.17 +1ms

  // ----------------  sending SET DP 1, TRUE

  express:router dispatching POST /inject/993c8470.01a278 +31s
  express:router query  : /inject/993c8470.01a278 +0ms
  express:router expressInit  : /inject/993c8470.01a278 +1ms
  express:router mounted_app  : /inject/993c8470.01a278 +0ms
  express:router dispatching POST /inject/993c8470.01a278 +0ms
  express:router query  : /inject/993c8470.01a278 +0ms
  express:router expressInit  : /inject/993c8470.01a278 +0ms
  express:router corsMiddleware  : /inject/993c8470.01a278 +1ms
  express:router jsonParser  : /inject/993c8470.01a278 +0ms
  body-parser:json content-type undefined +31s
  body-parser:json skip parsing +0ms
  express:router urlencodedParser  : /inject/993c8470.01a278 +0ms
  body-parser:urlencoded content-type undefined +0ms
  body-parser:urlencoded skip parsing +0ms
  express:router mounted_app  : /inject/993c8470.01a278 +1ms
  express:router dispatching POST /inject/993c8470.01a278 +0ms
  express:router query  : /inject/993c8470.01a278 +0ms
  express:router expressInit  : /inject/993c8470.01a278 +0ms
  express:router serveStatic  : /inject/993c8470.01a278 +0ms
  express:router mounted_app  : /inject/993c8470.01a278 +0ms
  express:router dispatching POST /inject/993c8470.01a278 +1ms
  express:router query  : /inject/993c8470.01a278 +0ms
  express:router expressInit  : /inject/993c8470.01a278 +0ms
  express:router mounted_app  : /inject/993c8470.01a278 +0ms
  express:router dispatching POST /inject/993c8470.01a278 +0ms
  express:router query  : /inject/993c8470.01a278 +0ms
  express:router expressInit  : /inject/993c8470.01a278 +0ms
  TuyAPI SET Payload: +724ms
  TuyAPI {
  TuyAPI   devId: 'device5-id****',
  TuyAPI   gwId: 'device5-id****',
  TuyAPI   uid: '',
  TuyAPI   t: 1622995104,
  TuyAPI   dps: { '1': true }
  TuyAPI } +0ms
  TuyAPI Received data: 000055aa00000000000000080000004b00000000332e3300000000000025bc00000001f201d2835a8b2f14b961521e3bdf5f8489748518094b5b4479590774debe58042cf0e2b2889cd070607529db3514ca5f2494d1bf0000aa55 +113ms
  TuyAPI Parsed: +1ms
  TuyAPI {
  TuyAPI   payload: { dps: { '1': true }, t: 1622995103 },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 8,
  TuyAPI   sequenceN: 0
  TuyAPI } +0ms
  TuyAPI Received DATA packet +1ms
6 Jun 17:58:24 - [info] [tuya-smart-device:e63245d0.e6cdc8] [object Object]
  TuyAPI Received data: 000055aa00000006000000070000000c00000000d876af4c0000aa55 +69ms
  TuyAPI Parsed: +0ms
  TuyAPI { payload: false, leftover: false, commandByte: 7, sequenceN: 6 } +1ms
  TuyAPI Got SET ack. +0ms
  TuyAPI Pinging 192.168.1.17 +9s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +72ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms
  TuyAPI Pong from 192.168.1.17 +1ms
  TuyAPI Pinging 192.168.1.17 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +109ms
  TuyAPI Parsed: +0ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms
  TuyAPI Pong from 192.168.1.17 +1ms
........................ omissis

note:

Here the node-red debug pad:

6/6/2021, 17:57:54node: Device INPUT
msg.payload : Object  { operation: "CONTROL", action: "DISCONNECT" }

6/6/2021, 17:58:24node: Device INPUT
msg.payload : Object  { dps: 1, set: true }

6/6/2021, 17:58:24node: Device Data
msg.payload.data.dps : Object { 1: true }

ERROR: no 'state' message from device-node. Expected state messages: "DISCONNECTED" (in 4.1 state msgs are sent) ERROR: COMMAND DISCONNECT don't work: the SET OK after the COMMAND DISCONNECT

Hope that can help you. Feel free to ask for more trace if that useful.

Best regards m.s.

vinodsr commented 3 years ago

Thanks for the logs. But it is missing the information I am looking for. Can you please disable the debug env variable. I need the logs which are thrown by the node. If possible include the complete logs. (No breaks).

On Sun, 6 Jun, 2021, 10:33 pm Marco Sillano, @.***> wrote:


A test

start conditions: debug trace: ON, device: ON, node-red: Deploy/restart flows

6 Jun 16:50:02 - [info] Stopped flows 6 Jun 16:50:02 - [info] Starting flows 6 Jun 16:50:02 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command TuyAPI Finding missing IP undefined or ID device5-id +5ms 6 Jun 16:50:02 - [info] Started flows socket.io-parser encoding packet {"type":2,"data":["ui-controls",{"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}},"theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#2a8e93","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"},"themeState":{"base-color":{"default":"#097479","value":"#2a8e93","edited":true},"page-titlebar-backgroundColor":{"value":"#2a8e93","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#41c2c9","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#2a8e93","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"menu":[],"globals":[]}],"nsp":"/"} +1m socket.io-parser encoded {"type":2,"data":["ui-controls",{"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}},"theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#2a8e93","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"},"themeState":{"base-color":{"default":"#097479","value":"#2a8e93","edited":true},"page-titlebar-backgroundColor":{"value":"#2a8e93","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#41c2c9","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#2a8e93","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"menu":[],"globals":[]}],"nsp":"/"} as 2["ui-controls",{"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","lockMenu":"false","allowTempTheme":"true","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}},"theme":{"name":"theme-dark","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#2a8e93","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif","edited":true,"reset":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"},"angularTheme":{"primary":"indigo","accents":"blue","warn":"red","background":"grey"},"themeState":{"base-color":{"default":"#097479","value":"#2a8e93","edited":true},"page-titlebar-backgroundColor":{"value":"#2a8e93","edited":false},"page-backgroundColor":{"value":"#111111","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#41c2c9","edited":false},"group-borderColor":{"value":"#555555","edited":false},"group-backgroundColor":{"value":"#333333","edited":false},"widget-textColor":{"value":"#eeeeee","edited":false},"widget-backgroundColor":{"value":"#2a8e93","edited":false},"widget-borderColor":{"value":"#333333","edited":false},"base-font":{"value":"-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif"}}},"menu":[],"globals":[]}] +0ms TuyAPI Socket closed: 192.168.1.17 +8ms TuyAPI Received UDP message. +278ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.12', TuyAPI gwId: 'device18-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'rqxvfakd', TuyAPI version: '3.3', TuyAPI lan_cap: 500, TuyAPI lan_seq: 11 TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +0ms TuyAPI Received UDP message. +1s TuyAPI UDP data: +2ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.7', TuyAPI gwId: 'device24-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyf9fsmuufeywsr', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +816ms TuyAPI UDP data: +2ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.10', TuyAPI gwId: 'device19-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'key7axydcvmea3x9', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +1ms TuyAPI Received UDP message. +218ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.16', TuyAPI gwId: 'device17-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keys83qyuhuqrdn7', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +285ms TuyAPI UDP data: +2ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.20', TuyAPI gwId: 'device23-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'key5nck4tavy43jp', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +1ms TuyAPI Received UDP message. +135ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.15', TuyAPI gwId: 'device15-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keys83qyuhuqrdn7', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +63ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.14', TuyAPI gwId: 'device10-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keya4gvchmtapm8n', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +1ms TuyAPI Received UDP message. +300ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.17', TuyAPI gwId: 'device5-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keym9qkuywghyrvs', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Connecting to 192.168.1.17... +4ms TuyAPI Socket connected. +82ms 6 Jun 16:50:05 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +32ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +60ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.17 +1ms ............... omissis

note:

  • test ok, device connected.

ERROR: no 'state' message from device-node. Expected 3 state messages: initial "DISCONNECTED", then "CONNECTING", then "CONNECTED" (in 4.1 state msgs are sent).


B test

start conditions: debug trace: ON, device: OFF, node-red: Deploy/restart flows

............. omissis TuyAPI gwId: 'device17-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keys83qyuhuqrdn7', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +3ms TuyAPI Received UDP message. +414ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.15', TuyAPI gwId: 'device15-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keys83qyuhuqrdn7', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +46ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.6', TuyAPI gwId: 'device6-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyf9fsmuufeywsr', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +1ms TuyAPI Received UDP message. +292ms TuyAPI UDP data: +2ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.10', TuyAPI gwId: 'device19-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'key7axydcvmea3x9', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +4ms TuyAPI Received UDP message. +112ms TuyAPI UDP data: +4ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.5', TuyAPI gwId: 'device27-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'c0nh3LmEk0NDebrq', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +407ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.14', TuyAPI gwId: 'device10-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keya4gvchmtapm8n', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +6ms TuyAPI Received UDP message. +301ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.11', TuyAPI gwId: 'device20-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyfa7hya4gfa7g9', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms 6 Jun 17:25:28 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct? 6 Jun 17:25:28 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying... 6 Jun 17:25:29 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command TuyAPI Finding missing IP undefined or ID device5-id +2s TuyAPI Received UDP message. +762ms TuyAPI UDP data: +2ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.20', TuyAPI gwId: 'device23-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'key5nck4tavy43jp', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +658ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.16', TuyAPI gwId: 'device17-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keys83qyuhuqrdn7', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +413ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.15', TuyAPI gwId: 'device15-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keys83qyuhuqrdn7', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +46ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.6', TuyAPI gwId: 'device6-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyf9fsmuufeywsr', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +296ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.10', TuyAPI gwId: 'device19-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'key7axydcvmea3x9', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +109ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.5', TuyAPI gwId: 'device27-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'c0nh3LmEk0NDebrq', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +3ms TuyAPI Received UDP message. +415ms TuyAPI UDP data: +0ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.14', TuyAPI gwId: 'device10-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keya4gvchmtapm8n', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +1ms TuyAPI Received UDP message. +306ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.11', TuyAPI gwId: 'device20-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyfa7hya4gfa7g9', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +3ms TuyAPI Received UDP message. +1s TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.7', TuyAPI gwId: 'device24-id', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyf9fsmuufeywsr', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +61ms TuyAPI UDP data: +2ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.13', TuyAPI gwId: 'device16-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'ds0dztbnkfwlnhrk', TuyAPI version: '3.3', TuyAPI token: true TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms TuyAPI Received UDP message. +358ms TuyAPI UDP data: +0ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.12', TuyAPI gwId: 'device18-id****', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'rqxvfakd', TuyAPI version: '3.3', TuyAPI lan_cap: 500, TuyAPI lan_seq: 11 TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +1ms ............... omissis

note: -. test ok, but why the test to other devices? (all flows are disabled)

ERROR: no 'state' message from device-node. Expected many state messages: initial "DISCONNECTED", then many "CONNECTING", then "DISCONNECTED" ERROR: the "find() timed out." is sent as an error and not as STATE msg (in 4.1 state msgs are sent).


C test

start conditions: debug trace: ON, device: ON, node-red: Deploy/restart flows

  • now, after the device connection (same as A) the device is turned OFF

    ............... omissis.... like A test TuyAPI Received UDP message. +227ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.6', TuyAPI gwId: 'device6-id****', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keyf9fsmuufeywsr', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +2ms

............ here I turn OFF the device

TuyAPI Received UDP message. +97ms TuyAPI UDP data: +1ms TuyAPI { TuyAPI payload: { TuyAPI ip: '192.168.1.17', TuyAPI gwId: 'device5-id', TuyAPI active: 2, TuyAPI ablilty: 0, TuyAPI encrypt: true, TuyAPI productKey: 'keym9qkuywghyrvs', TuyAPI version: '3.3' TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 TuyAPI } +3ms TuyAPI Connecting to 192.168.1.17... +3ms TuyAPI Socket connected. +112ms 6 Jun 17:03:11 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +5ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +66ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Disconnect +2s 6 Jun 17:03:43 - [info] [tuya-smart-device:e63245d0.e6cdc8] Disconnected from tuyaDevice. TuyAPI Socket closed: 192.168.1.17 +4ms TuyAPI Connecting to 192.168.1.17... +1s (node:14400) UnhandledPromiseRejectionWarning: Error: connection timed out at Socket. (d:\node-red\flow-1984\node_modules\tuyapi\index.js:442:18) at Object.onceWrapper (events.js:421:28) at Socket.emit (events.js:315:20) at Socket._onTimeout (net.js:483:8) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7) (Use node --trace-warnings ... to show where the warning was created) (node:14400) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:14400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. TuyAPI Socket closed: 192.168.1.17 +5s

note:

  • no more trace until 17:09 !!!
  • after the device disconnected, no connection retry for more than 300 sec.
  • after that, if I turn ON the device: nothing happens in trace
  • after that, if I turn ON the device AND if I send COMMAND CONNECT: nothing happens in trace (in 4.1 it is working).

ERROR: no 'state' message from device-node. Expected state messages: "DISCONNECTED", then many: "CONNERCTING", "DISCONNECTED". ERROR: impossible to reconnect: the condition of test B is not restored.


D test

start conditions: debug trace: ON, device: ON, node-red: Deploy/restart flows

  • now, after the device connection (same as A) I send a COMMAND DISCONNECT then SET dp 1 true

............... omissis 6 Jun 17:57:33 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id**** TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +33ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +58ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.17 +0ms

//--------- sending DISCONNECT

express:router dispatching POST /inject/1991e72.c15c719 +23s express:router query : /inject/1991e72.c15c719 +1ms express:router expressInit : /inject/1991e72.c15c719 +3ms express:router mounted_app : /inject/1991e72.c15c719 +1ms express:router dispatching POST /inject/1991e72.c15c719 +0ms express:router query : /inject/1991e72.c15c719 +1ms express:router expressInit : /inject/1991e72.c15c719 +0ms express:router corsMiddleware : /inject/1991e72.c15c719 +1ms express:router jsonParser : /inject/1991e72.c15c719 +1ms body-parser:json content-type undefined +23s body-parser:json skip parsing +1ms express:router urlencodedParser : /inject/1991e72.c15c719 +1ms body-parser:urlencoded content-type undefined +1ms body-parser:urlencoded skip parsing +1ms express:router mounted_app : /inject/1991e72.c15c719 +2ms express:router dispatching POST /inject/1991e72.c15c719 +1ms express:router query : /inject/1991e72.c15c719 +0ms express:router expressInit : /inject/1991e72.c15c719 +8ms express:router serveStatic : /inject/1991e72.c15c719 +1ms express:router mounted_app : /inject/1991e72.c15c719 +1ms express:router dispatching POST /inject/1991e72.c15c719 +0ms express:router query : /inject/1991e72.c15c719 +1ms express:router expressInit : /inject/1991e72.c15c719 +0ms express:router mounted_app : /inject/1991e72.c15c719 +1ms express:router dispatching POST /inject/1991e72.c15c719 +1ms express:router query : /inject/1991e72.c15c719 +0ms express:router expressInit : /inject/1991e72.c15c719 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +9ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +6ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +329ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +56ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.17 +1ms

// ---------------- sending SET DP 1, TRUE

express:router dispatching POST /inject/993c8470.01a278 +31s express:router query : /inject/993c8470.01a278 +0ms express:router expressInit : /inject/993c8470.01a278 +1ms express:router mounted_app : /inject/993c8470.01a278 +0ms express:router dispatching POST /inject/993c8470.01a278 +0ms express:router query : /inject/993c8470.01a278 +0ms express:router expressInit : /inject/993c8470.01a278 +0ms express:router corsMiddleware : /inject/993c8470.01a278 +1ms express:router jsonParser : /inject/993c8470.01a278 +0ms body-parser:json content-type undefined +31s body-parser:json skip parsing +0ms express:router urlencodedParser : /inject/993c8470.01a278 +0ms body-parser:urlencoded content-type undefined +0ms body-parser:urlencoded skip parsing +0ms express:router mounted_app : /inject/993c8470.01a278 +1ms express:router dispatching POST /inject/993c8470.01a278 +0ms express:router query : /inject/993c8470.01a278 +0ms express:router expressInit : /inject/993c8470.01a278 +0ms express:router serveStatic : /inject/993c8470.01a278 +0ms express:router mounted_app : /inject/993c8470.01a278 +0ms express:router dispatching POST /inject/993c8470.01a278 +1ms express:router query : /inject/993c8470.01a278 +0ms express:router expressInit : /inject/993c8470.01a278 +0ms express:router mounted_app : /inject/993c8470.01a278 +0ms express:router dispatching POST /inject/993c8470.01a278 +0ms express:router query : /inject/993c8470.01a278 +0ms express:router expressInit : /inject/993c8470.01a278 +0ms TuyAPI SET Payload: +724ms TuyAPI { TuyAPI devId: 'device5-id', TuyAPI gwId: 'device5-id', TuyAPI uid: '', TuyAPI t: 1622995104, TuyAPI dps: { '1': true } TuyAPI } +0ms TuyAPI Received data: 000055aa00000000000000080000004b00000000332e3300000000000025bc00000001f201d2835a8b2f14b961521e3bdf5f8489748518094b5b4479590774debe58042cf0e2b2889cd070607529db3514ca5f2494d1bf0000aa55 +113ms TuyAPI Parsed: +1ms TuyAPI { TuyAPI payload: { dps: { '1': true }, t: 1622995103 }, TuyAPI leftover: false, TuyAPI commandByte: 8, TuyAPI sequenceN: 0 TuyAPI } +0ms TuyAPI Received DATA packet +1ms 6 Jun 17:58:24 - [info] [tuya-smart-device:e63245d0.e6cdc8] [object Object] TuyAPI Received data: 000055aa00000006000000070000000c00000000d876af4c0000aa55 +69ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 7, sequenceN: 6 } +1ms TuyAPI Got SET ack. +0ms TuyAPI Pinging 192.168.1.17 +9s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +72ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.17 +1ms TuyAPI Pinging 192.168.1.17 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +109ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms TuyAPI Pong from 192.168.1.17 +1ms ........................ omissis

note:

  • COMMAND DISCONNECT don't works, SET is OK

Here the node-red debug pad:

6/6/2021, 17:57:54node: Device INPUT msg.payload : Object { operation: "CONTROL", action: "DISCONNECT" }

6/6/2021, 17:58:24node: Device INPUT msg.payload : Object { dps: 1, set: true }

6/6/2021, 17:58:24node: Device Data msg.payload.data.dps : Object { 1: true }

ERROR: no 'state' message from device-node. Expected state messages: "DISCONNECTED" (in 4.1 state msgs are sent) ERROR: COMMAND DISCONNECT don't work: the SET OK after the COMMAND DISCONNECT

Hope that can help you. Feel free to ask for more trace if that useful.

Best regards m.s.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/64#issuecomment-855429623, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6OEQIFTHMR6U5KRCWNDTROS5FANCNFSM46AJN5IQ .

msillano commented 3 years ago

new test series


A test

start conditions: debug trace: OFF, device: ON, node-red: from node-red start

Welcome to Node-RED
===================

7 Jun 14:46:19 - [info] Node-RED version: v1.2.6
7 Jun 14:46:19 - [info] Node.js  version: v14.15.1
7 Jun 14:46:19 - [info] Windows_NT 10.0.18363 x64 LE
7 Jun 14:46:20 - [info] Loading palette nodes
7 Jun 14:46:22 - [info] Dashboard version 2.29.1 started at /ui
7 Jun 14:46:23 - [info] Settings file  : d:\node-red\flow-1984\settings.js
7 Jun 14:46:23 - [info] Context store  : 'default' [module=memory]
7 Jun 14:46:23 - [info] User directory : d:\node-red\flow-1984
7 Jun 14:46:23 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Jun 14:46:23 - [info] Flows file     : d:\node-red\flow-1984\flows_i7-4770.json
7 Jun 14:46:23 - [info] Server now running at http://127.0.0.1:1984/
7 Jun 14:46:23 - [info] Starting flows
7 Jun 14:46:23 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:46:23 - [info] Started flows

D:\node-red>REM the dashboard:

D:\node-red>dashboard-1984.html

D:\node-red>REM the interface

D:\node-red>start chrome http://localhost:1984

7 Jun 14:46:28 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****
7 Jun 14:46:40 - [info] [tuya-smart-device:e63245d0.e6cdc8] Disconnected from tuyaDevice.
7 Jun 14:46:41 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****

note:


B test

start conditions: debug trace: OFF, device: OFF, node-red: from node-red start

Welcome to Node-RED
===================

7 Jun 14:51:39 - [info] Node-RED version: v1.2.6
7 Jun 14:51:39 - [info] Node.js  version: v14.15.1
7 Jun 14:51:39 - [info] Windows_NT 10.0.18363 x64 LE
7 Jun 14:51:40 - [info] Loading palette nodes
7 Jun 14:51:43 - [info] Dashboard version 2.29.1 started at /ui
7 Jun 14:51:43 - [info] Settings file  : d:\node-red\flow-1984\settings.js
7 Jun 14:51:43 - [info] Context store  : 'default' [module=memory]
7 Jun 14:51:43 - [info] User directory : d:\node-red\flow-1984
7 Jun 14:51:43 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Jun 14:51:43 - [info] Flows file     : d:\node-red\flow-1984\flows_i7-4770.json
7 Jun 14:51:43 - [info] Server now running at http://127.0.0.1:1984/
7 Jun 14:51:43 - [info] Starting flows
7 Jun 14:51:43 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:51:43 - [info] Started flows

D:\node-red>REM the dashboard:

D:\node-red>dashboard-1984.html

D:\node-red>REM the interface

D:\node-red>start chrome http://localhost:1984
7 Jun 14:51:53 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
7 Jun 14:51:53 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying...
7 Jun 14:51:54 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:52:04 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
7 Jun 14:52:04 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying...
7 Jun 14:52:05 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:52:15 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
7 Jun 14:52:15 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying...
7 Jun 14:52:16 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:52:26 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
7 Jun 14:52:26 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying...
7 Jun 14:52:27 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:52:37 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
7 Jun 14:52:37 - [info] [tuya-smart-device:e63245d0.e6cdc8] Cannot find the device, re-trying...
7 Jun 14:52:38 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:52:48 - [error] [tuya-smart-device:e63245d0.e6cdc8] Error: find() timed out. Is the device powered on and the ID or IP correct?
................... same never ending

note: -. test ok, but why the test to other devices (see debug log)? (all flows are disabled)

ERROR: no 'state' message from device-node. Expected many state messages: initial "DISCONNECTED", then many "CONNECTING", then "DISCONNECTED" ERROR: the "find() timed out." is sent as an error and not as STATE msg (in 4.1 state msgs are sent).


C test

start conditions: debug trace: OFF, device: ON, node-red: from node-red start

Welcome to Node-RED
===================

7 Jun 14:58:11 - [info] Node-RED version: v1.2.6
7 Jun 14:58:11 - [info] Node.js  version: v14.15.1
7 Jun 14:58:11 - [info] Windows_NT 10.0.18363 x64 LE
7 Jun 14:58:12 - [info] Loading palette nodes
7 Jun 14:58:14 - [info] Dashboard version 2.29.1 started at /ui
7 Jun 14:58:15 - [info] Settings file  : d:\node-red\flow-1984\settings.js
7 Jun 14:58:15 - [info] Context store  : 'default' [module=memory]
7 Jun 14:58:15 - [info] User directory : d:\node-red\flow-1984
7 Jun 14:58:15 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Jun 14:58:15 - [info] Flows file     : d:\node-red\flow-1984\flows_i7-4770.json
7 Jun 14:58:15 - [info] Server now running at http://127.0.0.1:1984/
7 Jun 14:58:15 - [info] Starting flows
7 Jun 14:58:15 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 14:58:15 - [info] Started flows

D:\node-red>REM the dashboard:

D:\node-red>dashboard-1984.html

D:\node-red>REM the interface

D:\node-red>start chrome http://localhost:1984
7 Jun 14:58:19 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****

----------------- at 14:59  I turn OFF the device power

7 Jun 14:59:11 - [info] [tuya-smart-device:e63245d0.e6cdc8] Disconnected from tuyaDevice.
(node:9296) UnhandledPromiseRejectionWarning: Error: connection timed out
    at Socket.<anonymous> (d:\node-red\flow-1984\node_modules\tuyapi\index.js:442:18)
    at Object.onceWrapper (events.js:421:28)
    at Socket.emit (events.js:315:20)
    at Socket._onTimeout (net.js:483:8)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9296) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9296) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

note:

ERROR: no 'state' message from device-node. Expected state messages: "DISCONNECTED", then many: "CONNERCTING", "DISCONNECTED". ERROR: impossible to reconnect: the condition of test B is not restored.


D test

start conditions: debug trace: OFF, device: ON, node-red: from node-red start

Welcome to Node-RED
===================

7 Jun 15:04:31 - [info] Node-RED version: v1.2.6
7 Jun 15:04:31 - [info] Node.js  version: v14.15.1
7 Jun 15:04:31 - [info] Windows_NT 10.0.18363 x64 LE
7 Jun 15:04:32 - [info] Loading palette nodes
7 Jun 15:04:35 - [info] Dashboard version 2.29.1 started at /ui
7 Jun 15:04:35 - [info] Settings file  : d:\node-red\flow-1984\settings.js
7 Jun 15:04:35 - [info] Context store  : 'default' [module=memory]
7 Jun 15:04:35 - [info] User directory : d:\node-red\flow-1984
7 Jun 15:04:35 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Jun 15:04:35 - [info] Flows file     : d:\node-red\flow-1984\flows_i7-4770.json
7 Jun 15:04:35 - [info] Server now running at http://127.0.0.1:1984/
7 Jun 15:04:35 - [info] Starting flows
7 Jun 15:04:35 - [info] [tuya-smart-device:e63245d0.e6cdc8] initiating the find command
7 Jun 15:04:35 - [info] Started flows
7 Jun 15:04:35 - [info] [tuya-smart-device:e63245d0.e6cdc8] Connected to device! device5-id****

D:\node-red>REM the dashboard:

D:\node-red>dashboard-1984.html

D:\node-red>REM the interface

D:\node-red>start chrome http://localhost:1984

 ------- at 15:06:07 I send COMMAD DISCONNECT
 -----------  NONE ON TRACE !
 ------- at 15:06:43 I send 'SET dp 1, false:

7 Jun 15:06:43 - [info] [tuya-smart-device:e63245d0.e6cdc8] [object Object]

-------  nothing more

note:

Here the node-red debug pad:

7/6/2021, 15:06:07node: Device INPUT
msg.payload : Object  { operation: "CONTROL", action: "DISCONNECT" }

7/6/2021, 15:06:43node: Device INPUT
msg.payload : Object { dps: 1, set: false }

7/6/2021, 15:06:43node: Device Data
msg.payload.data.dps : Object { 1: false }

ERROR: no 'state' message from device-node. Expected state messages: "DISCONNECTED"
ERROR: COMMAND DISCONNECT don't work: the SET OK after the COMMAND DISCONNECT

Complete logs, but I don't see big differences... Ok, good luck.

Best regards m.s.

vinodsr commented 3 years ago

Quick check are you checking on this branch feature/fix-timeouts ?

In the logs I see another bugfix branch,.....

msillano commented 3 years ago

tuya-smart-device.zip

Pls. try the modified tuya-smart-device version here, I tried to solve the main problems:

I tested it with only one device.

Nex days I will try more.

Best regards

m. s.

vinodsr commented 3 years ago

I cannot modify custom versions. Have you taken the correct branch?

msillano commented 3 years ago

The file attached to the previous comment, is the file tuya-smart-device.zip, in https://github.com/vinodsr/node-red-contrib-tuya-smart-device/files/6611494/tuya-smart-device.zip.

I can't send it by mail, because of Google restrictions. Maybe changing the name... Let me know.

vinodsr commented 3 years ago

Thanks for the changes. I think you were working on old code . most of the changes in this has already been done.

I had incorporated the unhandled exception part and the error handling for the timeout while setting.

The updated code base in there in the fix timeout branch https://github.com/vinodsr/node-red-contrib-tuya-smart-device/tree/feature/fix-timeouts

Please take the latest version and test your cases. I am unable to test the unhandled exception as it is not happening in my case.

Thank you for your dedication. :)

vinodsr commented 3 years ago

Released 4.1.1

Please verify your issues are fixed