This is a sub-tutorial for my Door Unlocker App tutorial. Please read that first.

What’s different with this code?

This version is the same as the static IP address version, just with a couple of extra steps:

  1. Every 6 minutes, check if your public IP address has changed.

This is important because if you don’t have access to wifi from the main entrance door and your IP address has changed, you won’t be able to use the old URL to open the door.

Why every 6 minutes?

The maximum number of requests you can make to (the API that tells you your IP address), is one every 5 minutes. So to be on the safe side, the request is made once every 6 minutes.

Set up an email address

You’ll need to set up an email address which will be used to send the notification email. You can use gmail to create a free email.

You can make it as anonymous as you want, and make sure you set “allow less secure apps” to “on”.

Obviously don’t choose 2 factor authentication. You want this email address to be as insecure as possible, so that the code can access it.

Image for post
Image for post

The code

Install the ESP32 Mail Client library.

Make sure you update the constants with the relevant details.

eg. emailSenderAccount should be the email address you just created.

Set emailSenderPassword to be the password you created, and emailRecipient should be your personal email address.

The email

When your IP address changes, you should receive an email like this:

Image for post
Image for post

Make sure you inform anyone who is using the old URL about the new IP address.

Public IP address change notification services usually cost a bit of money, so enjoy this free service :)

I’m a software developer who is passionate about learning how things work behind the scenes.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store