许多客户端打印完毕后的Arduino(宇野)以太网客户端连接失败 [英] Arduino (Uno) Ethernet client connection fails after many client prints

查看:212
本文介绍了许多客户端打印完毕后的Arduino(宇野)以太网客户端连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个Arduino乌诺以太网盾。

发送的HTTP请求后,的 client.println(...)的,客户端开始连接时失败。失效时间似乎是随机的,并且从该环的序列读出可〜1000和7000〜之间的任何变化。

的错误不是与以太网发送缓冲器溢出做(以下这个建议

下面是code是失败的:

 的#include< Ethernet.h>
#包括LT&;&spi.h中GT;//网络常数
字节的MAC [] = {为0x00,0x23,0xdf,为0x82,0xd4,0×01};
字节的IP [] = {/ *绝密* /};
字节服务器[] = {/ *绝密* /};
INT端口= / * *删节/;
Client客户端(服务器,端口);//国
INT序列;无效设置(){
    Ethernet.begin(MAC,IP);
    Serial.begin(9600);
    序列= 0;    延迟(1000);
}空隙环(){
    httpPut(/主题/:测试/发布的sessionId = SESenanhygrp);
    Serial.println(序列++);
}无效httpPut(字符* URL){
    如果(!client.connect()){
        Serial.println(例外:HTTP PUT期间无法连接);
        返回;
    }    client.print(PUT);
    client.print();
    client.print(URL);
    client.println(HTTP / 1.0);
    client.println();    而(!client.available()){
        延迟(1);
    }    而(client.available()){
        焦C = client.read();
        Serial.print(C);
    }    而(client.connected()){
        Serial.println(等待服务器断开连接);
    }    client.stop();
}

在下面的环节出现错误

 如果(!client.connect()){
    Serial.println(例外:HTTP PUT期间无法连接);
    返回;
}


解决方案

有在Arduino的以太网库V22(错误作为的 Linux / Windows的V0022 / 1.0以太网问题解决了 的)。

我的解决方案是使用的的Ethernet2 库(由彼得tinker.it)。在code需要轻微的修修补补,但一切似乎是现在的工作很好。我已经成功地克服了没有任何问题发送40000+ HTTP消息。 (偶尔单个消息不能被发送,但该错误率小于4%。)

I'm using an Arduino Uno with Ethernet Shield.

After sending many HTTP requests, client.println(...), the client starts to fail when connecting. The time to failure appears to be random, and the sequence readout from the loop can vary anywhere between ~1000 and ~7000.

The error is not to do with the Ethernet Transmit Buffer overflowing (Following this advice)

Here is the code that is failing:

#include <Ethernet.h>
#include <SPI.h>

// Network constants
byte mac[] = {0x00, 0x23, 0xdf, 0x82, 0xd4, 0x01};
byte ip[] = {/*REDACTED*/};
byte server[] = {/*REDACTED*/};
int port = /*REDACTED*/;
Client client(server, port);

// State
int sequence;

void setup(){
    Ethernet.begin(mac, ip);
    Serial.begin(9600);
    sequence = 0;

    delay(1000);
}

void loop(){
    httpPut("/topic/:test/publish?sessionId=SESenanhygrp");
    Serial.println(sequence++);
}

void httpPut(char* url){
    if (!client.connect()) {
        Serial.println("EXCEPTION: during HTTP PUT. Could not connect");
        return;
    }

    client.print("PUT");
    client.print(" ");
    client.print(url);
    client.println(" HTTP/1.0");
    client.println();

    while(!client.available()){
        delay(1);
    }

    while(client.available()) {
        char c = client.read();
        Serial.print(c);
    }

    while(client.connected()){
        Serial.println("Waiting for server to disconnect");
    }

    client.stop();
}

The error occurs in the following segment

if (!client.connect()) {
    Serial.println("EXCEPTION: during HTTP PUT. Could not connect");
    return;
}

解决方案

There is a bug in the Arduino Ethernet library in v22 (as discussed in Linux/Windows V0022/1.0 Ethernet problem SOLVED).

The solution for me was to use the Ethernet2 library (by Peter from tinker.it). The code needed minor tinkering, but everything appears to be working fine now. I've managed to get over 40000+ HTTP messages sent without any problems. (Occasionally single messages cannot be sent, but this error rate is less than 4%.)

这篇关于许多客户端打印完毕后的Arduino(宇野)以太网客户端连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