• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32 webserver over ngrok shows no updated sensor values. Problem with websockets?

Q&A Forum › Category: ESP32 › ESP32 webserver over ngrok shows no updated sensor values. Problem with websockets?
0 Vote Up Vote Down
Michael Rogulla asked 4 years ago

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.

Question Tags: ngrok websockets
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Michael Rogulla answered 4 years ago

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.

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Michael Rogulla answered 4 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Michael.
Thanks for taking the time to share your findings.
It might be useful for other readers.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.