Ethernet Receive Problem

I have a bigger problem in the moment. With high traffic I lost up to 60% of all my received packages. I have same problem with STM32duino which is also based on LWIP.

lwIP has a lot of configuration options, this one should be the number of buffered messages when the blocking processing is not fast enough:

        "mbox-size": {
            "help": "mailbox size",
            "value": 8
        },

tried this in mbed_app.json, but I get errors

 {
	"target_overrides": {
		"*": {
			"lwip.mem-size": 16384,
			"mbox-size": {
            "help": "mailbox size",
            "value": 8
        },
			"platform.stdio-baud-rate": 115200,
			"platform.stdio-buffered-serial": 1,
			"target.printf_lib": "std"
		}
	}
}
[ERROR] in ./mbed_app.json element target_overrides.*.mbox-size: OrderedDict([('help', 'mailbox size'), ('value', 16)]) is not of type 'array', 'string', 'integer', 'boolean', 'null'; in ./mbed_app.json element target_overrides.*.mbox-size: OrderedDict([('help', 'mailbox size'), ('value', 16)]) is not of type 'array', 'string', 'integer', 'boolean', 'null'

that setting was simply copied from mbed-os/connectivity/lwipstack/mbed_lib.json, sorry.
There you’ll find the available settings that can be used with the mbed config system.

So in the mbed_app, just use e.g. “lwip.mbox-size” : 16 to buffer the double amount of packages.

{
	"target_overrides": {
		"*": {
			"lwip.mem-size": 16384,
			"lwip.mbox-size":  16,
  			"platform.stdio-baud-rate": 115200,
			"platform.stdio-buffered-serial": 1,
			"target.printf_lib": "std"
		}
	}
}

Are you still using the non-blocking socket as in your example code? Have you tried a blocking socket?

I’m using always a non blocking socket. Otherways I need more sockets and threads.

Tried it but also no luck. There are 24 packets send within 2ms from a PC application.
Only 11 packets reached.

difficult to help… I think blocking sockets are more efficient, because you are not wasting time by running in a loop. An incoming packet triggers an interrupt and the data is put into a queue/mailbox. Waiting in a recvfrom will activate a receiver thread immediately (when the prio higher) and you can process your data and packets will be received in the background.
Then it depends on the processing time, when the incoming data is continous 12 packets per ms, then the processing must be faster than ~83 µs. When the data comes in bursts, then there is a chance to buffer the data by increasing the mailbox size.

Are there some examples how to handle within threads. My app need to receive and to send data on more than one socket?

I have packed this in a UDPconnection class, I have to strip it a little bit and can upload an example to github.

I have created an example with my UDPConnection classe:

In main, there are two connections created. The UDPConnection class starts a receiving thread and when data is received, it calls message handlers. There is a simple ExampleMessageHandler, it can be used as a template for own handlers. In the dispatch method, you get the received data, size and remote address. I have tried to increase thread prio for the receiving thread, but this did not work, don’t know yet why.
Another thread is started for asynchronus sending.
I’m using VSCode / gcc, but it compiles also with Mbed Studio.

The problem with receiving was solved. It was a misunderstanding how connect() works on UDP, the filtering was the problem.

1 Like