rwaldron / particle-io

Particle/Spark Core/Photon IO Plugin for Johnny-Five
http://johnny-five.io
MIT License
173 stars 31 forks source link

Add mDNS support for Robustness. #48

Open notthetup opened 9 years ago

notthetup commented 9 years ago

During the last NodeBoats workshops at JSConf.Asia, I realised that backhaul from the router to the SparkCloud was super critical and if SparkCore couldn't connect to the SparkCloud, for whatever reasons (flaky connection, too many simultaneous requests, etc), there was no way to connect to the SparkCore.

This was ironic since the SparkCore is actually connected to the same router as the controller, and we just need the SparkCloud to know the IP address of the SparkCore. Asking some friends, I realised that mDNS solves this exact issue using multicast.

So I spent today prototyping to see if this would work. As long as the multiple SparkCores on the same network broadcast a unique hostname, it seems to work quite robustly. I used this node mdns implementation which is really straightforward.

Would such a mechanism help to reduce reliance on backhaul and SparkCloud? If it makes sense, I can clean up my prototype implementation and raise a PR. Also I would love to know if there are other ways to get around this solution which we can explore.

P.S. This will also need a corresponding change in voodoospark to be able to optionally get the IP Address from mDNS instead of SparkCloud. There exists a library which does mDNS on the SparkCore, we will need to integrate it into the voodoospark firmware.

rwaldron commented 9 years ago

In a perfect world, there would be zero reliance on SparkCloud—if you have a plan to possibly solve that, then I'm ready to help test. My only requirements:

notthetup commented 9 years ago

Agreed. Let me clean up my prototype and I'll send a link.

Currently the setup requires the user to input a unique string (hostname) in both places: voodoospark and spark-io init. That should be all.

monteslu commented 9 years ago

Also might want to consider this https://github.com/kmpm/node-mdns-js If it works, it'll save a compile

notthetup commented 9 years ago

@monteslu Good catch. They both have similar APIs, I'll try both.

notthetup commented 9 years ago

I finally managed to get this to work. It ended up being quite the rabbit hole thanks to the SparkCore not being happy when it can't be connected to Spark Cloud.

I made it work with what spark calls SEMIAUTOMATIC mode. But even there there are a few more hoops I had to work through with crazy work arounds.

I wanted to have it try to connect to SparkCloud and then use MDNS if that failed, but that seems impossible based on my understanding. Maybe I need to dig into it a little more.

Currently I have it on my branches.

https://github.com/notthetup/spark-io https://github.com/notthetup/voodoospark

I am not sure how to proceed in integration since it added quite a few dependencies on the voodoospark side of things. Maybe it's better of as a fork of the original? What do you guys think?