Skip to content

Lock in C33 using ethernet adapter and TCP connection in a long run #240

Open
@Eduardo-Lopes

Description

@Eduardo-Lopes

Hey all.
I implemented a HTTP server on C33.
But in a stress test, the board doesn't do well.
I take the smallest sample.

#include <EthernetC33.h>

EthernetServer server(7);

void setup() {
  Serial.begin(9600);

  if (Ethernet.begin() == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
  }
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  EthernetClient client = server.available();
  if (client) {
    char previous_c = 0;
    int sequential_newline = 0;
    char buffer[1024];
    int pos = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (previous_c == '\r' && c == '\n')
          sequential_newline++;
        else if (previous_c != '\n' || c != '\r')
          sequential_newline = 0;

        if (sequential_newline == 2)
          break;

        previous_c = c;
        buffer[pos++] = c;
      }
    }
    
    client.write(buffer, pos );

    delay(1);
    // close the connection:
    client.stop();
  }
}

and the python code to call

import socket

server_address = ('192.168.0.103', 7)  # Replace with the desired server address and port

while True:
    tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    tcp_socket.connect(server_address)

    data = b"POST /mode/IDLE HTTP/1.1\r\nHost: 192.168.0.103\r\nUser-Agent: python-requests/2.28.1\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n"
    tcp_socket.sendall(data)

    while True:
        response = tcp_socket.recv(1024)

        if not response:
            break

        print(response.decode(), end='')

    tcp_socket.close()

I take a deep look at the source code too. It looks like a problem in lwip function
tcp_output that doesn't clean the recv buffer in some way.
And it looks like that is something low level because the C33 stops responding to ping too.
In lwip functions is called tcp_write to add the buffer and tcp_output to send the buffer, but tcp_write keeps returning ERR_MEM.

Also, there is no SDCard on the shield.

Any help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: waiting for informationMore information must be provided before work can proceedtopic: codeRelated to content of the project itselftype: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions