|
| 1 | +.. _example_esp8266_wifi: |
| 2 | + |
| 3 | +ESP8266 WiFi Module |
| 4 | +#################### |
| 5 | + |
| 6 | +Overview |
| 7 | +******** |
| 8 | + |
| 9 | + This example is designed to show basic usage of ESP01/ESP01S esp8266 WiFi Module on embARC board. |
| 10 | + |
| 11 | +Detailed Description |
| 12 | +==================== |
| 13 | + |
| 14 | + * Extra Required Peripherals |
| 15 | + ESP01/ESP01S WiFi Module |
| 16 | + |
| 17 | + * Design Concept |
| 18 | + Without downloading users' image, ESP01/ESP01S can be controlled using AT commands. |
| 19 | + This example is designed to show how to use AT commands to control the Wi-Fi module and exchange data. |
| 20 | + Besides, we use AT command to establish a TCP server and provide simple HTTP service just like our another example :ref:`example_net_httpserver` |
| 21 | + |
| 22 | + * Usage Manual |
| 23 | + - Connect ESP01/ESP01S module to your board, see :ref:`peripheral_preparation`. |
| 24 | + - Set up an AP, the default setting of this example is to connect a WIFI with SSID: `embARC`, pwd: `qazwsxedc`. |
| 25 | + - Build, download, run the example and get log from COM port console. |
| 26 | + - When you see a `while` is shown in log, meaning that the server is setup and waiting for input. Then open your web browser (Chrome, Firefox) and visit the ip address shown in the log. You will get a web page right away. |
| 27 | + |
| 28 | +Building and Running |
| 29 | +******************** |
| 30 | + |
| 31 | +This example outputs to the console. It is supported by all platform. The commands to run this example are as follows: |
| 32 | + |
| 33 | +.. code-block:: console |
| 34 | +
|
| 35 | + $ cd <embarc_root>/example/freertos/esp8266_wifi |
| 36 | + $ make BOARD=emsk BD_VER=22 CUR_CORE=arcem7d TOOLCHAIN=gnu run |
| 37 | +
|
| 38 | +
|
| 39 | +Sample Output |
| 40 | +============= |
| 41 | + |
| 42 | +.. code-block:: console |
| 43 | +
|
| 44 | + ----------------------------------------------------------- |
| 45 | + ____ _ ____ |
| 46 | + | _ \ _____ _____ _ __ ___ __| | __ ) _ _ |
| 47 | + | |_) / _ \ \ /\ / / _ \ '__/ _ \/ _` | _ \| | | | |
| 48 | + | __/ (_) \ V V / __/ | | __/ (_| | |_) | |_| | |
| 49 | + |_| \___/ \_/\_/ \___|_| \___|\__,_|____/ \__, | |
| 50 | + |___/ |
| 51 | + _ _ ____ ____ |
| 52 | + ___ _ __ ___ | |__ / \ | _ \ / ___| |
| 53 | + / _ \ '_ ` _ \| '_ \ / _ \ | |_) | | |
| 54 | + | __/ | | | | | |_) / ___ \| _ <| |___ |
| 55 | + \___|_| |_| |_|_.__/_/ \_\_| \_\\____| |
| 56 | + ------------------------------------------------------------ |
| 57 | +
|
| 58 | + embARC Build Time: Oct 17 2018, 15:25:42 |
| 59 | + Compiler Version: Metaware, 4.2.1 Compatible Clang 4.0.1 (branches/release_40) |
| 60 | + =========================== Init ============================ |
| 61 | + [at_parser_init]56: obj->psio 0x800062c0 -> 0x80000f28 |
| 62 | + [at_send_cmd]83: command is NULL, send AT test command |
| 63 | + [at_send_cmd]117: at_out: "AT |
| 64 | + " (4) |
| 65 | + [at_get_reply]137: "AT |
| 66 | +
|
| 67 | + OK" (9) |
| 68 | + ============================ Set Mode ============================ |
| 69 | + [at_send_cmd]117: at_out: "AT+CWMODE_CUR? |
| 70 | + " (16) |
| 71 | + [at_get_reply]137: " |
| 72 | + AT+CWMODE_CUR? |
| 73 | + +CWMODE_CUR:1 |
| 74 | +
|
| 75 | + OK" (38) |
| 76 | + CWMODE_CUR = 1 |
| 77 | + [at_send_cmd]117: at_out: "AT+CWMODE_CUR=3 |
| 78 | + " (17) |
| 79 | + [at_get_reply]137: " |
| 80 | + AT+CWMODE_CUR=3 |
| 81 | +
|
| 82 | + OK" (24) |
| 83 | + ============================ Connect WiFi ============================ |
| 84 | + [at_send_cmd]117: at_out: "AT+CWLAP |
| 85 | + " (10) |
| 86 | + [at_get_reply]137: " |
| 87 | + AT+CWLAP |
| 88 | + +CWLAP:(3,"embARC",-61,"6a:ec:c5:cc:2f:3b",1,32767,0) |
| 89 | + +CWLAP:(5,"Synopsys",-91,"6c:f3:7f:a5:8a:e3",1,-49,0) |
| 90 | + +CWLAP:(0,"synopsys-guest",-81,"6c:f3:7f:a5:38:21",1,-47,0) |
| 91 | + +CWLAP:(5,"Synopsys",-81,"6c:f3:7f:a5:38:23",1,-47,0) |
| 92 | + +CWLAP:(3,"ClickShare-1871789077",-87,"28:24:ff:bf:2b:06",1,32767,0) |
| 93 | + +CWLAP:(0,"synopsys-guest",-91,"6c:f3:7f:a5:8a:e1",1,-47,0) |
| 94 | + +CWLAP:(5,"Synopsys",-86,"04:bd:88:5a:7c:42",6,-51,0) |
| 95 | + +CWLAP:(0,"synopsys-guest",-86,"04:bd:88:5a:7c:43",6,-51,0) |
| 96 | + +CWLAP:(0,"synopsys-guest",-73,"6c:f3:7f:a2:90:61",11,-54,0) |
| 97 | + +CWLAP:(5,"Synopsys",-71,"6c:f3:7f:a2:90:63",11,-56,0) |
| 98 | + +CWLAP:(3,"XKORAT - Mi",-71,"4c:49:e3:ba:95:80",11,-29,0) |
| 99 | +
|
| 100 | + OK" (731) |
| 101 | + Searching for WIFI "embARC" ...... |
| 102 | + WIFI "embARC" found! Try to connect |
| 103 | + [at_send_cmd]117: at_out: "AT+CWMODE_CUR=1 |
| 104 | + " (17) |
| 105 | + [at_get_reply]137: " |
| 106 | + AT+CWMODE_CUR=1 |
| 107 | +
|
| 108 | + OK" (24) |
| 109 | + [at_send_cmd]117: at_out: "AT+CWJAP_CUR="embARC","qazwsxedc" |
| 110 | + " (35) |
| 111 | + [at_get_reply]137: " |
| 112 | + AT+CWJAP_CUR="embARC","qazwsxedc" |
| 113 | + WIFI DISCONNECT |
| 114 | + WIFI CONNECTED |
| 115 | + WIFI GOT IP |
| 116 | +
|
| 117 | + OK" (88) |
| 118 | + WIFI "embARC" connect succeed |
| 119 | + ============================ Connect Server ============================ |
| 120 | + [at_send_cmd]117: at_out: "AT+CIPMUX=1 |
| 121 | + " (13) |
| 122 | + [at_get_reply]137: " |
| 123 | + AT+CIPMUX=1 |
| 124 | +
|
| 125 | + OK" (20) |
| 126 | + [at_send_cmd]117: at_out: "AT+CIPSERVER=1,80 |
| 127 | + " (19) |
| 128 | + [at_get_reply]137: " |
| 129 | + AT+CIPSERVER=1,80 |
| 130 | + no change |
| 131 | +
|
| 132 | + OK" (37) |
| 133 | + ============================ Show IP ============================ |
| 134 | + [at_send_cmd]117: at_out: "AT+CIFSR |
| 135 | + " (10) |
| 136 | + [at_get_reply]137: " |
| 137 | + AT+CIFSR |
| 138 | + +CIFSR:STAIP,"192.168.137.96" |
| 139 | + +CIFSR:STAMAC,"5c:cf:7f:0c:27:d6" |
| 140 | +
|
| 141 | + OK" (83) |
| 142 | + ============================ while ============================ |
| 143 | + ============================ send ============================ |
| 144 | +
|
| 145 | + The message is: |
| 146 | + 0,CONNECT |
| 147 | + 1,CONNECT |
| 148 | +
|
| 149 | + +IPD,0,383:GET / HTTP/1.1 |
| 150 | + Host: 192.168.137.96 |
| 151 | + Connection: keep-alive |
| 152 | + Upgrade-Insecure-Requests: 1 |
| 153 | + User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 |
| 154 | + Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 |
| 155 | + Accept-Encoding: gzip, deflate |
| 156 | + Accept-Language: en-US,en;q=0.9 |
| 157 | +
|
| 158 | +
|
| 159 | + Send Start |
| 160 | + [at_send_cmd]117: at_out: "AT+CIPSEND=0,44 |
| 161 | + " (17) |
| 162 | + [at_get_reply]137: "AT+CIPSEND=0,44 |
| 163 | +
|
| 164 | + OK" (22) |
| 165 | + [at_get_reply]137: " |
| 166 | + > |
| 167 | + Recv 44 bytes |
| 168 | +
|
| 169 | + SEND OK" (30) |
| 170 | + [at_send_cmd]117: at_out: "AT+CIPSEND=0,93 |
| 171 | + " (17) |
| 172 | + [at_get_reply]137: " |
| 173 | + AT+CIPSEND=0,93 |
| 174 | +
|
| 175 | + OK" (24) |
| 176 | + [at_get_reply]137: " |
| 177 | + > |
| 178 | + Recv 93 bytes |
| 179 | + " (21) |
| 180 | + [at_send_cmd]117: at_out: "AT+CIPSEND=0,93 |
| 181 | + " (17) |
| 182 | + [at_get_reply]137: "AT+CIPSEND=0,93 |
| 183 | + busy s... |
| 184 | + " (29) |
| 185 | + [at_send_cmd]117: at_out: "AT+CIPCLOSE=0 |
| 186 | + " (15) |
| 187 | + [at_get_reply]137: "AT+CIPCLOSE=0 |
| 188 | + busy s... |
| 189 | +
|
| 190 | + SEND OK" (36) |
| 191 | + Send Finish |
| 192 | +
|
0 commit comments