ESP8266 is a very affordable single chip WiFi solution, with a fairly capable CPU core on board. It came onto the scene in 2014 and made a pretty big splash.
We prepared a simple example to help you get off the ground quickly. We’ll show you how to use Mongoose Embedded Web Server to create a simple webserver running on ESP8266.
First, a quick refresher on setting up ESP8266 build environment. This is not specific to Mongoose Embedded Web Server, feel free to skip if you have everything ready.
You will need:
- One of the ESP8266 modules (we presume you already have that)
- A Linux machine running Ubuntu (a VM will do)
- The RTOS-based SDK - clone this repo
- GCC compiler toolchain
- Download xtensa-lx106-elf.tar.bz2 from this public folder.
- Follow instructions in step 4 of the README.
Once there, and assuming the toolchain has been installed correctly, you should be able to build it with the following commands:
$ export SDK_PATH=/opt/ESP8266_RTOS_SDK # change this to your SDK location
$ export BIN_PATH=./bin; mkdir ./bin
$ make clean; make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=dio SPI_SIZE_MAP=0
BIN_PATH: ./binNo boot needed.
Generate eagle.flash.bin and eagle.irom0text.bin successully in BIN_PATH
With firmware built, it is now ready for flashing. We recommend you use esptool for this, but any other flashing tool will do. For esptool, the command line will look like this:
$ esptool.py --port /dev/ttyUSB0 --baud 230400
write_flash --flash_mode=dio --flash_size=4m
Took 0.58s to erase flash block
Wrote 35840 bytes at 0x00000000 in 1.8 seconds (157.5 kbit/s)...
Took 2.02s to erase flash block
Wrote 301056 bytes at 0x00020000 in 15.4 seconds (156.7 kbit/s)...
Took 0.11s to erase flash block
Wrote 1024 bytes at 0x0007e000 in 0.1 seconds (163.5 kbit/s)...
After this, you should see a “Mongoose” WiFi network appear - example sets up an AP. Use password “Mongoose” to connect and navigate to http://192.168.4.1/, you should see a “Hello, world” greeting page - served by the event handler defined in user_main.c.
And that is all for today. This example only demonstrates a web server, but you have all the power of the Mongoose multi-protocol networking library at your disposal (except file serving, because ESP does not have a filesystem by default).