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:
- Every 6 minutes, check if your public IP address has changed.
- If it has changed, send an email to your email address notifying you of the new IP address.
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 http://bot.whatismyipaddress.com (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.
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.
When your IP address changes, you should receive an email like this:
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 :)