Skip to content

Commit

Permalink
doc: update the doc
Browse files Browse the repository at this point in the history
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
  • Loading branch information
Wayne Ren committed Dec 13, 2018
1 parent 7ba8907 commit dfb9e1a
Showing 1 changed file with 62 additions and 65 deletions.
127 changes: 62 additions & 65 deletions doc/documents/labs/level2/lab10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
A WiFi temperature monitor
===========================

ESPB266 WiFi module
----------------------

Purpose
^^^^^^^^

Expand Down Expand Up @@ -62,108 +59,108 @@ Ai-Thinker company has developed several WiFi modules based on ESP8266, includin
#include "embARC.h"
#include "embARC_debug.h"
#include "board.h"
#include "esp8266.h"
#include <stdio.h>
#include <string.h>
#define WIFI_SSID "\"embARC\""
#define WIFI_PWD "\"qazwsxedc\""
static char http_get[] = "GET /";
static char http_IDP[] = "+IPD,";
static char http_html_header[] = "HTTP/1.x 200 OK\r\nContent-type: text/html\r\n\r\n";
static char http_html_body_1[] =
"<html><head><title>ESP8266_AT_HttpServer</title></head><body><h1>Welcome to this Website</h1>";
static char http_html_body_2[] =
"<p>This Website is used to test the AT command about HttpServer of ESP8266.</p></body></html>";
static char http_server_buf[1024];
int main(void)
{
char *conn_buf;
//ESP8266 Init
EMBARC_PRINTF("============================ Init ============================\n");
ESP8266_DEFINE(esp8266);
esp8266_init(esp8266, UART_BAUDRATE_115200);
at_test(esp8266->p_at);
board_delay_ms(100, 1);
//Set Mode
EMBARC_PRINTF("============================ Set Mode ============================\n");
esp8266_wifi_mode_get(esp8266, false);
board_delay_ms(100, 1);
esp8266_wifi_mode_set(esp8266, 3, false);
board_delay_ms(100, 1);
//Connect WiFi
EMBARC_PRINTF("============================ Connect WiFi ============================\n");
do {
esp8266_wifi_scan(esp8266, http_server_buf);
EMBARC_PRINTF("Searching for WIFI %s ......\n", WIFI_SSID);
board_delay_ms(100, 1);
} while (strstr(http_server_buf, WIFI_SSID)==NULL);
EMBARC_PRINTF("WIFI %s found! Try to connect\n", WIFI_SSID);
while (esp8266_wifi_connect(esp8266, WIFI_SSID, WIFI_PWD, false) != AT_OK) {
EMBARC_PRINTF("WIFI %s connect failed\n", WIFI_SSID);
board_delay_ms(100, 1);
}
EMBARC_PRINTF("WIFI %s connect succeed\n", WIFI_SSID);
//Creat Server
EMBARC_PRINTF("============================ Connect Server ============================\n");
esp8266_tcp_server_open(esp8266, 80);
//Show IP
EMBARC_PRINTF("============================ Show IP ============================\n");
esp8266_address_get(esp8266);
board_delay_ms(1000, 1);
while (1) {
memset(http_server_buf, 0, sizeof(http_server_buf));
at_read(esp8266->p_at ,http_server_buf ,1000);
board_delay_ms(200, 1);
//EMBARC_PRINTF("Alive\n");
if (strstr(http_server_buf, http_get) != NULL) {
EMBARC_PRINTF("============================ send ============================\n");
EMBARC_PRINTF("\nThe message is:\n%s\n", http_server_buf);
conn_buf = strstr(http_server_buf, http_IDP) + 5;
*(conn_buf+1) = 0;
EMBARC_PRINTF("Send Start\n");
board_delay_ms(10, 1);
esp8266_connect_write(esp8266, http_html_header, conn_buf, (sizeof(http_html_header)-1));
board_delay_ms(100, 1);
esp8266_connect_write(esp8266, http_html_body_1, conn_buf, (sizeof(http_html_body_1)-1));
board_delay_ms(300, 1);
esp8266_connect_write(esp8266, http_html_body_2, conn_buf, (sizeof(http_html_body_2)-1));
board_delay_ms(300, 1);
esp8266_CIPCLOSE(esp8266, conn_buf);
EMBARC_PRINTF("Send Finish\n");
}
}
return E_OK;
}
Expand Down Expand Up @@ -214,22 +211,22 @@ At this point, feedback information is shown on your serial port console, repres
[at_send_cmd]131: at_out: "AT
" (4)
[at_get_reply]154: "AT
OK" (9)
============================ Set Mode ============================
[at_send_cmd]131: at_out: "AT+CWMODE_CUR?
" (16)
[at_get_reply]154: "
AT+CWMODE_CUR?
+CWMODE_CUR:1
OK" (38)
CWMODE_CUR = 1
[at_send_cmd]131: at_out: "AT+CWMODE_CUR=3
" (17)
[at_get_reply]154: "
AT+CWMODE_CUR=3
OK" (24)
============================ Connect WiFi ============================
[at_send_cmd]131: at_out: "AT+CWLAP
Expand All @@ -243,15 +240,15 @@ At this point, feedback information is shown on your serial port console, repres
+CWLAP:(0,"iFuture",-94,"d4:68:ba:06:65:4a",1,-16,0)
+CWLAP:(4,"iFuture_City",-93,"d4:68:ba:0e:65:09",3,-4,0)
+CWLAP:(3,"embARC",-62,"5e:e0:c5:4f:df:80",6,32767,0)
OK" (416)
Searching for WIFI "embARC" ......
WIFI "embARC" found! Try to connect
[at_send_cmd]131: at_out: "AT+CWMODE_CUR=1
" (17)
[at_get_reply]154: "
AT+CWMODE_CUR=1
OK" (24)
[at_send_cmd]131: at_out: "AT+CWJAP_CUR="embARC","qazwsxedc"
" (35)
Expand All @@ -260,22 +257,22 @@ At this point, feedback information is shown on your serial port console, repres
WIFI DISCONNECT
WIFI CONNECTED
WIFI GOT IP
OK" (88)
WIFI "embARC" connect succeed
============================ Connect Server ============================
[at_send_cmd]131: at_out: "AT+CIPMUX=1
" (13)
[at_get_reply]154: "
AT+CIPMUX=1
OK" (20)
[at_send_cmd]131: at_out: "AT+CIPSERVER=1,80
" (19)
[at_get_reply]154: "
AT+CIPSERVER=1,80
no change
OK" (37)
============================ Show IP ============================
[at_send_cmd]131: at_out: "AT+CIFSR
Expand All @@ -284,7 +281,7 @@ At this point, feedback information is shown on your serial port console, repres
AT+CIFSR
+CIFSR:STAIP,"192.168.137.236"
+CIFSR:STAMAC,"5c:cf:7f:0b:5f:9a"
OK" (84)
**Access server**
Expand All @@ -296,11 +293,11 @@ At this point, use a PC or mobile phone to connect to the same WiFi, open a brow
.. code-block:: console
============================ send ============================
The message is:
0,CONNECT
1,CONNECT
+IPD,0,384:GET / HTTP/1.1
Host: 192.168.137.236
Connection: keep-alive
Expand All @@ -309,53 +306,53 @@ At this point, use a PC or mobile phone to connect to the same WiFi, open a brow
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Send Start
[at_send_cmd]131: at_out: "AT+CIPSEND=0,44
" (17)
[at_get_reply]154: "AT+CIPSEND=0,44
OK" (22)
[at_get_reply]154: "
>
Recv 44 bytes
SEND OK" (30)
[at_send_cmd]131: at_out: "AT+CIPSEND=0,93
" (17)
[at_get_reply]154: "
AT+CIPSEND=0,93
OK" (24)
[at_get_reply]154: "
>
Recv 93 bytes
SEND OK" (30)
[at_send_cmd]131: at_out: "AT+CIPSEND=0,93
" (17)
[at_get_reply]154: "
AT+CIPSEND=0,93
OK" (24)
[at_get_reply]154: "
>
Recv 93 bytes
SEND OK" (30)
[at_send_cmd]131: at_out: "AT+CIPCLOSE=0
" (15)
[at_get_reply]154: "
AT+CIPCLOSE=0
0,CLOSED
OK" (32)
Send Finish
============================ send ============================
The message is:
+IPD,1,353:GET /favicon.ico HTTP/1.1
Host: 192.168.137.236
Connection: keep-alive
Expand All @@ -364,47 +361,47 @@ At this point, use a PC or mobile phone to connect to the same WiFi, open a brow
Referer: http://192.168.137.236/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Send Start
[at_send_cmd]131: at_out: "AT+CIPSEND=1,44
" (17)
[at_get_reply]154: "AT+CIPSEND=1,44
OK" (22)
[at_get_reply]154: "
>
Recv 44 bytes
SEND OK" (30)
[at_send_cmd]131: at_out: "AT+CIPSEND=1,93
" (17)
[at_get_reply]154: "
AT+CIPSEND=1,93
OK" (24)
[at_get_reply]154: "
>
Recv 93 bytes
SEND OK" (30)
[at_send_cmd]131: at_out: "AT+CIPSEND=1,93
" (17)
[at_get_reply]154: "
AT+CIPSEND=1,93
OK" (24)
[at_get_reply]154: "
>
Recv 93 bytes
SEND OK" (30)
[at_send_cmd]131: at_out: "AT+CIPCLOSE=1
" (15)
[at_get_reply]154: "
AT+CIPCLOSE=1
1,CLOSED
OK" (32)
Send Finish
Expand Down

0 comments on commit dfb9e1a

Please sign in to comment.