Creating a Basic HTTP Server with ESP32

This tutorial shows how to create a basic “HTTP Server” application for the ESP32 chip and debug it with VisualGDB. We will use the Sparkfun ESP32 Thing board with the Olimex ARM-USB-OCD-H JTAG programmer to program and debug the board.

Before you begin, install VisualGDB 5.2 or later. We also recommend following the basic ESP32 tutorial to check that the JTAG connection with your device is working properly.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:01-demoprjname
  2. Proceed with the default settings on the first page:02-msbuild
  3. Select the ESP32 toolchain and the regular ESP32 device:03-esp32
  4. On the Sample Selection page select the “HTTP Server” sample and optionally change the subnet number:04-server
  5. Finally select the interface you want to use for debugging. If you are using one of the Olimex JTAG debuggers, enable the “set explicit speed” checkbox:05-debug
  6. Press “Finish” to generate your project. Before you can build it, open the Project Properties and change the optimization level for the debug configuration from -O0 to -Og as the default -O0 level prevents the ESP-IDF code from working correctly:06-optimize
  7. The project generated by VisualGDB does 3 vital steps. First it enables the DHCP server so that the devices connecting to its Wi-Fi network will automatically get assigned IP addresses:

    Then it starts the Wi-Fi hardware in the Access Point mode:

    Finally it creates a thread that listens for connections on port 80 and responds to each one. Note that the last part uses the regular socket functions like bind() and accept() to work with the sockets:
  8. The project is based on the open-source ESP-IDF framework, so you can use features like Go-to-definition and Code Map to quickly explore how different functions interact:codemap
  9. Build the project via Build->Build Solution:07-build
  10. Now press F5 to automatically program the SPI FLASH and begin debugging your project:08-load
  11. Once the project is running, connect to the ESP32_VisualGDB Wi-Fi network from your device:09-wifi
  12. Once the connection is successful, open 192.168.<subnet>.1 in your browser:10-page
  13. Set a breakpoint after the call to read() and refresh your browser page. The breakpoint will hit and you will see the HTTP request sent your the browser to the device:11-watchNote that the ESP32 tools have several known limitations. Please refer to this post for a discussion on known issues and workarounds.