Connection to Arduino Ethernet (Uno) server ends after many client printouts

I am using Arduino Uno with an Ethernet screen.

After sending many HTTP requests to client.println (...), the client fails to connect. The failure time seems random, and reading the sequence from the loop can range from ~ 1000 to ~ 7000.

The error is not related to the Ethernet transfer buffer overflow (after this tip )

Here is the code that does not work:

#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();
}

An error occurs in the next segment.

if (!client.connect()) {
    Serial.println("EXCEPTION: during HTTP PUT. Could not connect");
    return;
}
+5
source share
2 answers

Ethernet Arduino v22 ( Linux/Windows V0022/1.0 Ethernet SOLVED).

Ethernet2 ( Peter tinker.it). , . 40000+ HTTP-, - . ( , 4%.)

0

, 10x . , 1000 7000 , , , , Arduino, , - , , - . Arduino . , , , , Arduino . , , .

0

All Articles