arduino / arduino/ArduinoCore-renesas

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

Open
#240 5 comments 0 reactions 0 assignees View on GitHub
status: waiting for information topic: code type: imperfection
Dominant language
C
Stars
193
Forks
112
PR merge metrics
No merged PRs in 30d

Description

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

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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the long-run TCP loop with the EthernetC33 HTTP server and Python socket client, then inspect the mentioned lwip tcp_write and tcp_output paths when tcp_write returns ERR_MEM. Done means repeated connections complete without exhausting buffers and the C33 continues responding to ping; the payload names no repository files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
embedded-iot, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.