web服务器不稳定,不稳定的Arduino Web服务器

我一直在尝试使用Arduino设置Web服务器 . 我有一台UNO和一台HanRun HR91105A我上网了,我正在使用WebServer示例的修改版来测试我的代码 . 事实上它确实起作用了 . 但是在设置端口转发后,连接突然变得不稳定 . 它连接并工作几分钟,然后突然我甚至无法ping它 . 尝试ping Arduino会导致请求超时 . 在线研究表明有两种可能:

1.)所有RAM都用完了

2.)以太网屏蔽有故障

以下是我的代码

#include

#include

// Enter a MAC address and IP address for your controller below.

// The IP address will be dependent on your local network:

byte mac[] = {

0x44, 0x00, 0x10, 0x20, 0x8C, 0x0A

};

IPAddress ip(192,168,1,90);

// Initialize the Ethernet server library

// with the IP address and port you want to use

// (port 80 is default for HTTP):

EthernetServer server(8081);

void setup() {

// Open serial communications and wait for port to open:

Serial.begin(9600);

while (!Serial) {

; // wait for serial port to connect. Needed for native USB port only

}

// start the Ethernet connection and the server:

Ethernet.begin(mac, ip);

server.begin();

Serial.print("server is at ");

Serial.println(Ethernet.localIP());

}

void loop() {

// listen for incoming clients

EthernetClient client = server.available();

if (client) {

Serial.println("new client");

// an http request ends with a blank line

boolean currentLineIsBlank = true;

while (client.connected()) {

if (client.available()) {

char c = client.read();

Serial.write(c);

// if you've gotten to the end of the line (received a newline

// character) and the line is blank, the http request has ended,

// so you can send a reply

if (c == '\n' && currentLineIsBlank) {

// send a standard http response header

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println("Connection: close");

client.println("Refresh: 2");

client.println();

client.println("");

//-----------------Type in outputs below-------------------------------------

client.println("");

client.print("Hello World!");

client.print("

client.print("Sensor Data");

client.println("

");

client.print("

");

client.print("Pressure:");

client.println("

");

client.print("

");

client.print("Acceleration:");

client.println("

");

client.println("

client.println("");

break;

//-----------------End of outputs--------------------------------------------

}

if (c == '\n') {

// you're starting a new line

currentLineIsBlank = true;

} else if (c != '\r') {

// you've gotten a character on the current line

currentLineIsBlank = false;

}

}

}

// give the web browser time to receive the data

delay(1);

// close the connection:

client.stop();

Serial.println("client disconnected");

}

}

另外,arduino确实有一个静态IP,所以我很确定它不是DHCP租约到期的问题 .

我非常怀疑屏蔽是否有故障,因为它在运行时变得非常热 . 另外它是一个仿冒品 . 但我不能忽视我编码效率低下的可能性,因为我不是很有经验 . 任何帮助,将不胜感激 . 谢谢 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值