Simple socket and errno = 11, No more processes

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: Simple socket and errno = 11, No more processes

Postby FrankJensen » Thu Mar 14, 2024 7:13 am

My problem is sending bytes, not receiving.

When I use send() the ESP32 is not setting the "do not fragment" flag in the packet header. Even though I send only 12 bytes. And I think (this is guessing) that my Huawei inverter do not like that. Is it not responding. I am only guessing, but my reason for this guess, is cause when I send the exact same data from a software from my PC, the only real difference I see in the packet header, is the "do not fragment" flag, that is true from my PC, and false from my ESP32.

So how do I set this flag?

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: Simple socket and errno = 11, No more processes

Postby ESP_Sprite » Thu Mar 14, 2024 7:31 am

I don't think the current version of lwip is capable of setting this flag, although you can hack it back in if you're OK with changing the lwip sources.

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: Simple socket and errno = 11, No more processes

Postby FrankJensen » Thu Mar 14, 2024 8:19 am

But from the menuconfig, it should be possible, as I understand it.

LWIP_IP_FRAG
Enable fragment outgoing IP packets
Found in: Component config > LWIP
Enabling this option allows fragmenting outgoing IP packets if their size exceeds MTU.


But clearing this option (its set as default) dont seem to change the fact, that the packet send do not have the dont fragment flag set.

I am getting a little stuck here. Since some receivers do block fragmented IP packages, how can I come around this.... AND the Arduino framework seems to handle this nicely....

chegewara
Posts: 2240
Joined: Wed Jun 14, 2017 9:00 pm

Re: Simple socket and errno = 11, No more processes

Postby chegewara » Thu Mar 14, 2024 3:48 pm

FrankJensen wrote:
Tue Mar 12, 2024 10:42 pm
Looking i wireshark, sending request from ESP32
- ESP32 -> Huawei - a 66 byte Modbus/TCP package is send
- Huawei -> ESP32 a 64 byte [ACK] is sent
- ESP32 -> Huawei a 54 byte [FIN, ACK] is sent
- Huawei -> ESP32 [ACK]
- Huawei -> ESP32 [FIN, ACK]
- ESP32 -> Huawei [ACK]
This is the reason i suggested it:
FIN: a message that triggers a graceful connection termination between a client and a server
esp32 seems to be sending FIN, which you dont have in this comm

Code: Select all

Comparing, sending the exact same request using QModMaster from my PC
- PC -> Huawei - a 66 byte Modbus/TCP package is send
- Huawei -> PC a 64 byte [ACK] is sent
- Huawei -> PC a 295 byte Modbus response is sent
- goodbye packages follows
1. The client sends a FIN message to the server
2. The server receives the client’s FIN message and ACKs it to the client
3. The client receives the server’s ACK and waits
4. If there are messages to be sent from the server to the client, the server sends it
5. The server sends a FIN message to the client
6. The client receives the server’s FIN message and ACKs it to the server
7. The server receives the client’s ACK and closes the connection on the server-side
8. The client waits a protocolar time
9. The client closes the connection on the client-side
https://www.baeldung.com/cs/tcp-fin-vs-rst#fin-message


But of course usually i am wrong, so good luck.

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: Simple socket and errno = 11, No more processes

Postby ESP_Sprite » Fri Mar 15, 2024 2:36 am

FrankJensen wrote:
Thu Mar 14, 2024 8:19 am
But from the menuconfig, it should be possible, as I understand it.

LWIP_IP_FRAG
Enable fragment outgoing IP packets
That is something else. This enables LWIP to fragment packets that are larger than the MTU if it's sent out. The DF bit tells upstream routers etc to not fragment the packet if it's larger than *their* MTU. It's the difference between defining behaviour in LWIP, and setting a bit in the packet that defines the behaviour of an upstream device.

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: Simple socket and errno = 11, No more processes

Postby FrankJensen » Sat Mar 16, 2024 8:41 am

Yes, that is correct.
ESP32 -> Huawei sends 12 bytes,
Huawei -> ESp32 sends [ACK]
ESP32 -> Huawai sends [FIN][ACK] after 5 second timeout

So for some reason, the Huawei inverter do not answer. But it answers percectly sending the same 12 bytes from my PC. I think, that Huawei waits for more data, or something. Only difference I can see, is that from my PC dont fragment flag is set, in the packet header, and from the ESP32 its not.

What should happen after the Huawei sends the [ACK], is a response of 295 bytes. Like from my PC.

And my code is working, cause I use exact same code to send data to a LAN -> RS232 box with loopback, and it transmits and receives perfectly. So its back to something specific for Huawei.....

I dont know how to solve this.... Maybe use a LAN -> RS232 and connect to the modbus RTU in stead, but that seems a little silly......

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: Simple socket and errno = 11, No more processes

Postby FrankJensen » Sat Mar 16, 2024 9:43 am

And what annoys me the most, is that my old code - using the Arduino framework, instead of the ESP-IDF framework - works flawlessly. So I know for sure, that its not a ESP32 hardware issue........

FrankJensen
Posts: 35
Joined: Sun Mar 10, 2024 9:34 pm

Re: Simple socket and errno = 11, No more processes

Postby FrankJensen » Sat Mar 16, 2024 4:06 pm

Okay.... Issue solved......

Googling until crosseyed, I found a openhab config file for Huawei, and I notised a pre-delay parameter. It seems, that after connecting, Huawei needs a little time to be ready for a command. So I added a delay. And now I get a reply.... :)
I tried delays everywhere, but not inbetween connect and write.

Maybe the Arduino framework has this delay build in. Or the code is just very slow :)

Boiled down code

Code: Select all

connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr));
vTaskDelay(pdMS_TO_TICKS(500));
int nSend = write(sock, sendbuffer, _len_trans);
int bytes_received = recv(sock, _frame, _len_recv, 0);
Just in case, someone else should struggle with this problem.... Thank you for your help.

ESP_Sprite
Posts: 9052
Joined: Thu Nov 26, 2015 4:08 am

Re: Simple socket and errno = 11, No more processes

Postby ESP_Sprite » Sun Mar 17, 2024 3:40 am

Heh, I can entirely understand why that'd make you pull your hair out. Glad you fixed it and thanks for sharing the solution!

Who is online

Users browsing this forum: No registered users and 217 guests