Creating a simple WiFi HTTP Server using ESP8266

This tutorial shows how to create a basic WiFi HTTP server with the ESP8266 chip and VisualGDB. Before you begin, follow our ESP8266 OpenOCD tutorial to ensure that you can program your ESP8266 board.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:01-wiz
  2. Proceed with the default “embedded binary” setting on the first page:02-embeddedbin
  3. On the next page select the ESP8266 device. The WiFi and TCP/IP libraries requires a lot of space, so you will not be able to use the “no FLASH” mode:03-device
  4. On the sample page Select the HTTP Server (IoT SDK):04-http
  5. On the debug method page specify the debug settings that worked with the ESP8266 OpenOCD tutorial:openocd
  6. Press Finish to build the project. Uncomment the call to system_soft_wdt_stop() and build the project by pressing Ctrl-Shift-B:06-build
  7. Once the build is done, set a breakpoint after the call to wifi_softap_get_config() and hit F5 to start debugging. VisualGDB will program the SPI FLASH and start the program:07-load
  8. When the breakpoint is hit, hover the mouse over the “cfg” variable to see the current WiFi configuration. The test program will replace the SSID with the name selected in the wizard and apply it by calling wifi_softap_set_config_current():08-step
  9. If you have disabled the software watchdog earlier, you can step through the initialization function and observe what it does. Note that it starts the DHCP server so that you won’t need to configure network parameters manually:09-accept
  10. Hit F5 to resume the program. Open the WiFi network list on your PC and connect to the ESP8266 network:10-network
  11. Use the “ipconfig” command to verify that you have connected to the network and that the IP address has been assigned:11-ipaddr
  12. Open the page in your browser and observe the output generated by the ESP8266 chip:12-helloEach time you refresh the page, the counter should increase.
  13. You can reset the ESP8266 firmware by pressing the Reset button in the GDB Session window:13-reset
  14. You can also set a breakpoint in the HTTP-related code, however if you spend more than 1 second stopped at it, the ESP8266 chip will restart as many library functions reenable the software watchdog after we have disabled it in user_init. Disabling the software watchdog from the function you want to debug will partially solve this problem, but it may interfere with other WiFi functionality:   14-edit
  15. If you have connected the serial port on your ESP8266 board to a USB-to-COM circuit, you can enable the Raw Terminal in VisualGDB Project Properties. The baud rate depends on the speed of the on-board crystal and should be set to 74880 for the Olimex ESP8266 module with a 26 MHz crystal: 15-comport
  16. If you start your program now, you will see a lot of debug output shown by the ESP8266 firmware:16-log
  17. You can add your own messages to the debug output by calling the os_printf() function. Note that you will need to declare the os_printf_plus() one to do that, as the ESP8266 SDK does not include a definition for it:17-serveThe main compilation with the ESP8266 IoT SDK is that it is single-threaded, so your code needs to be consist of callback functions and event handlers that cannot take too much time. In order to use a more convenient thread approach, try the ESP8266 RTOS SDK, that is described in the next tutorial.