HOME

truhialamV2 or the internet of freezers

truhialamV2 in case

Somehow it always bothered me that whenever I cleaned out my freezer I found lots of stuff that I had totally forgotten about and that by the time probably was completely inedible. So a couple of weeks ago I decided to do something about that.

The first step was to make an inventory list on paper and pin that to my fridge.
Now I just have to add stuff I put into the freezer and cross off what I took out and in theory there should be no more surprises in the future. (At some point the paper list might become an app or something along those lines, but for now it is good enough.)

That actually worked remarkably well, except when it didn't.
Since the list is in the kitchen and the freezer is in the basement the 30 seconds or so it takes me to get from one to the other is usually enough to forget to update the list. And as we all know the one thing worse than missing documentation is wrong documentation.

Therefore: Internet of Things to the rescue !

The obvious solution to the problem is to have my freezer remind me to update the list ^^.
I quickly threw a prototype together with a Raspberry Pi, a push button and a couple lines of python on a Saturday afternoon some weeks ago.
From then on I got an email notification to my phone 5 minutes after the freezer lid was closed.

As that worked perfectly I decided to replace this hackish solution with something more robust (and less wasteful in terms of hardware cost).

For the sensor I went with a cheap magnetic door sensor. And for the microcontroller I chose an ESP-01 since all I needed was WiFi and a single digital input pin.

This setup is pretty basic and there are lots of great articles and tutorials on how to program the ESP8266 with the Arduino IDE. So I am not going repeat that here.
If you are looking for more information on that please refer to [1] or [2] or check out my GitLab repository for this project.

Instead I want to give you a couple more details about the problems I ran into with this build and the solutions I came up with.

Problem 1: Using the GPIO pins of the ESP-01 as inputs

This is just meant to be a quick primer on the peculiarities of the ESP-01 GPIO pins. If you want to know more about this topic I encourage you to read this excellent article.

When researching the ESP-01's IO capabilities I discovered lots of projects using its GPIO pins as outputs, e.g. for controlling lights via WiFi.
But for some reason barely anyone was using them for input.

As it turns out there is good reason for that.
While the ESP-01 module does provide two GPIO pins, they are also overloaded with the function of activating the controller's firmware flashing modes.
For my particular use case this is a problem since that means that I always have to open the lid of my freezer (or disconnect the sensor) whenever I have to restart the ESP or otherwise it will start up in a bootloader mode no matter if the sensor is connected to GPIO0 or GPIO2.

There are several solutions for this problem. All of which, to my knowledge, require additional hardware if such a sensor is to be connected to GPIO0 or GPIO2 and not to interfere with the startup of the controller.

I was not exactly thrilled about the prospect of needing additional components as I chose the ESP-01 explicitly for its compactness.
Therefore I went a different path.

Instead of using one of the GPIO pins I disabled the UART function of the RX pin and used that as an additions input. The only drawback to this solutios is that you lose the ability to upload new firmware while the sensor is connected. That is a minor inconvenience during development but not a problem in production use.

This solution does not require any additional hardware and only one line of additional code:

Serial.begin(115200, SERIAL8N1, SERIALTX_ONLY);

This disables the receive function of the UART so the corresponding pin can be reconfigured as GPIO3:

pinMode(3, INPUT_PULLUP);

Problem 2: Sending emails with the ESP8266

There are several tutorials out there on sending emails from an ESP8266. Many of them, especially those sending through gmail, I found to be no longer valid or using rather brittle implementations that will probably stop working as soon as Google makes changes to the gmail service.

One of the reasons for this is that there currently is no viable TLS implementation for the ESP.

As a workaround I decided to just send email with plain SMTP.

CAUTION: Yes, that does mean that all communication is unencrypted. So if security is of concern to you, you should probably set up a local mail relay so there is no unencrypted communication outside your local network.

Using SMTP from the ESP is rather straight forward. You can find the code in my GitLab repository.
The only problem you might encounter if you don't want to set up a local mail relay is to find an email provider that does not require TLS or SSL nowadays.
As a matter of fact there are still several such providers out there. I am not going to link to any specific ones though as there have been several instances in the past where such providers closed their doors to non paying hobbyists once they found out they were recommended for such use on blogs.

That is basically it. Once I figured out the constraints of the GPIO pins and how to send email everything else was smooth sailing.

I hope you found this post helpful.

If you are interested in the code, schematics or templates for the case I used, please check out the project's repository on GitLab.

Feel free to contact me if you have any questions on one of the subjects i touched here.