Dr.Random
Dr.Random

Reputation: 500

Webserver hosted on an ESP32 using p2p

I was thinking about how could i host a webserver from an esp32 that is accessible from outside of it's network. The first thing i did was i port forwarded my esp32 private ip on my router and configured a dns server to my router's public ip ( no-ip , ddns.net )

That was good. I could reach my webserver hosted on my esp32 but if i want to create a product, this is not a good solution because i can not force the users to configure their routers and configure a dns provider for themselfs.

So the next thing in my mind was, i needed a server. I could have used mqtt or any other service to exchange data with the client but i wanted to do it myself.

So i set up a node js server on my PC. The esp32 can connect to this server because it is on a public network and port forwarded already. The esp32 can use websockets as a client or http requests to send data to the server. This is ok, but the web app that the client sees is not hosted on the esp32, but on the server. This makes it hard to update the web app files ( html and js files ) both on the server and on the esp32. Because what if the client want to reach the web app from within it's local network without internet. The esp32 should have the exact same web app hosted like on the server.

I was using socket io to communicate the esp32's data with the web app client. The node js server served the static html and js files to the client, and forwarded the esp's messages coming on websocket throught socket io to the client.

Okay so the problem in here as i said that i had to update the files on both the node server and on the esp32. This is not a good way.

So i need some kind of a p2p connection. At this point i read about hole punching and webrtc and things like that.

What i tried to establish p2p connection:

aaand nothing happens. The router's don't want to open their ports.

I tried this with raw udp, http requests and websockets. These were unsecured connections.

I found literally no low level explanation about web rtc's data channel. If i would want to write this "open source" protocoll using the C language there is just the explanation about this webrtc with high level languages like *built in options on browsers in JS and things like that.

ESP32 microcontroller LINK.

The question is, how could i estabilish a p2p connection between a microcontroller ( like esp32 using esp idf or arduino framework ) and a browser client? Is it even possible?

Upvotes: 1

Views: 1306

Answers (1)

Pavel Anpin
Pavel Anpin

Reputation: 44

Have you considered mDNS/DNS-SD? You can advertise your service from esp32 and discover it with your client via arbitrary network

Upvotes: 0

Related Questions