Unable to listen to all ip addresses on the subnet on stm32
Posted: Thu Oct 06, 2022 9:20 pm
I have connected a STM32(NUCLEO-F767ZI) to my laptop via ethernet cable. The IP address of laptop ethernet is 169.252.72.123 with a subnet mask of 255.255.0.0.
When I bind my ethernet to 0.0.0.0 it must listen to all ip address in the subnet i.e. 169.252.72.123/16. i.e. when i send data from my laptop to say 169.252.72.155 on port 1024, STM32 must receive the data. But this is not happening. (as per my understanding binding to 0.0.0.0 is equivalent to binding to INADDR_ANY in udp.h)
However, when I use a particular ip address, say IPAddress ip(169,252,72,24); and Ethernet.begin on this ip (rest of the parameters mac, dns, gateway, subnet and port same as in below code) and send data from my laptop to this particular ip 169.252.72.24 on port 1024, then STM32 correctly receives the data.
How can i listen to all ip address on the subnet so that I can receive data on stm32 when my laptop sends data on any of the 169.252.72.123/16 addresses
On arduino IDE, I have the following code and loaded it onto the STM32
On the laptop, I have a simple python code to send a message:
When I bind my ethernet to 0.0.0.0 it must listen to all ip address in the subnet i.e. 169.252.72.123/16. i.e. when i send data from my laptop to say 169.252.72.155 on port 1024, STM32 must receive the data. But this is not happening. (as per my understanding binding to 0.0.0.0 is equivalent to binding to INADDR_ANY in udp.h)
However, when I use a particular ip address, say IPAddress ip(169,252,72,24); and Ethernet.begin on this ip (rest of the parameters mac, dns, gateway, subnet and port same as in below code) and send data from my laptop to this particular ip 169.252.72.24 on port 1024, then STM32 correctly receives the data.
How can i listen to all ip address on the subnet so that I can receive data on stm32 when my laptop sends data on any of the 169.252.72.123/16 addresses
On arduino IDE, I have the following code and loaded it onto the STM32
Code: Select all
#include <LwIP.h>
#include <STM32Ethernet.h>
#include <EthernetUdp.h>
byte mac[] = { 0xAB, 0xCD, 0xEF, 0xFE, 0xCD, 0xAB };
IPAddress ip(0,0,0,0);
IPAddress dns(169,252,1,1);
IPAddress gateway(169,252,1,1);
IPAddress subnet(255,255,0,0);
EthernetUDP Udp;
unsigned int stm32localport = 1024;
char packetBuffer[200]; //max 200 byte pkt; can be changed
void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect.
}
Ethernet.begin(mac, ip, dns, gateway, subnet);
Udp.begin(stm32localport);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Udp.read(packetBuffer, packetSize);
Serial.println(packetBuffer);
}
}
Code: Select all
import socket
UDP_IP = "169.252.72.155"
UDP_PORT = 1024
MESSAGE = "Hello"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))