Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The library doesn't connect to devices if I restart the node service #7

Open
HuzefaGadi opened this issue Jun 20, 2018 · 17 comments
Open

Comments

@HuzefaGadi
Copy link

Hi,

The library works only in this sequence.

start nodejs service > start the device it stops working if the sequence is changed, like the device is already running and then I restart/start the node service after that.

any help will be appreciated.

Thanks
Huzefa

@futomi
Copy link
Owner

futomi commented Jun 20, 2018

Thank you for your feedback.
I've not understand what you want to do yet reading your comment. Could you elaborate a little more what you want to do and what is wrong.

@HuzefaGadi
Copy link
Author

Hello Futomi,
Thank you for your prompt response.
so here is the detail, I am using this library in my nodejs project which basically talks to a air-conditioner. everything works fine in this sequence

  1. I do npm start on my project.
  2. switch the air conditioner.

but I sometimes make changes to my node project and I have to restart the service. once I restart my service your library stops talking to the air-conditioner.. in short when I do discoverDevices I get no response, I get response only when I restart my air conditioner.

Thanks
Huzefa

@futomi
Copy link
Owner

futomi commented Jun 20, 2018

Thank you for explaining your situation.
The point is that ECHONET Lite devices are sometimes not discovered using the startDiscovery() method, isn't it?
What OS do you use? Windows 10?

@HuzefaGadi
Copy link
Author

HuzefaGadi commented Jun 20, 2018 via email

@futomi
Copy link
Owner

futomi commented Jun 20, 2018

Thank you for letting me know the OS type.
Actually, I have not tested this module on Mac OS.
I'll test on Mac OS. Give me some time.

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

@HuzefaGadi, I encountered the problem you reported on Mac OS. It seems that some ECHONET Lite devices does not react to the discovery packet. Investigating the problem, I found that leaving a multicast group (socket.dropMembership() method) does not work well on Mac OS as expected. It'll take more time to solve this problem.

BTW, where do you live and what ECHONET Lite product do you use? If you don't mind, could you let me know that? I'd like to know what type of ECHONET Lite products are selling in which country.

Thank you.

@HuzefaGadi
Copy link
Author

HuzefaGadi commented Jun 21, 2018 via email

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

Thank you so much for letting know. Most of actual ECHONET Lite products available in Japan reacts to the discovery packet. I'll try the MoekadenRoom.

Thank you.

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

I tried the MoekadenRoom. This module successfully discovered the MoekadenRoom devices. This module was run on Mac OS, and the MoekadenRoom was run on Win10 (64bit). The test code runs the discovery process multiple times, the MoekadenRoom was always discovered. Besides, whenever the test code runs, the MoekadenRoom is discovered successfully.

@HuzefaGadi
Copy link
Author

HuzefaGadi commented Jun 21, 2018 via email

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

Try this code:

'use strict';
process.chdir(__dirname);

// Load the node-echonet-lite module
var EchonetLite = require('node-echonet-lite');

// Create an EchonetLite object
var el = new EchonetLite({'type': 'lan'});

// Initialize the EchonetLite object
el.init((err) => {
  if(err) { // An error was occurred
    showErrorExit(err);
  } else { // Start to discover devices
    discoverDevices();
  }
});

// Start to discover devices
function discoverDevices() {
  console.log('Started.');
  // Start to discover Echonet Lite devices
  el.startDiscovery((err, res) => {
    // Error handling
    if(err) {
      showErrorExit(err);
    }
    // Output the found device
    var device = res['device'];
    var address = device['address'];
    var eoj = device['eoj'][0];
    var group_code = Buffer.from([eoj[0]]).toString('hex'); // Class group code
    var class_code = Buffer.from([eoj[1]]).toString('hex'); // Class code
    console.log(address + ': ' + group_code + '-' + class_code);
  });
  setTimeout(() => {
    el.stopDiscovery();
    console.log('Stopped');
    setTimeout(() => {
      discoverDevices();
    }, 10000);
  }, 5000);
}

// Print an error then terminate the process of this script
function showErrorExit(err) {
  console.log('[ERROR] '+ err.toString());
  process.exit();
}

@HuzefaGadi
Copy link
Author

HuzefaGadi commented Jun 21, 2018 via email

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

Did my code work well in your environment eventually?

@HuzefaGadi
Copy link
Author

No I am facing same issue with your code too.. The problem happens only when you try the steps . I told you.. just restart your script while MoekadenRoom is ON and see if it still discover devices.. for me it stops discovering devices after I restart the script

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

I did the steps you mentioned. In my environment, it works well. Hum, it seems to be difficult to solve...

Anyway, I found another issue thanks to your feedback. I'll keep to try to solve the issue. If the issue were solved, your problem might be solved.

I'll keep this issue to be opened for a while.

Thank you.

@HuzefaGadi
Copy link
Author

Will this library support batteries running on echonetlite? @futomi

@futomi
Copy link
Owner

futomi commented Jun 21, 2018

Will this library support batteries running on echonetlite? @futomi

Do you mean the storage battery class specified in ECHONET Lite spec?
No, for now. Such type of devices are really expensive. Though I'd like to support the class, I can't afford to buy such devices. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants