question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Host is unreachable, report error

See original GitHub issue

Hi 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

image

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:

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. 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:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kueblccommented, Aug 8, 2019

Heartbeat disconnect is being discussed for v6.0.0 https://github.com/codetheweb/tuyapi/issues/169#issuecomment-510637591

0reactions
subzero79commented, Aug 8, 2019

Thanks very much. I’ll subscribe to the post for updates

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Solve a Destination Host Unreachable Error - Lifewire
Destination host unreachable errors are often caused by a misaligned gateway due to poor internet or cable connections.
Read more >
Revamp SSH Unreachable Host Detection/Reporting #42173
Ansible playbooks abort (i.e. treats hosts as "UNREACHABLE") instead of failing for hosts when the issue is for example an authentication ...
Read more >
Host Unreachable vs Host Down - Forum - SolarWinds THWACK
Hi,. I am trying to understand when does Orion Advanced Alert report a host as unreachable and when does it report it as...
Read more >
vSphere HA reports that an agent is in the Agent Unreachable ...
To resolve this issue: Determine if vCenter Server is reporting the host as Not Responding.
Read more >
Ansible host reachability should not determine overall ...
Off course, this only applies to unreachable hosts, if you have something else (a failure or something due to a variable not set)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found