Simple socket and errno = 11, No more processes

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Mon Mar 11, 2024 9:35 pm

Is the data received at the other end?

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

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

Postby FrankJensen » Mon Mar 11, 2024 9:54 pm

Hmmm. I will need to find a way to check that....There is not really any user interface on the receiver. But I tried using wireshark in order to see, what happened. But i was not able to see any packages sent to the receiver IP adress. I thought, that I was using wireshark wrong. But maybe I used it correctly, and there simply was no packages.... I am not a shark into wireshark :-)

I think, I will try to send some packages to my PC, and take a look at wireshark again.

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

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

Postby FrankJensen » Mon Mar 11, 2024 11:49 pm

It seems, like the data is sent - and received. I had a LAN to Serial adaptor, where I can see, how many bytes it receives. When I change the IP and PORT to match this adaptor, the log reads out, that it receives 72 bytes every minute, exactly corresponding to my 12 bytes every 10 seconds.

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

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

Postby FrankJensen » Tue Mar 12, 2024 12:06 am

Just set up my serial adaptor, so that the received data is looped back.... AND now I actually receive data. So now its getting really strange..... :?: It seems, like my Huawei device replies when getting the request from the Arduino code, but not from the ESP-IDF code. Now I need do find out, if Huawei actually answers or not....

I will get back, in case other struggle with the same. At least it seems my code works. Thanx for now :)

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

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

Postby FrankJensen » Tue Mar 12, 2024 7:19 am

This is really a puzzle....

My code works, when using the LAN to RS232 adapter with loopback...
But to my Huawei, there is no response..

When trying to communicate with Huawei, if I change the port or the IP, there is no connection. So they are definitely seeing eachother.

If I use RealTerm to send a package to Huawei, it responds immediately. If I upload my old Arduino code to the very same ESP32, it works.

I fail to see, how to proceed... Timeout in my old Arduino code is 2 seconds. In my new code, its 5 seconds. Can Huawei respond too quickly, so than the data is somehow missed? The only real differece, is that the Huawai interface is LAN based, and in my test with the RS232, there is a delay, cause the data is converted into RS232, looped back, and then converted back to LAN.

Wireshark I can not use, cause there are several switches on the route.

I am all out of ideas....

By the way, since the ESP32 is eating all the sockets, if there is no reply, is there a way to reset this? Or close all the sockets hanging? Cause at night, when there is no sun, this is actually the exact situation I have. Cause the dongle receives the data, but the inverter is selves is sleeping, so there is no reply.

MicroController
Posts: 1706
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

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

Postby MicroController » Tue Mar 12, 2024 10:52 am

If the server side is offline, establishing a connection should already fail.
In other cases, if you implement a timeout like you already did and make sure to close every socket upon timeout or completion, there shouldn't be any socket 'leak'. - Though you may want to check the default linger timeout, and/or set a reasonable value (a few seconds) for SO_LINGER, to avoid having 'dead' sockets needlessly linger too long.

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

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

Postby FrankJensen » Tue Mar 12, 2024 10:42 pm

Hi again.

Now a lot smarter, but not any wizer.....

I know now for a fact that
- The package is sent
- The package is received
- The Huaway disconnects, and sends nothing.

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]

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

In the header bytes (the 66 bytes), I can see the modbus data as the last 12 bytes in both cases. Rest of the header is different. Guess thats normal. And as seen, the first 2 lines looks similar, first 66 bytes, then 64 bytes. And then the difference. When its from the ESP32, the Huawei hangs up. But not from the PC.

So I must assume, that something in the header must be wrong. Is there any kind of keep-connection, or whatever, that I need to specify, when I create the socket?? Is there something special, when its binary data or modbus?

And again let me mention - uploading my Arduino code, it works. In other words, this snipped of code from the arduino framework, is working

Code: Select all

size_t nSend = HUAWEI_client.write(sendbuffer, 12);
int _len = (sendbuffer[11]*2) + 9;
uint8_t* _frame = (uint8_t*) malloc(_len);
int nRes = readBytes((char*)_frame, _len);
And this snippet from my ESP-IDF framework, is not

Code: Select all

int nSend = send(sock, sendbuffer, _len_trans, 0);
int _len_recv = (sendbuffer[11]*2) + 9;
uint8_t* _frame = (uint8_t*) malloc(_len_recv);
int bytes_received = recv(sock, _frame, _len_recv, 0);
Anyone have a clue... ? Cause I am quite clueless.

Any help would be highly apreciated :|
Attachments
2.JPG
2.JPG (24.38 KiB) Viewed 1735 times
1.JPG
1.JPG (36.19 KiB) Viewed 1738 times

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

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

Postby FrankJensen » Wed Mar 13, 2024 9:55 pm

Looking at the headers, I find only one real difference

The one that succeeds(PC):
- ip.flags == 0x2: Do not fragment

The one that fails (ESP32):
- ip.flags == 0x0: No flags set

From what I read, lwIP should only fragment, if the size of the message exceeds buffer_size.
Since I only send 12 bytes, this should be well below the default 1024 bytes.

The suggested ways of setting this flag, that I can find, do not seem to work. How do I set this dont fragment flag?

This fails:

Code: Select all

int df_flag = 1; // Use value 1 to enable DF
if (setsockopt(sock, IPPROTO_IP, IP_DF, &df_flag, sizeof(df_flag)) < 0) {
     ESP_LOGE(TAG, "Failed to set DF flag");
}

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

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

Postby FrankJensen » Wed Mar 13, 2024 11:31 pm

Even if I disable "Enable fragment outgoing IP4 packets" in menuconfig, the header viewed in wireshark still have no "dont fragment" flags....

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

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

Postby chegewara » Thu Mar 14, 2024 1:18 am

Code: Select all

while(1)
{
         int bytes_received = recv(sock, _frame, _len_recv, 0);
 
        if (bytes_received < 0) {
               ESP_LOGE(TAG, "Failed to receive data: %i - %s", errno, strerror(errno));
               break;
        }
        if (bytes_received == 0) {
              ESP_LOGI(TAG, "Server closed connection");
              break;
       }
       if (bytes_received > 0) {
           ESP_LOGI(TAG, "Data received successfully");
       }
}

Who is online

Users browsing this forum: Google [Bot], mln2007 and 93 guests