2

I'm trying to send udp packet from python server to arduino client by broadcast IP('255.255.255.255').The python server is sending the packet fine but the arduino can't recieve the packet at all even after disabling the windows firewall

server code :

    server = socket(AF_INET, SOCK_DGRAM)
    server.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    server.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
    server.bind(('', 8090))
    while True:
            # sending a messgae to client port with broadcast IP
            message = str.encode("12000")
            server.sendto(message, ('<broadcast>', 8090))
            print("Sent packet with message: ", message)
            time.sleep(1)
            content, addr = server.recvfrom(1024)
            sender_port = int(content.decode())

            print("sender port: ", sender_port)
            IP, port = addr
            print("from: ", IP, port)

     /////Arduino code:
     const char* ssid = "";
     const char* password = "";
     int port = 8090;
     char packetBuffer[255];
     WiFiUDP udp;

            void setup()
    {
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    delay(2000);
    Serial.println("...");
    }
    udp.begin(port);
    Serial.print("WiFi connected with IP: ");
    Serial.println(WiFi.localIP());
    }
    void loop()
    { 
    int packetSize = udp.parsePacket();
    Serial.println(packetSize);

    if (packetSize) {
    int len = udp.read(packetBuffer, 255);
    Serial.println("packet recieved");
    if (len > 0) {
  packetBuffer[len] = '\0';
}

Serial.println("Server IP address is ");
IPAddress remoteIp = udp.remoteIP();
Serial.println(remoteIp);

the packet size is received is 0 and it should have the size and contents

0 Answers0