Host is unreachable, report error
See original GitHub issueHi there, just wanted to thank you for this library. There is a nodered plugin that uses this library but looks like the creator is not interested in updating to the latest tuyapi. I though it would just be to pass the version in the constructor and change the package version. But didn’t work for me, so at the moment i am using the library by importing tuyapi into the global context which works good for me now. Describe the bug this is not like a bug but more like a question on the underlying net connect method. To use this tuya sockets i have them set up as mqtt switch in homeassistant, and all commanding and state report is done via nodered using mqtt in-out. To mark the devices as available or unavailable i use a 3 min interval ping to each device. To report the current state of the plugs i use a 10 sec interval query this time using the tuyapi module in a function node. I though to take out the ping out of the flow and just rely in tuyapi but seems like when host is unreachable there is no error report. I am correct to assume the net.connect method will not report any errors if the host is down? just will report on connections errors (sudden disconnect, refused, etc), the docs are not very specific on which errors
https://nodejs.org/api/net.html#net_event_connect
This is the code to check the status i use
const TuyAPI = global.get('tuyapi');
devObj = msg.payload
const device = new TuyAPI({
id: devObj.devId,
key: devObj.localKey,
ip: devObj.ip,
version: 3.3
});
device.connect();
device.on('connected', () => {
node.status({fill:"green",shape:"dot",text:"connected"});
});
device.on('disconnected', () => {
node.status({fill:"red",shape:"ring",text:"disconnected"});
});
device.on('error', error => {
node.log('Error!', error);
});
let stateHasChanged = false;
device.on('data', data => {
node.log('Data from device:', data);
data.dps.power = data.dps['19'].toString()
data.dps.state = data.dps['1']
data.devObj = devObj
delete data.dps['19']
delete data.dps['1']
node.send([data,null]);
device.disconnect()
});
setTimeout(() => { device.disconnect(); }, 1000);
node.on('close', function() {
device.disconnect() // tidy up any async code here - shutdown connections and so on.
});
To Reproduce Steps to reproduce the behavior:
- Go to ‘…’
- Click on ‘…’
- Scroll down to ‘…’
- See error
Expected behavior A clear and concise description of what you expected to happen.
Debug Output
Post the output of your program/app/script when run with the DEBUG
environment variable set to *
. Example: DEBUG=* node test.js
. Copy the output and paste it below (in between the code fences):
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [Debian]
- OS Version [9]
- Node Version [v10.16.0]
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Heartbeat disconnect is being discussed for v6.0.0 https://github.com/codetheweb/tuyapi/issues/169#issuecomment-510637591
Thanks very much. I’ll subscribe to the post for updates