1

I have a Raspberry Pi that is connected to my network and a Samsung Gear S that is connected to the same network. The Raspberry Pi is used as a server and the Gear S sends data to it. I currently need to insert the Raspberry Pi IP address manually in the Gear S app whenever I connect to another network. I've found that you can use raspberrypi.local and that the raspberry pi will recognize this address as it owns. My problem is that when I try to post something to the address "http://raspberrypi.local:8080/appdata/post" using Javascript, the post doesn't come true. I suppose that raspberrypi.local cannot be resolved.

I stumbled on mdns-js (https://www.npmjs.com/package/mdns-js) and I think this should solve my problem. I want to run the following example:

var mdns = require(['mdns-js']);
console.log("Require found");

var browser = mdns.createBrowser();
console.log("Browser created");

browser.on('ready', function () {
    browser.discover(); 
});

browser.on('update', function (data) {
    console.log('data:', data);
});

But I get the following error:

Error: Script error for "mdns-js"
http://requirejs.org/docs/errors.html#scripterror (require.js:140)

I use the require function from http://requirejs.org/. Anybody who can help me with this error or better solve my problem. Thanks

Tim
  • 445
  • 5
  • 19
  • Does the IP on the Raspberry Pi ever change, or is it just sitting on a home network? – colonelsanders Mar 28 '16 at 14:36
  • It can change because it is not always connected to the same network. – Tim Mar 28 '16 at 14:46
  • Might want to take a look at [this question](http://raspberrypi.stackexchange.com/questions/13936/find-raspberry-pi-address-on-local-network) then, assuming you can run those commands from the Gear S without root. – colonelsanders Mar 28 '16 at 14:49
  • @colonelsanders the problem is I need to do it in Javascript – Tim Mar 28 '16 at 14:52
  • Is the Gear app a web app then? Bit confused, sounds like you want to run JS on the Gear S that will find your Pi, which has a non-static address. I'm not aware of any reliable way to do that with client-side JS, apart from running a local scan to find all devices in the private space running on :8080. – colonelsanders Mar 28 '16 at 15:11
  • @colonelsanders, yes i'm writing a web app. So you say that there is no other way than doing a local scan? – Tim Mar 28 '16 at 15:49
  • 1
    Barring any experimental or poorly supported protocols, then yes. But only to _my_ knowledge. – colonelsanders Mar 28 '16 at 15:51

0 Answers0