Already played around with an ESP8266 since it is fascinating by its capabilities: Wi-Fi module and easy MCU to program and by its price: around 3$.
I've already explained how to flash the firmware on a new ESP and it will always be helpful on each project I'll start: https://www.hackster.io/iboboc/esp-07-or-esp-12-with-nodemcu-going-into-deep-sleep-a0560e
I decided to start my functional project, useful IoT device, a smart button. The goal was to create a wireless button that can trigger a programmed action, like:
- Panic Button! Send instant notifications, SMS messages, emails to friends and relatives.
- Doorbell. When the button is pushed, receive a notification on your phone.
- The Doctor is ready. Or anyone else who needs to inform someone when they are ready.
- Call to action: press -> notify your pc
- Connect to Pushbullet to send instant notifications or trigger IFTTT actions.
- Connect to Twitter, Instagram, Facebook, Whatsapp, or any other social medium with an API.
- Toggle a light on and off, anywhere in the world.
- Turn on any internet controlled device, wherever it is.
- Open door
- Call a cab
- Find your phone
- Dinner is ready
- Please call me
- Here I am
- etc
Of course, not a new idea, therefore I've started looking for similar projects.
Then I came across the IFTTT Smart Button project from Noel Portugal and other related projects, but none of them was really "complete" either not fully working or not satisfactory enough for me, therefore I've decided to take the best from each one and build my very own enhanced one.
Started from Noel Portugal v2 button: https://www.hackster.io/noelportugal/ifttt-smart-button-e11841 because it was energy efficient (powered only when pushed) and has OTA Wi-Fi configuration.
It didn't work with my ESP-07, webpage not served, button not working with GPIO02.
Then I've got the good ideas from Madhouse: https://www.hackster.io/madhouse/ifttt-button-adapted-from-noel-portugal-43ca3d
- added chipID to the SSID
- added customurl field to let you enter and save another IFTTT url
- customurl saved in file
- added URL decoding and parsing
- removed the AP scanning and populating dropdown
Since it was not working neither with original schematic or updated one (it was required to keep pressed the button), I've started again from scratch and used the good idea and schematic from Barnabynbear user: http://www.esp8266.com/viewtopic.php?p=25583#p25583 and using GPIO0 instead of GPIO02 to power down the module and leave out the GPIO02 and the diode (didn't understand the role and necesity)
Then I was inspired by the good ideas from Peter Jennings: http://benlo.com/esp8266/esp8266Projects.html
- using RGB led with GPIO12, GPIO13, GPIO14 to show status (red for power on, blue for WiFi connected, green for successful sent)
- and the most significant: to use a LED push light to house the button
Therefore I've started preparing the case for my button, using this 1$ LED button.
My favorite ESP models are 07 and 12E since they are small enough to fit it everywhere, has integrated antennas and enough GPIOs to connect the RGB leds and others.
This is the schematic
And since I am using NodeMCU, it is useful to know the GPIO index mapped:
I 've used GPIO12, 13 and 14 for RGB LED to show a different color for each step.
GPIO0 to power and control the module.
GPIO02 to power and GPIO15 to ground to boot the ESP.
Then started the coding. Here it is the logic:
- set GPIO00 to HIGH (linked to CH_PD) - keep the module enabled after button push
- enable RGB led and light the RED, getting into ON state
- check if the file customurl.txt exists (it is configured already) and load the URL
- try to connect to Wi-Fi
- start a timer and if an IP is not set in 10seconds, the shutdown (that means that WiFi is not available, so you can try later)
- if you keep pressing the button, remove the file customurl.txt and shutdown (with this, the configuration is erased)
- If no configuration exists (customurl.txt is not present) then change the Wi-Fi mode to Access Point with the name "SmartButton" plus the unique ChipID
- start a web server on IP 192.168.1.1 and a form to enter SSID name, password and a custom URL
- on submit, save to internal memory in the file customurl.txt and restart module.
- once connected and an IP is available, change the LED from red to BLUE (connected)
- create a TCP connection and send custom URL
- after sending, LED is changing color from blue to GREEN (success)
- wait 3 seconds (to acknowledge the state)
- close the LED (all colors)
- set GPIO0 to LOW which will set CH_PD to LOW and module is disabled
- - start a timer for 3 sec and reset/clear the config settings (that means that if the module is still powered on, means that button is still pushed, therefore you can reset your config and restart in Access Point mode.
Since I've wanted to have a nice formatted html with css for the hot spot, I've used the explanations how html is served from Lefteris Stamataros http://www.esp8266.com/viewtopic.php?p=21085#p21085
That allowed me to have a very nice configurable html page.
I've uploaded the full code and test it on a breadboard and it looked like this:
Since everything was working fine, I was starting soldering and puting everything together.
I've also kept wiring for serial connection: GND, TX and RX to allow me to easily update the software afterwards (connection to be fitted in a USB to Serial)
So, the white paper can be change and customized with any message or picture you want. The LED can still be seen in the back.
I had to add an extra piece of plastic (actually a cut from a glue gun stick) on top of the button for easy push.
And as you can see in the back, there is the ESP antenna and the wiring for serial connection fore re-programming (in the third battery slot)
And finally my customized one:
And here it is a movie showing how it works. (notice that you have to keep pushed for 2 secs in order to work. I consider it a feature - to not permit accidental pushes).
I have added in the code also a new feature: count the clicks and store the number on a file. It is fun for statistics.
I believe my button has great features and can be reused on any ESP8266 project and I've learned many things along.
From Bobby, from Galati.. all the best!
Comments