Hi all, I can access my webserver running on an ESP32 from the Internet by using ngrok. I can control the ESP32 by (for example) clicking some buttons on the webinterface, but when a value on the ESP32 changes, it does not show up on the (remote) website.
This is my setup: ESP32 runs ESPAsyncWebserver with a soft AP (192.168.4.1/). On my Linux-PC I am connected to the ESP32 webinterface by WiFi and the Linux-PC is connected to the internet by Ethernet. My authtoken is valid, and I start ngrok as follows:
ngrok http -auth”xxxxxxx” 192.168.4.1:80
When opening the resulting ngrok-address I see my website running on ESP32, but when a sensor value changes on the ESP32 it doesn’t get updated automatically. The documentation of ngrok says “Websocket endpoints work through ngrok’s http tunnels without any changes.”
I am new to ngrok, but I thought that starting ngrok (like above) opens a tunnel?
I can open the ESP32 website (192.168.4.1/) on my local Linux-PC and it displays everything correctly, even when a sensor value changes on the ESP32.
Thanks in advance for your help.
Hi.
I’m not sure if this is the case, but unfortunately, the ESP websocket only works with HTTP.
You’ll need to open the ngrok URL with the http:// (not https).
If you open ngrok like this, it will work:
- http://YOUR-NGROK-URL.ngrok.io
Is this the way you’re accessing the URL?
Regards,
Sara
Hi Sara, thanks for the quick answer. I opened the “…..ngrok.io” address with http, but it still does not show the values from the sensor. As I said, I can use the webserver and click on a button or use a slider, but there is no data shown from the ESP32. I use an iPhone 8 and Chrome or Safari, that should do the trick. At least websockets work with the ESP32 when the iPhone is connected directly to the ESP32.
ngrok is running on my local Linux-machine. Interesting: ngrok has an “inspect”-function on 127.0.0.1:4040. There I can see the files delivered from the webserver (index.html, style.css, script.js) and the history shows a “200” answer for each file. But when I look at the specification of websockets (wikipedia), the server should answer with “101 switching protocols” but it doesn’t.
…
Now I tried it with an Android smartphone (Samsung S20) and there it works, thanks for suggesting the “http”. And the inspect-function shows a 101-response!
So maybe I can boil it down to the point: the network is ok, but some smartphones are able to initiate websockets over ngrok, and some don’t. I think I’ll talk to ngrok support.
Best, Michael.
Thank you.
Then, let me know their answer. I want to know if it is related to Apple devices or caused by something else.
Regards,
Sara
Hi Sara,
the support from ngrok contacted me and suggested to try to invoke ngrok without auth. And yeah that did the trick!
So basically: start it up with “ngrok http 192.168.4.1:80” to connect my laptop to the ESP32-webserver, and then invoke the random address from ngrok (like “1a2wsdew34332.ngrok.io”) with *http*, not with https. Finally I was able to see sensor values changing on my ESP32 on iPhone and Android, and my ESP32 far far away. Cool. I can live without auth, because I am planning a public installation, but I wrote to the support to take some investigations to solve this issue.
Best, Michael