【安信可BW16-Kit】AT指令体验之WiFi HTTP
<div class='showpostmsg'># 【安信可BW16-Kit】AT指令体验之WiFi HTTP## 连接WiFi
### 01 设置模式 STA
命令: ```AT+WMODE=<MODE>,<save_flash>```
参数1:```<MODE>```Wi-Fi工作模式(0:未初始化或者关闭Wi-Fi 1:STA 2:AP 3:AP+STA)
参数2:```<save_flash>```是否保存到flash(0:不保存 1:保存)
```c
AT+WMODE=1,0
WIFI is already runningwifi start success
OK
After do cmd, available heap 160064
```
### 02 查找WiFi
```c
AT+WSCAN
+WSCAN:index SSID,CH,SECURITY,RSSI,BSSID
1 wenhou,1,WPA/WPA2 AES,-42,a4:1a:3a:5d:56:08
2 ,1,WPA/WPA2 AES,-44,a6:1a:3a:2d:56:08
3 wh5,153,WPA/WPA2 AES,-48,a4:1a:3a:5d:56:0a
4 ,153,WPA/WPA2 AES,-48,a6:1a:3a:5d:56:08
OK
After do cmd, available heap 160064
```
### 03 连接WiFi
命令: ```AT+WJAP=<ssid>,<pwd>[,<bssid>]```
参数1:```<ssid>```连接的AP的SSID(最大长度为32字节)
参数2:```<pwd>```连接的AP的密码(最大长度为32字节)
参数3:```<bssid>```连接的AP的BSSID(一般不用)
```c
AT+WJAP=wenhou,password
Connect to wenhou
RTL8721D: set ssid
RTL8721D: rtw_set_wpa_ie: AuthKeyMgmt = 0x2
RTL8721D: rtw_restruct_sec_ie: no pmksa cached
RTL8721D: start auth to a4:1a:3a:5d:56:08
RTL8721D: auth alg = 2
RTL8721D:
OnAuthClient:algthm = 0, seq = 2, status = 0, sae_msg_len = 0
RTL8721D: auth success, start assoc
RTL8721D: association success(res=3)
RTL8721D: ClientSendEAPOL: no use cache pmksa
RTL8721D: set pairwise key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4)
RTL8721D: set group key to hw: alg:4(WEP40-1 WEP104-5 TKIP-2 AES-4) keyid:2
(220)wenhou
+EVENT:WIFI_CONNECT
+EVENT:WIFI_GOT_IP
socket auto TT not set
Interface 0 IP address : 192.168.1.100
OK
After do cmd, available heap 152032
```
### 04 AT+WAUTOCONN 上电自动重连Wi-Fi
命令: ```AT+WAUTOCONN=<status>```
参数1:```<status>```0:禁用 1:使能
## HTTP通信
命令: ```AT+HTTPCLIENTLINE=<transport_type>,<opt>,<content-type>,<host>,<port>,<path>[,<data>]```
参数1:```<transport_type>```请求协议(1:HTTP 2:HTTPS)
参数2:```<opt>```请求类型(2:GET 3:POST)
参数3:```<content-type>```请求数据类型,仅 POST 生效,可以填写任意字符串,参考类型如下(```application/x-www-form-urlencoded``` ```application/json``` ```multipart/form-data``` ```text/xml``` ```text/html```)
参数4:```<host>```服务器域名或 IP(www.baidu.com 或 192.168.1.100)
参数5:```<port>```端口号(HTTP 缺省值80 HTTPS 缺省值443)
参数6:```<path>```HTTP(S)路径(缺省值”/”)
参数7:```<data>```请求携带的数据(如下)
1:当opt为GET时接在path中的,格式(?key1=value1&key2=value2 …)
2:当opt为POST时这个是POST携带的主体。
示例GET
```c
AT+HTTTPCLIENTLINE=1,2,"application/x-www-form-urlencoded","httpbin.org",80,"/get?key1=123&key2=456"
Request:
GET /get?key1=123&key2=456 HTTP/1.1
Host: httpbin.org
need send len=58 ,send succest len=58
curren parse data len 230
get bodylen=256
{
"args": {
"key1": "123",
"key2": "456"
},
"headers": {
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-65cf25c0-7cc21e33360f850d6c15f176"
},
"origin": "118.74.161.3",
"url": "http://httpbin.org/get?key1=123&key2=456"
}
OK
After do cmd, available heap 152032
```
示例POST
```c
AT+HTTTPCLIENTLINE=1,3,"application/json","httpbin.org",80,"/post",{"key1": 123}
Request:
POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json
Content-Length: 13
{"key1": 123}
need send len=107 ,send succest len=107
curren parse data len 230
get bodylen=363
{
"args": {},
"data": "{\"key1\": 123}",
"files": {},
"form": {},
"headers": {
"Content-Length": "13",
"Content-Type": "application/json",
"Host": "httpbin.org",
"X-Amzn-Trace-Id": "Root=1-65cf2617-2251e9f04b427bc40c26c29c"
},
"json": {
"key1": 123
},
"origin": "118.74.161.3",
"url": "http://httpbin.org/post"
}
OK
After do cmd, available heap 152032
```
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>AT指令用于WiFi HTTP看起来挺方便的,,,</p>
页:
[1]