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
43 stars 15 forks source link

Flow with multiple devices will sometimes report "Cannot call write after a stream was destroyed" after re-deploy #60

Closed foxylion closed 2 years ago

foxylion commented 3 years ago

Hi, first of all thank you for that awesome extension of node-red. Works quite well so far!

Sometimes I get an error Error from socket: Cannot call write after a stream was destroyed after I re-deploy my flow for some nodes that use the tuya-smart-device node. Mostly it is the same node. The only solution to fix the problem is restarting node-red. Otherwise the error will continue to be thrown.

Does anyone has an idea why that happens?

I've configured all nodes to use Device Virtual ID and Device Key.

Best, Jakob

vinodsr commented 3 years ago

Can you please share the logs for further investigation ?

foxylion commented 3 years ago

Hi, I have the log of Node-RED, does this help in any way? Or is there an option to get a more detailed log?

16 May 20:02:42 - [info] Started flows
16 May 20:02:42 - [info] [server:Home Assistant] Connecting to http://hass:8123
16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT Close
16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT End
16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT Connected
16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] Refreshing devices
16 May 20:02:42 - [info] [server:Home Assistant] Connected to http://hass:8123
16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT Subscribed to: "zigbee2mqtt/#
16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] Refreshing devices
16 May 20:02:43 - [info] [tuya-smart-device:power-plug-2] initiating the find command
16 May 20:02:43 - [info] [tuya-smart-device:power-plug-1] initiating the find command
16 May 20:02:44 - [info] [tuya-smart-device:power-plug-2] Connected to device! bf29d8d6d5becdd503m0ta
16 May 20:02:44 - [info] [tuya-smart-device:power-plug-2] Connected to device! bf29d8d6d5becdd503m0ta
16 May 20:02:44 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:02:44 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:02:45 - [info] [tuya-smart-device:power-plug-1] Connected to device! bf8780a47556c35c8a8lg2
16 May 20:02:45 - [info] [tuya-smart-device:power-plug-1] Connected to device! bf8780a47556c35c8a8lg2
16 May 20:02:52 - [info] [tuya-smart-device:power-plug-2] Data from device  [event:data]: {"dps":{"1":true,"9":0,"17":16,"18":0,"19":0,"20":2311,"21":1,"22":621,"23":30545,"24":17787,"25":1172,"26":0}}
16 May 20:02:52 - [info] [tuya-smart-device:power-plug-1] Data from device  [event:data]: {"dps":{"1":true,"9":0,"17":65,"18":0,"19":0,"20":2226,"21":1,"22":595,"23":29200,"24":16636,"25":1252,"26":0}}
16 May 20:02:54 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:02:54 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:04 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:04 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:14 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:14 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:22 - [info] [tuya-smart-device:power-plug-2] Data from device  [event:data]: {"dps":{"1":true,"9":0,"17":16,"18":0,"19":0,"20":2311,"21":1,"22":621,"23":30545,"24":17787,"25":1172,"26":0}}
16 May 20:03:22 - [info] [tuya-smart-device:power-plug-1] Data from device  [event:data]: {"dps":{"1":true,"9":0,"17":65,"18":0,"19":0,"20":2226,"21":1,"22":595,"23":29200,"24":16636,"25":1252,"26":0}}
16 May 20:03:24 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:24 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:34 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
16 May 20:03:34 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed
vinodsr commented 3 years ago

Are the two plugs same brand?

On Sun, 16 May 2021 at 11:35 PM, Jakob Nohe @.***> wrote:

Hi, I have the log of Node-RED, does this help in any way? Or is there an option to get a more detailed log?

