How to discover a Raspberry Pi on the local network


I am trying to build an app which will need to communicate with a Raspberry Pi HTTP server running on the same WiFi network. I am having a hard time figuring out how to do this while still staying in Expo for Android.

I can configure the Rapsberry Pi to run a local zeroconf server (avahi-daemon) which registers a named DNS entry. This works on iOS. I can use a named address like “http://raspberrypi.local” to communicate with it. However, this doesn’t work on an Android device. I could use react-native-zeroconf to discover the Pi, but that will mean ejecting. I could even do a local network scan the slow way using xmlHttpRequest, but that involves discovering your local IP address range. I am not aware of any expo compatible API to do that either.

Is there some clever hack/trick I am missing to make this work? I have complete control on the Pi so I can also change the setup on the Pi. I am really hoping to not have to eject because, well, Expo is awesome :slight_smile:


1 Like

Wait, are you saying that fetch('http://raspberrypi.local') doesn’t work on android?

Indeed. fetch('htp://raspberrypi.local') fails. I also have a <WebView> which is pointing to a URL hosted on the same server. That fails as well. I do not think this is even limited to Expo (or even react-native). I cannot even nagivate to http://raspberypi.local using the builtin Chrome browser on an Android device although I can do it on an iOS device.

I think that the resolution of the name raspberrypi.local to an IP address is builtin to iOS (because iOS natively implements zerconf), while on Android you have to explicitly do service discovery using a native solution like react-native-zeroconf to resolve the name raspberrypi.local to an IP address and then use the numerical IP address in the fetch query.

All of this is based on some recent reading. Please correct me if I am wrong.

Did you ever find a solution to this problem? I am facing this right now. Any suggested workaround? Cheers.

Hi…I would guess you could do this by port scanning every IP address to see if 22 is open? Which would be the SSH server - but this would be dependent on the Linux distro being run on the particular Pi. Easy enough if you know they will always have Raspbian for instance?
You could probably do that with the netcat command.

complete pcb