rwaldron / johnny-five

JavaScript Robotics and IoT programming framework, developed at Bocoup.
http://johnny-five.io
Other
13.26k stars 1.76k forks source link

How to reset connection to a board? #1790

Open Yvanovitch opened 2 years ago

Yvanovitch commented 2 years ago

Hi, My goal is to find a workaround for this problem: Device or Firmware Error A timeout occurred while connecting to the Board https://github.com/rwaldron/johnny-five/issues/1260 https://stackoverflow.com/questions/52242319/johnny-five-unable-to-connect-to-arduino

I kind of gave up to find a direct solution for that. I noticed that if I restart the program it works 100% of the time. So I would like make a new connection without restarting the whole program.

I found this discussion talking about it, but it seems there's no solution. I don't understand the argument saying "if we close and connect, the board would be in a corrupted state" because if we destroy the whole johnny-five object, and create a new one with "new", we'd have a clean state.

I tried to just destroy the current johnny-five object and recreate a clean one, but obviously it doesn't work: I get this error message : Error Resource temporarily unavailable Cannot lock port

Is there any other approach ? Thanks

scottgonzalez commented 1 year ago

There is no other approach that will work with Johnny-Five. Destroying a board instance is still not supported. My takeaway from the other issue is that while it's possible for Johnny-Five to implement a destroy method and clean up all state and object references internally, there is no guarantee that the application developer will properly clean up all of the external state and object references. Usually the project maintainers will just take a stance of "it's your application, it's your responsibility to right correct code."

However, while many people are using Johnny-Five for small projects that only use 5 volts and don't contain any inherently dangerous components, Johnny-Five is also used in projects that are directly connected to main power lines. @rwaldron is not willing to open the avenue for those developers to make a mistake and accidentally leave components in life threatening states.

Since it's clear that this functionality will not be added, I'd suggest just closing the issue.

scottgonzalez commented 1 year ago

FYI: I just posted a solution in the other issue.

mind0bender commented 1 year ago

I kind of did this a while ago by using child-process.

Currently I do not have the source code but it was easy to implement using events between two main files.

say index.js is your main file. make a run.js and spawn index from it.

now use johnny-five's events and send them to the parent process(run.js in this case) so that it can restart it again on disconnect/close.

I am not sure if this will help with your "corrupted state" problem.

e3e6 commented 8 months ago

As I understood the johnny-five is only designed for education purposes, meaning, you only run in through npm start.js and just restart if something is wrong.

I also got into this issue, trying to create a web-server to communicate with my robot, but I cannot reconnect to my robot without restarting the entire server.

e3e6 commented 8 months ago

@scottgonzalez could you post the link to your solution?

scottgonzalez commented 8 months ago

As I understood the johnny-five is only designed for education purposes

I'm not sure where you got that understanding from. There is no such disclaimer on the site or the repo. In fact the README contains snippets such as "...delivering robust, reality tested, highly composable APIs..." and "Johnny-Five wants to be a baseline control kit for hardware projects..." I am currently using Johnny-Five in a commercial product; it is not ideal, but it is certainly stable and reliable.

@scottgonzalez could you post the link to your solution?

https://github.com/rwaldron/johnny-five/issues/617#issuecomment-1423133210

scottgonzalez commented 8 months ago

I also got into this issue, trying to create a web-server to communicate with my robot, but I cannot reconnect to my robot without restarting the entire server.

Since Johnny-Five doesn't do any clean up, since it's not designed for disconnecting boards, you will likely run into issues with max even listeners, memory leaks, etc. if you're repeatedly connecting to the board based on web requests. You'll probably need to add additional logic, and possibly even patch Johnny-Five, to avoid this.

e3e6 commented 8 months ago

I'm not sure where you got that understanding from.

Well, there is no new releases since 2021, and no place to ask questions and get replies.

I am currently using Johnny-Five in a commercial product; it is not ideal, but it is certainly stable and reliable.

Could you share how did you managed to handle reconnecting?