In the previous tutorial we set up a simple web server and responded to incoming HTTP requests with a static web page, this time we're going to have some interaction between the web page and the device. We'll set up a simple web page with a button and when you click that button we'll toggle the LED on the ESP8266.
In the setup function we're going to add some additional handlers for incoming URIs.
Instead of serving up a simple 'Hello World' text response, this time we're pointing the root URI towards the servePage function, in which we'll create a more detailed HTML response.
We've added a second handler for the /args URI and pointed it towards the handleArgs function, this will be used to process the incoming data.
Finally we've added an onNotFound handler, this should respond to all other URIs and direct the browser back towards the root homepage.
I've clearly started something now and I was asked to make some TNT blocks, these blocks are predominantly red which leaves some issues for laser cutting. I could have used a red wood but the engraved areas would be a darker red, not the white colour required for the label. The solution was to mask a sheet of poplar and then paint key areas of it red, I used an airbrush to ensure that the colour didn't bleed under the masking. This gives me 3-4 different colours to use, all of the detailing was done with line artwork so that it stood out as a strong black.
The previous tutorial showed how to create a wifi access point but the ESP8266 didn't do anything once a station was connected. In this tutorial, we build upon the previous access point to serve a simple HTML web page in response to a request from a connected station.
Next we need to declare a new Web Server object using the HTTP port number, 80. This is the default port that a browser will use.
While I was in a minecrafty mood, I thought I'd take a look at some of the other blocks to see what could work on the laser. These oak blocks came out ok, I let the grain of the wood do the hard work as the detailing. It amuses me somewhat that they're made from illomba faced poplar ply instead of real oak. The lettering is done with negative engraving and the font could be a little thicker to make it stand out more.
In the previous tutorial we covered the very basic function of most micro controllers, blinking an LED, but the whole reason we're interested in the ESP devices is their ability to establish a WiFi connection. There is a library for this and it's very easy to set up.
The ESP8266 WiFi library has the ability to operate in a range of modes. It can act as a station where it would connect to an existing Wifi network, it can become an access point where it creates it's own wifi network and it lets devices connect directly to it. Finally it can operate in a mixture of both modes which is useful for forming mesh networks.
These little tokens are made to look like the chests from Minecraft. I made a whole batch for someone as part of an incentive system, each token collected allows 5 minutes of play on Minecraft.