Introduction: World Wide Web Control for Under $30.00
Applications for this project include:
Controlling items and getting information using any browser on any device (tablet/PC/phone) and also using low power mode to send back information from a remote locations for example monitoring water levels, wildlife etc.
To demonstrate what can be done the project has a temperature and humidity sensor that can be read and an LED that can be controlled. It is not intended to be an end product but more of an illustration of what can be achieved. It is hoped that the reader is inspired to create their own project for something more specific.
BV502 Mini-Max Microcontroller Aprox. £7.00 (ByVac)
ESP8266 Wi-Fi Controller Aprox £4.00
USB to Serial device Aprox £4.00 (ByVac)
Power supply (ByVac)
DST11 Temp + Humidity control Aprox £0.90
LED, 1000uF, 4k7 resistor
Breadboard and hook up wire
Complete kit of parts with software pre-loaded (ByVac) About £18.00
Step 1: Circuit Diagram & Building
The circuit is built on a solderless breadboard with the USB to serial supplying power for all of the circuit. The separate power supply which MUST be set to 3.3V, takes its input from the +V pin of the BV502 as this is the input from the USB. This separate supply powers the ESP8266.
Although the Mini-Max (BV502) has a built in 3.3V regulator it cannot supply enough power for the ESP8266 as well (it can but only just). There MUST be a large capacitor (about 1000uF) across the supply to the ESP8266 as it has been found by experimentation that unreliable results are obtained without it.
The Mini-Max circuit board has the port and pin named marked on it so C0 for example is port C pin 0. It is possible to build the circuit without a breadboard if the pins on the Mini_Max are soldered facing upwards. The kit
There are three switches shown, these are not actual switches but just wire jumpers on the breadboard. The firmware is written to read these switches to control the flow of the program. The program can also be controlled by the serial interface using the free IDE. For this project there is NO NEED to connect any of the switches, for now leave lines C7 to C9 unconnected.
If you are new to ByPic then it is best to simply connect up the BV502 and USB to serial first, then get the IDE going to give a feel for how the system works. This is fully explained here. ByPic is an interactive Rapid Application Development system which is an ideal partner for the ESP8266 Wi-Fi controller.
The next step is a quick introduction to ByPic
Step 2: Introduction to ByPic
ByPic is an interactive language that has been optimized for speed and for a simple for next loop can run at 1,250,000 lines per second, this compares with other interactive languages that can only manage about 25,000 lines per second for the same speed processor.
It is a cross between C and BASIC so should not be that difficult to learn. The reason for the speed optimization is so that it can be 'purposed' for a particular application. What does this mean? Well in a standard language you have many functions that perform particular jobs, In ByPic you write those functions yourself - or in the case of this project the functions have been written for you.
Using the example for this project we have a function called join() that will connect the ESP8266 to an existing Wi-Fi. It can be used interactivity as follows:
and will return success or fail. Using the function interactively mains that you can have instant feedback without the bother of compiling and downloading as you would need to do with say the Arduino.
In practice the functions can be built into modules or files, so for example the join() function is part of the ESP8266 file, there is another file which is added later called http_server.bas which uses some of the functions in the ESP file. This modular approach makes it easy to reuse code and modify the device for a particular application.
The language uses functions as the building block, so a typical function would be as in the picture, it always starts with the function keyword and ends with endf. A function is called simply by typing its name, functions can of course call other functions.
When a function is written (the free IDE can be used instead of the terminal screen) it goes to the RAM. If this function will be needed again at reset then it can be saved to Flash using the keyword flsave(""). In this way (or using the IDE) functions can be gradually built up until a complete system is achieved.
A special function called main() can be created that when saved to flash will automatically be run at start up, thus a turnkey system can be built.
Step 3: Wi-Fi Firmware
When the circuit has been built and ByPic is up and running (it will be up and running as soon as the serial is connected) it is time to download the firmware.
The firmware is currently available for ByPic version 2.30+ and the MX170 (newer Mini-Max BV502) and can be downloaded from here. The IDE must also be working to accept this script file. When the loading has completed (about 1 and 1/2 minutes) type .r (dot r) a couple of times to reset the processor, the kit comes with this software pre-loaded.
Without any of the 'switches' connected (C7 to C9 left disconnected) the Mini_Max will say wait... for a few seconds and then come up with the menu as shown in the picture.
You can play around with the commands, for example:
menu 5 to set the ESP8266 as a station
menu 6 - enter the SSID and password for your network
You should now be able to get the date and time from google (menu 11)
There is more on the use of the menu in the next section.
Step 4: Setting Up a Server (1)
A server is used in this context to provide a web page for a browser, so the setup will effectively be a HTTP server providing (all be it one) a web page to any browser that is connected. A server is useful for controlling things such as lights and heating as it can be contacted by any browser (potentially anywhere) and will respond straight away.
Select 3 to run info:
The important bits have been highlighted in white. This tells us that the current mode of operation is as an access point and if we were to scan on another device (laptop, phone etc.) we would see 'LINK3' as an open (the last 0) access point that we could connect to. We can communicate with it via the IP address as shown. This is 192.168.4.1 and cannot currently be changed. If Wi_Fi mode is not 2 then press 4 as we need the module to be an Access Point (AP)
Now press 9 to run the HTTP server. Go to the laptop or other device and connect to the SSID as shown in info, in this case LINK3. Because of the way the firmware is set up you will also need to place a shorting link between C9 on the Mini-Max and ground. Removing the link enables you to get out of the continuous server loop.
With the server up and running we will be able to see the SSID of the access point on another device, this depends whart device it is for example the picture shows a typical dongle Wi-Fi device connected to a PC, most laptops have built in Wi-Fi and for an Android device use the settings. Set the Wi-Fi link in the remote device PC/Laptop/Phone etc. to the SSID of the ESP8266 (LINK3 in the example but not on yours).
The remote device must obtain an IP address form the ESP8266 before communication can begin, this may take a few seconds or a few minutes. When an IP address has been obtained (an Android device will tell you) then in the address bar of the browser browse to 192.168.4.1.
You should see the yellow web page as in the picture, if you also have the USB to serial connected to the Mini-Max you will also see activity there.
You will see that from here you can control the LED and get results from the sensor. To stop the server running remove the link at C9.
Step 5: Setting Up a Server (2)
In part 1 of setting up a server, the ESP8266 was used as an access point. This was convenient because it meant that ANY device could link with it and control it even though they were not part of any network. However it is more likely or convenient that the ESP8266 is connected to an existing network, yet can still be a server.
Select option 5 to make the ESP8266 a station
Select option 6 (if not already done so) and put in your own home SSDI and password
Select option 3 and make a note of the IP address, also make sure that it is in mode 1 (station)
Select option 9 but this time brows to the IP address given in info, in the case of above this will be 192.168.11.54
You should be able to now connect without reconnecting to another access point. This is the most useful application for controlling a home network. For example powering up/down computer equipment, turning lights on and off. Even though it needs to be powered all of the time the power is very small about 1/3 Watt on average which is probably much less then most equipment on standby.