Hello YouTubers, here is the guy with the Swiss accent.
Today I will make my device really OTA capable.
And in addition, I will introduce an interesting, small electronic part which can be used for
many applications in our projects: The Reed switch.
I will show, how it works, and why it is an ideal addition to our wireless IOT devices.
The reed switch is a few centimeters long and a few millimeters thick and the outside
consists of glass.
Inside the glass, there are two magnetic contacts, which are normally open.
As soon as a magnetic field comes into close proximity, the contact closes.
It only costs a few cents.
These switches are mainly used in two applications: The first is a normal relay, which is operated
by electricity.
These relays are quite small and often can be mounted on PCBs.
They only switch small loads, but also do not need lot of current for switching.
So, if you want to have a galvanic separation in your Arduino projects, these reed relays
are a good choice, because normal relays need a much higher current to switch them.
Unfortunately, most reed relays are not specified below 5V.
So, if you use 3.3volt devices, you have to test first, if the contact closes.
But we can create the magnetic field with a simple magnet.
Somehow, this is “Over the air” or OTA.
Exactly as we deal with our devices.
But which problems can be solved with such a simple device?
Here, I have a nice thing: My proximity sensor for my lab LED lamps.
I printed a nice housing and it is closed and mounted at its place.
I did not foresee any switch at the outside, because it does not look nice, needs some
space, and is not easy to be mounted.
Of course, this device can be updated over the air, it can be monitored the same way,
and I even can enter the configuration with my smartphone or browser.
But it has some issues you only discover if you use it.
Let’s look at the three modes such a device can take:
1.
Operation: This is the normal mode where it is connected to your Wi-Fi and does its job
2.
Configuration: At the beginning, you have to enter the Wi-Fi- and other credentials.
Usually, this has only to be done once.
Without these credentials, your device will not be usable.
But sometimes, you need to change the configuration.
Of course, otherwise it would not make sense to make your device configurable.
3.
Update the firmware This can happen from time to time, because you enhance your sketches.
At the beginning, I tried to do everything completely automatic: As soon as the device
was not able to connect to Wi-Fi, I assumed, the credentials were not entered yet or someone
changed the Wi-Fi password.
In this case, the device automatically entered into Config mode and stayed there.
Unfortunately, this did not only happen when I wanted.
The ESP sometimes just does not connect the first time to the Wi-Fi.
Then, my sketch reboots and the second time, it usually works.
But with this automatic stuff, the device ended quite a few times in configuration and
did not do the job.
Now, you are right, I could have entered a timeout in WiFiManager.
This would have eased this problem, But then, we immediately discover the next
problem: How can we enter the config mode if we really want to change the configuration?
And here, I found no solution yet.
Another thing is OTA update.
I included it at every boot.
This worked fine.
Then, I changed something at the code, and did not pay attention, and it was not only
flashed on my test device, but also on my production device.
This problem could be solved by strictly separating the test and the production environment.
I am sure, you are much better than me in designing these systems and adhere exactly
to your rules.
I am not good at that.
So, I wanted to decide, when I update my production devices.
And here comes the reed switch into play.
It offers an elegant solution to solve both problems at once: I connect such a small switch
to one pin and use Pinmode with the “PULL_UP” parameter.
So, this pin can be used to detect, if the switch is closed or not.
Then, I check, for how long this switch is closed.
If it is shortly closed, the device initiates an OTA update.
If it is closed for a longer time, it enters into configuration mode.
And because the reed swich alse works OTA, I glued it into the housing and marked on
the outside, where it is placed.
Now, if I want to do an update or a configuration change, I just use a small magnet and put
it into proximity to the switch.
Then, the device does, what I want.
Now I have a real “OTA” device.
I hope, this video was useful or at least interesting for you.
Bye.