Automatically find IP address Raspberry Pi on same subnet using Javascript

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. How can I solve this?

That’s a tricky one.

So, you’re trying to allow the Samsung device to access the Pi on the same network without an IP? I don’t think there’s a way to do that.

http://webkay.robinlinus.com/ has a network scan that suggests you can do what you’re after but it’s never brought up devices for me.

Name resolution on my system is done using Bonjour (Zeroconf) That is easy because I am using a Mac which has bonjour by default. Zeroconf is a protocol for searching the local net for devices like net printers. On a PC anyone who installs iTunes gets bonjour with it. In linux Zeroconf is implemented .with Avahi. I have no idea what a Samsung Gear S is and whether it can use Zeroconf. Zeroconf just uses standard protocols to do its search. I suppose you could duplicate that functionality in Javascript. Sorry I’m not answering your question directly but hope you can find it using the varous buzz words I mention here. Zeroconf is a distributed thing. I don’t know the details but the rPi needs a server to answer zeroconf requests about what its name is. Most current distributions do that but you can search for how to add support if it is not in yours. Bonjour (or its equivalent on other hosts) is a host service that finds devices and puts the name in the local “hosts” file used when an app tries to connect using that name. Apologies, I just figured all this out a couple of days ago and I think it is right but I may have some details wrong.

A lot of the people that use “raspberrypi.local” basically get support for it automatically and often have no idea how the support got there. Lots of support sites answering various raspberry pi questions will just say use the name “raspberrypi.local” with nothing about what to do if it doesn’t work. I had to wade through lots of sites to track it down. The key is knowing how Bonjour or Zeroconf works.so googling for those gave me the best help. Mostly it is not really a raspberry pi question. These days the pi end is already in most distributions. Your host, in your case the Gear S has to do its part. There is usually a way for any device that supports network printers, especially apple printers, because that is where it the protocol originated.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.