16 May 20:02:42 - [info] Started flows 16 May 20:02:42 - [info] [server:Home Assistant] Connecting to http://hass:8123 16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT Close 16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT End 16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT Connected 16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] Refreshing devices 16 May 20:02:42 - [info] [server:Home Assistant] Connected to http://hass:8123 16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] MQTT Subscribed to: "zigbee2mqtt/# 16 May 20:02:42 - [info] [zigbee2mqtt-server:zigbee2mqtt] Refreshing devices 16 May 20:02:43 - [info] [tuya-smart-device:power-plug-2] initiating the find command 16 May 20:02:43 - [info] [tuya-smart-device:power-plug-1] initiating the find command 16 May 20:02:44 - [info] [tuya-smart-device:power-plug-2] Connected to device! bf29d8d6d5becdd503m0ta 16 May 20:02:44 - [info] [tuya-smart-device:power-plug-2] Connected to device! bf29d8d6d5becdd503m0ta 16 May 20:02:44 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:02:44 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:02:45 - [info] [tuya-smart-device:power-plug-1] Connected to device! bf8780a47556c35c8a8lg2 16 May 20:02:45 - [info] [tuya-smart-device:power-plug-1] Connected to device! bf8780a47556c35c8a8lg2 16 May 20:02:52 - [info] [tuya-smart-device:power-plug-2] Data from device [event:data]: {"dps":{"1":true,"9":0,"17":16,"18":0,"19":0,"20":2311,"21":1,"22":621,"23":30545,"24":17787,"25":1172,"26":0}} 16 May 20:02:52 - [info] [tuya-smart-device:power-plug-1] Data from device [event:data]: {"dps":{"1":true,"9":0,"17":65,"18":0,"19":0,"20":2226,"21":1,"22":595,"23":29200,"24":16636,"25":1252,"26":0}} 16 May 20:02:54 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:02:54 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:04 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:04 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:14 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:14 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:22 - [info] [tuya-smart-device:power-plug-2] Data from device [event:data]: {"dps":{"1":true,"9":0,"17":16,"18":0,"19":0,"20":2311,"21":1,"22":621,"23":30545,"24":17787,"25":1172,"26":0}} 16 May 20:03:22 - [info] [tuya-smart-device:power-plug-1] Data from device [event:data]: {"dps":{"1":true,"9":0,"17":65,"18":0,"19":0,"20":2226,"21":1,"22":595,"23":29200,"24":16636,"25":1252,"26":0}} 16 May 20:03:24 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:24 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:34 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed 16 May 20:03:34 - [error] [tuya-smart-device:power-plug-1] Error: Error from socket: Cannot call write after a stream was destroyed

— 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/60#issuecomment-841853538, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6OARI25ICDXEBBJQRNDTOACOPANCNFSM44BUNB4Q .

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

foxylion commented 3 years ago

All power plugs are from the same brand (and the same model): Teckin SP22

foxylion commented 3 years ago

Maybe this can help, I found some more log that is produced before the flow is started:

24 May 14:04:45 - [info] Flows werden gestartet
24 May 14:04:46 - [info] [tuya-smart-device:power-plug-2] Recieved the config {"id":"eaa4fd2.896ec","type":"tuya-smart-device","z":"d20aa8b8.d7f6b8","deviceName":"power-plug-2","deviceId":"bf29d8d6d5becd******","deviceKey":"a6c759da92******","deviceIp":"","retryTimeout":1000,"findTimeout":1000,"tuyaVersion":"3.1","eventMode":"event-both","x":830,"y":320,"wires":[["3c74be4e.913f32"]]}
24 May 14:04:46 - [info] [tuya-smart-device:power-plug-2] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true
24 May 14:04:46 - [info] [tuya-smart-device:power-plug-2] Connecting to Tuya with params {"id":"bf29d8d6d5becdd*******","key":"a6c759da9******","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  1000 , retryTimeout:  1000

24 May 14:04:46 - [info] [tuya-smart-device:power-plug-1] Recieved the config {"id":"73bd27e1.eb9168","type":"tuya-smart-device","z":"d20aa8b8.d7f6b8","deviceName":"power-plug-1","deviceId":"bf8780a47556c3******","deviceKey":"7affab4704******","deviceIp":"","retryTimeout":1000,"findTimeout":1000,"tuyaVersion":"3.1","eventMode":"event-both","x":830,"y":120,"wires":[["8ffa77b.f1a6288"]]}
24 May 14:04:46 - [info] [tuya-smart-device:power-plug-1] Event subscription : shouldSubscribeData=>true , shouldSubscribeRefreshData=>true
24 May 14:04:46 - [info] [tuya-smart-device:power-plug-1] Connecting to Tuya with params {"id":"bf8780a47556c******","key":"7affab4704******","ip":"","issueGetOnConnect":false,"nullPayloadOnJSONError":false,"version":"3.1"} , findTimeout :  1000 , retryTimeout:  1000
vinodsr commented 3 years ago

I just got similar issue. The issue was because I had a duplicate node for the same device. Once I removed the duplicate the issue was resolved,

vinodsr commented 3 years ago

Also released a new version which enables reconnect command, please check that as well

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

Auto closing the issue