The old guide was out of date and had become a little messy and I had been thinking about redoing it for a while. Also, how I use the ESP8266 has changed and since I am using one as part of a IOT Word Clock I am currently building I thought I would update the guide. So, here is the all new version 2.0. The post for the IOT Word Clock will come later, probably much later…
When the ESP8266 first came out there was a lot of excitement and buzz. Here was a new chip that was cheap and allowed internet connectivity. I got caught up in all the excitement and bought several different modules. I intended to use them in various projects where I wanted some kind of remote control. Things didn’t go as planned though, I found the AT command interface very clunky and the ESp8266’s not very reliable. I put the ESP8266s away in the bottom of a draw and moved to Bluetooth.
Things changed when the ESP8266 core for the Arduino IDE was released. This meant you could program them as if they were Arduinos, no more messing around with AT commands. Programming the ESP8266s via the Arduino IDE made things a lot easier and it meant that in many cases you no longer required an Arduino.
In the first part I explained how to set up the IDE and got the basic blink sketch working. Here I go through building a web page control panel to control the LED remotely. I will start with a basic web page and then slowly refine it so we end with a simple but elegant control panel.
For this example I will be using the ESP8266 as an access point (AP Mode). This means the ESP8266 will create its own little network which we can connect to. The ESP8266 will then serve a small web page which we can view on a mobile device or any web enabled device such as a laptop.
I still have the LED connected to pin D1 but now I want to turn it on and off from a web page viewed on a mobile device. The web page will need 2 buttons, one for on and one for off. It would be nice if it also showed the current LED status. Something like “LED is on” and “LED is off”. Since this is a first example of a web control the actual web page should be as simply as possible.
I won’t go in to detail about creating web pages, if you are new to this there are many other sites to help you.
In the previous part we used the ESP8266 in Access Point mode where the ESP8266 generated it’s own mini network. Here we get the ESP8266 to connect to an existing wifi network. To do this we use the ESP8266 in Station Mode (STA). Switching to Station Mode is done by the library automatically so we do not need to mess around.
When using the ESP8266 in Station Mode, the connecting device has to be connected to the same network as the ESP8266. In AP mode, since the ESP8266 creates its own network, other local networks don’t matter.