{"id":594,"date":"2015-08-25T16:09:17","date_gmt":"2015-08-25T23:09:17","guid":{"rendered":"http:\/\/visualgdb.com\/w\/?p=594"},"modified":"2017-05-26T10:31:23","modified_gmt":"2017-05-26T17:31:23","slug":"creating-a-simple-wifi-http-server-with-esp8266-and-visualgdb","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/esp8266\/http\/","title":{"rendered":"Creating a simple WiFi HTTP Server using ESP8266"},"content":{"rendered":"<p>This tutorial shows how to create a basic WiFi HTTP server with the ESP8266 chip and VisualGDB. Before you begin, follow our <a href=\"http:\/\/visualgdb.com\/tutorials\/esp8266\/openocd\/\">ESP8266 OpenOCD tutorial<\/a> to ensure that you can program your ESP8266 board.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-wiz.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-595\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-wiz.png\" alt=\"01-wiz\" width=\"800\" height=\"490\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-wiz.png 800w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/01-wiz-300x184.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/li>\n<li>Proceed with the default &#8220;embedded binary&#8221; setting on the first page:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-embeddedbin.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-596\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-embeddedbin.png\" alt=\"02-embeddedbin\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-embeddedbin.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/02-embeddedbin-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>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 &#8220;no FLASH&#8221; mode:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-device7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-597\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-device7.png\" alt=\"03-device\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-device7.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/03-device7-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>On the sample page Select the HTTP Server (IoT SDK):<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-http.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-598\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-http.png\" alt=\"04-http\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-http.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/04-http-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>On the debug method page specify the debug settings that worked with the <a href=\"http:\/\/visualgdb.com\/tutorials\/esp8266\/openocd\/\">ESP8266 OpenOCD tutorial<\/a>:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/openocd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1178\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/openocd.png\" alt=\"openocd\" width=\"702\" height=\"571\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/openocd.png 702w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/openocd-300x244.png 300w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><\/a><\/li>\n<li>Press Finish to build the project. Uncomment the call to system_soft_wdt_stop() and build the project by pressing Ctrl-Shift-B:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-build4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-600\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-build4.png\" alt=\"06-build\" width=\"699\" height=\"607\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-build4.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/06-build4-300x261.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>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:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-load.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-601\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-load.png\" alt=\"07-load\" width=\"684\" height=\"382\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-load.png 684w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/07-load-300x168.png 300w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/a><\/li>\n<li>When the breakpoint is hit, hover the mouse over the &#8220;cfg&#8221; 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():<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-step.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-602\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-step.png\" alt=\"08-step\" width=\"699\" height=\"605\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-step.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/08-step-300x260.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>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&#8217;t need to configure network parameters manually:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-accept.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-603\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-accept.png\" alt=\"09-accept\" width=\"699\" height=\"606\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-accept.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/09-accept-300x260.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>Hit F5 to resume the program. Open the WiFi network list on your PC and connect to the ESP8266 network:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-network.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-604\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-network.png\" alt=\"10-network\" width=\"280\" height=\"395\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-network.png 280w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/10-network-213x300.png 213w\" sizes=\"(max-width: 280px) 100vw, 280px\" \/><\/a><\/li>\n<li>Use the &#8220;ipconfig&#8221; command to verify that you have connected to the network and that the IP address has been assigned:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-ipaddr.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-605\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-ipaddr.png\" alt=\"11-ipaddr\" width=\"677\" height=\"294\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-ipaddr.png 677w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/11-ipaddr-300x130.png 300w\" sizes=\"(max-width: 677px) 100vw, 677px\" \/><\/a><\/li>\n<li>Open the 192.168.123.1 page in your browser and observe the output generated by the ESP8266 chip:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-hello.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-606\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-hello.png\" alt=\"12-hello\" width=\"676\" height=\"279\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-hello.png 676w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/12-hello-300x124.png 300w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><\/a>Each time you refresh the page, the counter should increase.<\/li>\n<li>You can reset the ESP8266 firmware by pressing the Reset button in the GDB Session window:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-reset.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-607\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-reset.png\" alt=\"13-reset\" width=\"699\" height=\"605\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-reset.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/13-reset-300x260.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>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: \u00a0 <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-edit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-608\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-edit.png\" alt=\"14-edit\" width=\"699\" height=\"605\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-edit.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/14-edit-300x260.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>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: <a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-comport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-609\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-comport.png\" alt=\"15-comport\" width=\"773\" height=\"745\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-comport.png 773w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/15-comport-300x289.png 300w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/a><\/li>\n<li>If you start your program now, you will see a lot of debug output shown by the ESP8266 firmware:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-log2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-610\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-log2.png\" alt=\"16-log\" width=\"699\" height=\"608\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-log2.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/16-log2-300x261.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a><\/li>\n<li>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:<a href=\"http:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-serve.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-611\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-serve.png\" alt=\"17-serve\" width=\"699\" height=\"605\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-serve.png 699w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2015\/08\/17-serve-300x260.png 300w\" sizes=\"(max-width: 699px) 100vw, 699px\" \/><\/a>The 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.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a basic WiFi HTTP server with the ESP8266 chip and VisualGDB. Before you begin,<\/p>\n","protected":false},"author":1,"featured_media":612,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[142],"tags":[100,101,56,102],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/594"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=594"}],"version-history":[{"count":5,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/594\/revisions"}],"predecessor-version":[{"id":1181,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/594\/revisions\/1181"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media\/612"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=594"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}