Recently I bought a couple of wifi relays from Xiaomi. While they have been solid so far, I really dislike Xiaomi's app. But, I do like the idea that it actually works both in LAN and over the internet. When in LAN they are very quick to turn on and off, considering Xiaomi's servers are in China.
So I want to roll my own ESP8266 based relay (I know I can get the hardware ready made, so that's a bonus). My issue is, how can I automatically detect the relays on my network from a web page?
From an "App" I could use SSDP, mDNS-SD or UPNP to detect things. But I haven't found info on wether this is possible from the web browser (Chrome on Android basically). Since I changed my weather station web page to be a Progressive Web App, I've been hooked. I really like the idea of things just being webpages and not apps you have to install. And PWAs fill the gap with offline mode too.
It's strange though, that the "difficult" part (turning the relays on and off from outside the LAN) is trivial to solve via a MQTT server. But I'd prefer not to rely on the external MQTT server. If I'm on the LAN, I want to talk to the relays directly. If not, then send the command through MQTT.
I could, of course, rely on the server to query the relays, but in that case I'd need an internet connection (if my MQTT server is on the "cloud"), or a home hosted server. I do have a server at home, and even if I didn't, a raspberry pi could easily fill the gap. But the ideal would be not to even need a server when talking to the devices over LAN (Wifi in this case). I prefer to keep it P2P as much as possible, and only use MQTT as a fall back for when i'm on WAN (MQTT solves the problems of CG-NAT and port forwarding).