node-echonet-lite icon indicating copy to clipboard operation
node-echonet-lite copied to clipboard

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

Open HuzefaGadi opened this issue 7 years ago • 17 comments

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

HuzefaGadi avatar Jun 20 '18 07:06 HuzefaGadi

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.

futomi avatar Jun 20 '18 07:06 futomi

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

HuzefaGadi avatar Jun 20 '18 07:06 HuzefaGadi

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?

futomi avatar Jun 20 '18 08:06 futomi

I am on Mac OS. The startdiscovery works only when the server is first to start and then clients.. if a device is already up and if I run the server, that device is not discovered on start discovery

On Wed, Jun 20, 2018, 1:52 PM Futomi Hatano [email protected] wrote:

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?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/futomi/node-echonet-lite/issues/7#issuecomment-398666317, or mute the thread https://github.com/notifications/unsubscribe-auth/AEZ9dr5n7zhraNEg5AcybKboQ_IOCAjOks5t-gZdgaJpZM4UuvhD .

HuzefaGadi avatar Jun 20 '18 08:06 HuzefaGadi

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 avatar Jun 20 '18 08:06 futomi

@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.

futomi avatar Jun 21 '18 04:06 futomi

Hi,

This issue also appears on Linux as well.. I am using a coral edge box and running my scripts into it.

I am from India, and I am using echonetlite simulator instead of actual devices as they aren't available here. https://github.com/SonyCSL/MoekadenRoom this is the url for that simulator.

I would also like to know if the library supports batteries as well.

Thanks

On Thu, Jun 21, 2018, 10:11 AM Futomi Hatano [email protected] wrote:

@HuzefaGadi https://github.com/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() https://nodejs.org/api/dgram.html#dgram_socket_dropmembership_multicastaddress_multicastinterface 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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/futomi/node-echonet-lite/issues/7#issuecomment-398974036, or mute the thread https://github.com/notifications/unsubscribe-auth/AEZ9dgnF8-czjyzNurr-iVFt7Siw4jVnks5t-yPcgaJpZM4UuvhD .

HuzefaGadi avatar Jun 21 '18 04:06 HuzefaGadi

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 avatar Jun 21 '18 04:06 futomi

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.

futomi avatar Jun 21 '18 05:06 futomi

Can u share that test code

On Thu, Jun 21, 2018, 10:45 AM Futomi Hatano [email protected] wrote:

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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/futomi/node-echonet-lite/issues/7#issuecomment-398978634, or mute the thread https://github.com/notifications/unsubscribe-auth/AEZ9dsNQFcOMPL_ulH3pnQLnLEswXDUXks5t-yvpgaJpZM4UuvhD .

HuzefaGadi avatar Jun 21 '18 05:06 HuzefaGadi

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();
}

futomi avatar Jun 21 '18 05:06 futomi

I have the same code.. do this and see if it works... Start the simulator and run your script.. stop your script and run it again.. keep the simulator ON all the time..

See if the discover devices work then

On Thu, Jun 21, 2018, 11:02 AM Futomi Hatano [email protected] wrote:

Try this code:

'use strict';process.chdir(__dirname); // Load the node-echonet-lite modulevar EchonetLite = require('node-echonet-lite'); // Create an EchonetLite objectvar el = new EchonetLite({'type': 'lan'}); // Initialize the EchonetLite objectel.init((err) => { if(err) { // An error was occurred showErrorExit(err); } else { // Start to discover devices discoverDevices(); } }); // Start to discover devicesfunction 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 scriptfunction showErrorExit(err) { console.log('[ERROR] '+ err.toString()); process.exit(); }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/futomi/node-echonet-lite/issues/7#issuecomment-398981225, or mute the thread https://github.com/notifications/unsubscribe-auth/AEZ9dmMXgbL4QeEDfw4VZiGZZDMncZVWks5t-y_0gaJpZM4UuvhD .

HuzefaGadi avatar Jun 21 '18 05:06 HuzefaGadi

Did my code work well in your environment eventually?

futomi avatar Jun 21 '18 05:06 futomi

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

HuzefaGadi avatar Jun 21 '18 06:06 HuzefaGadi

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.

futomi avatar Jun 21 '18 06:06 futomi

Will this library support batteries running on echonetlite? @futomi

HuzefaGadi avatar Jun 21 '18 06:06 HuzefaGadi

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.

futomi avatar Jun 21 '18 07:06 futomi