Controlling ESP32 through the internet

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
mslepe
Posts: 1
Joined: Sat Jan 02, 2021 7:59 pm

Controlling ESP32 through the internet

Post by mslepe » Sat Jan 02, 2021 8:19 pm

Hi! I've been playing with an ESP32 board I bought in Aliexpress and I want to control the alarm of my house with it, with both wifi and bluetooth. Both methods work without problems.

I uploaded html, css and js files to the board so I can control the motion sensors, trigger the siren and check the status of the alarm through a webpage.

This only works when I'm connected to my LAN though. One way to access the board from the internet would be to redirect ports in the router so that requests made to a specific port from outside would be redirected to the ESP32, but I was wondering if anyone knows how to do this without having to configure the router. NGROK is useful for something like this but I have no idea how to use it with an ESP32. I saw that there is a library called YalerWiFiServer that does this but it's available for arduino only.

Does anyone knows how to access the board from the internet ?

User avatar
pythoncoder
Posts: 4792
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Controlling ESP32 through the internet

Post by pythoncoder » Sun Jan 03, 2021 10:56 am

I would use MQTT with a public broker. This would require no changes to your router. Opening ports to the internet is only for the brave, IMO.
Peter Hinch

Tupps
Posts: 2
Joined: Tue Dec 29, 2020 10:43 am

Re: Controlling ESP32 through the internet

Post by Tupps » Sun Jan 03, 2021 11:05 am

There are a number of ways to do this:

Expose a port on your router that forwards to port 80 on your ESP32
Connect to your home network via a VPN.
Connect the ESP32 to an external MQTT server and control from there (this would involve a fair bit of code rewriting).

The big thing you want to consider is the security of your connection of the ESP32, the VPN is secure as you will need username/password or a certificate (better solution) to connect to the network.

Exposing a port will have little chance of someone finding it however, you do have the risk of it being exposed in services like Shodan and people stuffing around with your alarm system. It could be possible to add authentication to the web site, you would probably want to run it via HTTPS as well. Your ISP will have to give your internet address a real IP address, which isn't always a given sometimes you have to ask or sign up for a 'gaming pack' that gives you a real IP.

Doing the work to expose it via MQTT is a fair bit more work and then you would need to provide a UI to the MQTT server. If you were going to produce this as a commercial solution this would be the route (or an architecture similar to this) that I would take.

Personally, I would look at controlling it via a VPN first, if that doesn't suit exposing a port, after adding a bit of security to the webserver. Finally using an external MQTT server or similar, but this is going to be close to a complete rewrite.

User avatar
pythoncoder
Posts: 4792
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Controlling ESP32 through the internet

Post by pythoncoder » Mon Jan 04, 2021 12:04 pm

I assume you're aware of the official MQTT library? There is also this resilient asynchronous one. MQTT is quite easy to use and has the advantage of costing nothing ;)
Peter Hinch

Post Reply