CONCEPT VISUALIZED
I'm trying to establish a bidirectional communication where ethernet UDP packets enter a linux system (suppose a Raspberry pi) from eth0 interface and piped into the UART hardware of the system, then read by the second linux system, piped into the eth0 interface and transmitted again as UDP packets to a sensor and vice versa.
In other words I'm trying to convert UDP packets to serial and again to UDP seamlessly.
I've managed to make the UDP packets from PC to reach the second linux system, but they don't reach the sensor which is their final destination.
Configuration: PC is just in the same subnet as the first linux system and sends packets constantly in broadcast address, port 33000.
In the first linux system I used netcat to pipe data from eth0 to UART using these commands: stty -F /dev/ttyS0 to set the baud rate of the uart and then nc -ul 172.31.255.255 33000 >/dev/ttyS0 </dev/ttyS0 to pipe data from eth0 to the ttyS0 (uart). Data are successfully transmitted to the second linux system where I can print the payloads. But from there on problems appear.
In the second linux system I used the same commands as the first: stty -F /dev/ttyS0 and nc -ul 172.31.255.255 33000 >/dev/ttyS0 </dev/ttyS0. The problem is that the packets don't reach their final destination which is the sensor. I monitor the traffic in the second linux system's eth0 interface with wireshark and no UDP packets are transmitted.
Weirdly enough, with this configuration, packets from PC (port 33000) don't reach the sensor, BUT, if I change the listening port to 10021 (in both linux systems), then the way is open for the packets from the sensor and they successfully reach the PC (software).
I'm thinking that it might has to do with the server/client roles. PC (through sensor's special software) initiates communication with sensor by sending SYN packets in 33000 and waits for a reply. Those packets don't reach the sensor, but sensor sends data of telemetry in port 10021 and those packets successfully reach the software (PC).
Any insights welcome.