Opengate WiFi with Wemos D1

Opengate WiFi with Wemos D1: open the garage and the home gate from the mobile phone.

Open gate with WiFi

This project stems from a specific need. I have a limited number of remote controls to open the garage and gate of the house. Insufficient for all the members of the family. To solve I had two ways; or I bought other remote controls or I created a software system to open the gate. So I chose to create this opengate WiFi with Wemos D1.

Despite the fact that the cost of a remote control was negligible, I chose to create the software even if this involved spending days between development and testing. A choice justified by the fact that I should not have remembered to take the remote control every time I left the house. It would have been sufficient only phone that now we always have with us at any time of day.

Is it safe to open the gate with WiFi?

This is the question. Is it safe to open the doors of your home via WiFi? Is better a commercial system or a specially created software? Almost all commercial systems have WiFi WPA2 security. The Wemos D1 cards also use it. WPA2 encryption is cracked only by a bruteforce attack. Or at least it’s like this right now. So choosing a fairly complex WiFi key, the security is quite high. However it is possible to add some precautions to further increase it. Because the bruteforce attack takes many hours to succeed, its countermeasure consists in limiting the time in which the WiFi is turned on by the following mechanisms:

  1. WiFi always off;
  2. activation of the Wifi on demand, by pressing a button hidden in a zone under the surveillance camera;
  3. immediate shutdown of the wifi after several seconds of inactivity;
  4. turn off the wifi after a few minutes from activation;
  5. Instantly turn off the WiFi for each incorrect Userid and Password;
  6. random seed for always different communication strings;
  7. always different cookies every time you use them;
  8. implemented (but for my security reasons is not present on this page), sirens activation if, after a certain time from the opening of the gate, you do not enter a password on a keypad inside the house.

As mentioned, to combat bruteforce attacks on WPA2 encryption, we can reduce the time available to the attacker by switching off the wifi. However, each time it is necessary to reactivate it by pressing a hidden button.  It’s a disadvantage because to open the garage it could happen that you have to get out of the car while it rains in torrents. However, to leave the WiFi enabled, it is sufficient to comment on lines 449 to 556, or to add WiFi activation via a small PIR sensor.

How do I activate this opengate WiFi with Wemos D1?

The display screen of "Opengate WiFi with Wemos D1"

Screens displayed on an Android phone. In the foreground, the buttons. Behind the authentication screen.

When you want to enter in the house, turn on the WiFi by pressing the hidden button under the camera frame. Then, from any device that has an internet browser (tablet, mobile phone, notebook, car radio etc …) access the network. Type in your browser http: \\ (changeable by string  IPAddress apIP(1, 2, 3, 4);  in the attached sketch) to access the logon page. Now if you enter the correct user and password you can access the html page with the buttons to open the various gates (garage, gate, gate). In case of wrong password and/or url artifacts, the WiFi is turned off immediately. Among the buttons displayed there is also one dedicated to turn off the WiFi as soon as we do not need it anymore.

Required material for this Opengate WiFi with Wemos D1:

Opengate WiFi with Wemos D1: schema

Opengate WiFi with Wemos D1: schema

  • Wemos D1 card (works like an Arduino board, has a limited number of usable pins but has WiFi on board).
  • A piece of wire as an antenna to be connected to pin A0. In this way the detectable value is almost random and is used as a seed for the random function.
  • Two Rele cards for Arduino with 2 relays (as shown in the figure on the right) or one with 4 relays. Purchasable on the internet.

 Special features

  • Power supply detail for opengate WiFi with Wemos D1

    Opengate WiFi with Wemos D1: schema

    Special features To turn off the system, use one of the relays. When you press the hidden button, power is supplied to the Wemos card. This immediately activates the relay with the contacts connected in parallel with the hidden button. Thus the power supply is maintained even when the button is released. With this mode the scketch has full control of its power and is able to remove it for the safety reasons already mentioned (incorrect passwords, timeot various) and also to not waste energy.

  • The Wemos card activates locks via a relay board. There are commercially available relay card types which are activated at 0V and others at 5V. Therefore, the TipoAttivazioneRelay variable has been introduced, which allows to have the correct excitation voltage for each type of relay card on the output pin of the Wemos. Setting TypeActivationRelay to 1 the Wemos card will send to its pins the value 1 to activate them and 0 to release them. If, instead,  set TypeActivationRelay to 0, it will send 0 to activate the relays and 1 to de-energize them. In the case of the relay modules visible in the figure above, it is necessary set TypeActivationRelay = 0. If instead of a relay module you use a transistor to drive the relays, set TypeAttivazioneRelay to 1 if you use a NPN transistor, 0 if it’s PNP.
  • Each intermediate url that the program uses, such as those for understanding the pressed button, has incorporated a random string, different each time and valid only for that session.

Video: “Opengate WiFi with Wemos D1” in action

Customize the sketch:

Following the diagram, and loading the sketch, the system behaves as visible in the video. If you want to put it to work by personalizing it, you have to act on the variables const char * ssid = “WemosD1”; and const char * password = “WemosD1Key”; the first to change the WiFi network name and the second for the network password. You can also change the URL to access the main page http:\\ through the string IPAddress apIP (1, 2, 3, 4); in which you can only change the 4 numbers inside the brackets. Valid values from 0 to 255.


This sketch is distributed under license Postcardware (or cardware), freely usable on moral condition that you send me a postcard (or an email) from the point of the universe in which you are and that you mention the link of this page and author in the comments of the program.

Download sketch for Opengate WiFi