Arduino to Python Over Ethernet Without Router

Hello,

I’m attempting to transmit/receive data with an arduino over an ethernet cable plugged directly into my computer. I’ve gotten to the point where the arduino is definitely receiving data from my computer, but for an unknown reason, never responds. I downloaded wireshark to attempt to diagnose this. At the time the arduino is cycling through the Udp.write area of code, it spams “ARP Announcement for 169.254.245.1” 10 times or so. No UDP protocol messages originating from the arduino are recorded by wireshark. UDP protocol messages originating from my computer are recorded by wireshark.

I’m using an arduino uno with the ethernet W5100 shield.

I’m afraid my networking experience is essentially zero and have no idea what th ARP announcement means or if it’s an issue. But I can’t find any other issue.

Arduino Code

#include <Ethernet.h> 
#include <EthernetUdp.h> 

byte mac[] = { 0x34, 0x29, 0x8f, 0x7a, 0x7f, 0x3b}; //Assign a mac address
IPAddress ip(169,254,245,1); //arduino IP
char ReplyBuffer[] = "response";

EthernetServer server(80);
unsigned int localPort = 5000;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
String datReq;
int packetSize; 
EthernetUDP Udp;

void setup() {
  
Serial.begin(9600); 
Ethernet.begin(mac, ip); 
Udp.begin(localPort);
Serial.print("test");
delay(1500); 
}

void loop() {
  
  packetSize = Udp.parsePacket();
  
  if(packetSize>0){
  
  Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
  String datReq(packetBuffer); 
  Serial.println(datReq);

    if (datReq =="Blue") { //See if blue was requested
    Serial.println("data requested...");
    Serial.println(Udp.remoteIP());
    Serial.println(Udp.remotePort());
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());  
    Udp.write(ReplyBuffer); 
    Udp.endPacket(); //Packet has been sent
    Serial.println("packet should be sent");
    }
  }
  memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
}

Python Code

from socket import *
import time
 
address = ( '169.254.245.1', 5000) #match arduino IP + port
client_socket = socket(AF_INET, SOCK_DGRAM) 
print(client_socket)
client_socket.settimeout(5) #wait up to 5 seconds
 
while(1): 
 
    data = "Blue" #response should be sent
    
    client_socket.sendto(data.encode(), address)
    print(client_socket)
    
    try:
        rec_data, addr = client_socket.recvfrom(2048)
        print(rec_data)
    except:
        print("No message received")
        print(client_socket)
        pass
    time.sleep(.1)

If the Arduino is set to static IP address 169.254.245.1 then you’d want the PC to be at 169.254.245.2
Read the section How to assign static IP address using Control Panel in How to set a static IP address on Windows 10 • Pureinfotech

.

Thanks for the assistance! I tried doing that, i set the computer ip address to 169.254.245.2, subnet mask to 255.255.255.0 and the gateway to 169.254.245.3 (the last two were just a guess). Wireshark now reporting messages "who has 169.254.245.2? Tell 169.254.245.1" in a similar fashion: a series of them when the arduino should be writing the udp message.

You should not need a crossover Ethernet cable because modern network cards should now automatically handle this, but if you do have a crossover Ethernet cable, I would try it. Or insert a network switch.

I don't know how you choose 169.254.x.x but that has special meaning. https://packetlife.net/blog/2008/sep/24/169-254-0-0-addresses-explained/. I would use 10.0.0.1 for the Arduino and 10.0.0.2 for your PC. https://en.wikipedia.org/wiki/Private_network

.

I’m already using a crossover cable. I’m afraid I have no idea how I chose 169.254.x.x, i started and stopped this project awhile ago. Just now picking it up again
I switched the ip addresses as you suggested and it’s the same message
What are these subnets/gateways? Do they matter?

Maybe you should try the UDP example program first where the Arduino gets its IP address from the router. There maybe something else wrong.

Some of the W5100 shields require modification of resistors. https://forum.arduino.cc/index.php?topic=351477.30

good catch with the resistor issue, mine has 510. When I get parts I’ll post again if that resolves the issue or not. Thanks!