Resolving mDNS in App Inventor 2

I am currently trying to develop an AI2 app that connects to a .local domain, said domain is hosted by an mDNS client running on an ESP8266 board.

Does App Inventor 2, or for that matter, Android in general, resolve mDNS domains? My plan is to have the app able to communicate using the Web component via HTTP to the board via LAN, since the network I'm connecting to uses DHCP, non-negotiable.

I saw this post which has almost the exact same scenario as I do, but to this day, there's no replies:

Any help would be appreciated

I asked ChatGPT for you. Below is the answer
Taifun


:jigsaw: The Core Problem

Android cannot resolve .local mDNS hostnames (like http://esp8266.local) natively.
That means in App Inventor:

Web1.Url = "http://esp8266.local"
Web1.Get

:arrow_right: :x: This will fail with “Host not found.”

Android simply ignores .local unless an mDNS resolver is built into your app.


:white_check_mark: Your Options in App Inventor

Option 1: Use a fixed local IP (simplest)

If your ESP8266 usually gets the same IP from the router, you can:

Check its IP once from the serial monitor (WiFi.localIP()).

Then use that IP in your app:
http://192.168.1.123/

:white_check_mark: Works everywhere
:x: Breaks if the IP changes (DHCP reset, router reboot, etc.)


Option 2: Use a Dynamic mDNS Resolver (with an extension)

App Inventor itself does not support mDNS, but you can add this using an extension (a .aix file).

There are two paths:

:brain: Option 2A: Use an existing mDNS extension

As of 2025, there are community-built extensions that wrap Android’s JmDNS library.
Search for:

JmDNS Extension for App Inventor or

mDNS Discovery AIX

For example, an extension like this (if you find one):

JmDNS.aix

It typically adds blocks like:

StartDiscovery("_http._tcp.local.")

WhenServiceFound(name, ip, port)

StopDiscovery

You’d then:

  1. Discover the ESP8266 service dynamically.

  2. Get its IP.

  3. Build the URL dynamically and send it to the Web component.

Example (pseudo blocks):

when Button1.Click
call mDNS.StartDiscovery("_http._tcp.local.")

when mDNS.ServiceFound name ip port
set Web1.Url to "http://" + ip + "/"
call Web1.Get

:white_check_mark: Works on Android
:white_check_mark: No manual IP entry
:warning: Requires a working .aix extension — there’s no official one from MIT.

If you want, I can show you how to wrap JmDNS into a custom .aix extension yourself (works even without root or special permissions).


Option 3: ESP8266 announces its IP via HTTP or MQTT

Instead of resolving .local, you can make the ESP report its IP:

Variant A: ESP8266 posts its IP to a known server

When booting:

WiFi.localIP().toString();
HTTPClient http;
http.begin("http://your-server.com/report?ip=" + WiFi.localIP().toString());
http.GET();

Your app fetches that IP from the server.

:white_check_mark: Works with basic App Inventor blocks
:x: Needs Internet / small backend

Variant B: Local UDP broadcast

ESP broadcasts its IP periodically to port (e.g., 4210)
App Inventor app listens via UDP extension (like UDP.aix)
When IP received → Web1.Url = "http:///"

:white_check_mark: Fully local, no DNS
:x: Requires UDP listener extension


:rocket: Recommended Practical Setup (2025)

Goal Method Tools Needed

Just want it to work Use static IP on ESP8266 none
Want automatic discovery Use mDNS/JmDNS extension custom .aix
Want local but robust Use UDP broadcast for IP discovery UDP extension


:gear: If You Want mDNS via Custom Extension

Yes — you need an extension.
MIT App Inventor doesn’t include the mDNS Java API (JmDNS).
It’s not possible with default blocks only.

You can either:

Find an existing .aix (I can help you locate one or show how to make it),

Or build one using the App Inventor Extension Template and include this library:

implementation 'org.jmdns:jmdns:3.5.5'

Inside, you’d expose a method to start discovery and a callback event when a device is found.


:white_check_mark: Summary

Approach Works in App Inventor? Needs Extension? Internet? Notes

esp8266.local :x: No — No Android can’t resolve it
Static IP :white_check_mark: Yes No No Simplest workaround
mDNS (JmDNS) :white_check_mark: Yes :white_check_mark: Yes No Best local discovery method
UDP Broadcast :white_check_mark: Yes :white_check_mark: Yes No Lightweight alternative
Cloud IP Sync :white_check_mark: Yes No :white_check_mark: Yes Works even across networks

If you can get to your local router's administrative web page, there is usually a router setting that demarcates a range of local IP addresses for fixed addresses, for example for printers that need to have stable IP addresses.

That range of addresses is beyond the control of DHCP.

a range of local IP addresses for fixed addresses

Would this mean that whenever the board connects to the network, it would be assigned a specific range that the app can scan, or would it assign just one static IP for it?

  1. The only mention of JmDNS that I can find is this: Error from Companion: java.lang.NoClassDefFoundError, and it just mentions JmDNS as a transitive dependency

  2. The board operates in a LAN-exclusive network, unregistered devices (like my board) does not have external internet access. So no accessing servers outside of the intranet

  3. For UDP broadcast, doesn't this require the app to know the board's IP in the first place?

I've also asked a chatbot regarding this question, but it yielded no results, hence why I'm asking here

Yes, but you do the records keeping as to who or what gets which IP address.

https://www.google.com/search?q=how+to+set+static+router+ip+address+range

As local administrator on your router, this gives you control over a specific IP address range. It then falls on you to go around to your devices and tell them which IP address belongs to them.

Good to know. I'll inform my institution's sysadmin and see if they can do this. Thank you!