|
Arduino+ESP8266五个他ESP8266HTTPClient.h获取网页信息,不断重启,打印内容如下:
rl\0l恟$鈔?l?b|帎抮b?b騨nlnnbbp?blrlp騨??l?bn鈔??b尿nn'l?l`?nn$`nr帓抧rr抈p騨r?bbn鈔b尿nn'l`?nn$`nr帓抧rl`r拻nrl`?膸ll`鼈n抈......
WiFi Connected!URL: http://www.example.com
Send GET request to URL: http://www.example.com
Server Response Payload:
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Exception (9):
epc1=0x402125ec epc2=0x00000000 epc3=0x00000000 excvaddr=0x000001fe depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffc90 end: 3fffffc0 offset: 0190
3ffffe20: 00000000 00000000 4bc6a7f0 00000000
3ffffe30: 3ffee9c8 00000000 40100205 00000000
3ffffe40: 00002826 3ffef438 00001a14 00000000
3ffffe50: 000001bd 000001bd 3ffe85e4 ffffffff
3ffffe60: 00002826 3fffff64 3ffef4f4 40201bf0
3ffffe70: 0000012c 00000020 3ffef434 3ffee644
3ffffe80: 000000c8 00000020 3ffef4f4 3ffee644
3ffffe90: 000000c8 3fffff64 00000001 40202081
3ffffea0: 000000c8 00000000 3ffefc84 402020b5
3ffffeb0: 000000c8 3ffffee0 3ffee5b4 402020dc
3ffffec0: 00000000 3ffe87ea 3ffee5b4 402023d8
3ffffed0: 000000c8 3ffe87ea 3ffee5b4 40201188
3ffffee0: 3fffff64 3ffef6ac 000f000f 80000000
3ffffef0: 5f010050 3f001388 00000000 4023874a
3fffff00: 00000000 70747468 00000000 04000000
3fffff10: 3ffef87c 0000001f 80000000 3ffef814
3fffff20: 0011001f 80000000 00000000 40205d44
3fffff30: 00000000 00000000 00000000 00000000
3fffff40: ffffffff 248b9d01 00000000 3ffe000a
3fffff50: 00000000 3ffe87da 00000000 00000000
3fffff60: 00000000 40207dac 00000000 00001388
3fffff70: 0000270f 00000000 00000000 3ffef4f4
3fffff80: 00000000 00000000 04e804ef 00000000
3fffff90: 3fffdad0 00000000 3ffee630 402011ae
3fffffa0: feefeffe 00000000 3ffee630 40204dc8
3fffffb0: feefeffe feefeffe 3ffe85e0 40100b51
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v00046310
~ld
..
原代码参考:
http://www.taichi-maker.com/home ... tpclient/getstring/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
// 测试HTTP请求用的URL
#define URL "http://www.example.com"
// 设置wifi接入信息(请根据您的WiFi信息进行修改)
const char* ssid = "你的WIFI";
const char* password = "WIFI密码";
void setup() {
//初始化串口设置
Serial.begin(115200);
//设置ESP8266工作模式为无线终端模式
WiFi.mode(WIFI_STA);
//开始连接wifi
WiFi.begin(ssid, password);
//等待WiFi连接,连接成功打印IP
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi Connected!");
}
void loop()
{
// 如果ESP8266连接WiFi则发送HTTP请求
if ((WiFi.status() == WL_CONNECTED))
{
esp8266Http();
}
delay(5000); // 短暂等待
}
// 发送HTTP请求并且将服务器响应通过串口输出
void esp8266Http()
{
//创建 HTTPClient 对象
HTTPClient httpClient;
WiFiClient clien; //
httpClient.begin(clien, URL); //
Serial.print("URL: "); Serial.println(URL);
//启动连接并发送HTTP请求
int httpCode = httpClient.GET();
Serial.print("Send GET request to URL: ");
Serial.println(URL);
//如果服务器响应OK则从服务器获取响应体信息并通过串口输出
//如果服务器不响应OK则将服务器响应状态码通过串口输出
if (httpCode == HTTP_CODE_OK)
{
String responsePayload = httpClient.getString();
Serial.println("Server Response Payload: ");
Serial.println(responsePayload);
}
else
{
Serial.println("Server Respose Code:");
Serial.println(httpCode);
}
//关闭ESP8266与服务器连接
httpClient.end();
}
请大佬分析一下,这是为什么?如何 解决? |
|