Ethernet shield, network switch- Only one way connection..

Hello again :confused:

Recently I was asking on this great forum about ethernet shield connection problems when connected to network via network switch. I'm working on my engineer graduation project, building flight simulator by using real aircraft fuselage and rebuilded original gauges. They are driven by three arduino mega bards connected via ethernet to one PC. To do that I have to use network switch which causes a lot of problems. Network switch work great with only one"type" od ethernet shield (marked 09/44 as i wrote at this topic: Wiznet W5100 Ethernet shield Manual Speed - Networking, Protocols, and Devices - Arduino Forum)

Thanks to help of keithsw1111 I can now communicate with other shields. Ive done that by manual setting static ARP of my arduino on main PC. But looks like connection is made only in half way (on ethernet shield All diodes lights on, full duplex diode too). By using UDP Send Receive example code I can see, that arduino receiving packes, but I cannot Receive "acknowledged" response on PC UDP monitor. Ping of arduino results "host unreachable". It looks like arduino don't know to what adress send response or how get through switch. Looks like arduino also need in its code manual setting of static ARP of main PC, but is that possible to make such command in sketch?
I am sniffing packets by Packet Sender software, but checked also wireshark, same result. PC does not Receive any packets from arduino, but it definietly recieves packets from PC.
Any help will be really appreciated.. Thank you!
Greetings from Poland!

If you dont mind getting ugly there is a way to code directly to the wiznet chip and issue a SEND_MAC packet. This packet skips the ARP lookup which is likely not working and instead sends to packet to a nominated MAC address.

This clearly has disadvantages as you have to hardcode the MAC address of your PC ... but if you are truly stuck and need a way to try to make it work it is an option.

Let me know and I will post you some sample code.

I'm also interested in sample code :slight_smile:

Thanks Keithsw1111, of course i'm intrested in sample code! :slight_smile:

o do that I have to use network switch which causes a lot of problems

Why do you have to use a network switch? Might be easier and more practical to ditch the switch and use a wireless router.

Might be easier and more practical to ditch the switch and use a wireless router.

Why add even more variables to system still under test? I don't think replacing a wired network switch with a wireless one would offer any advantages in this case.

Zoomkat- I want to use switch because I alredy bought it, and using switch is slightly more professional. And this problem with ethernet shields is do frustrating, that I have to try everything tho get it resolved. But if trays of using switch proove its useless I will probably buy additional router, and just switch wifi of to use it as simple switch. The problem with routers is that it is hard to find router with minimum 5 lan ports. So im desperate to use this switch. Can anyone recomend switch that works with w5100?
Someone told me that tp-link switches are often making problems with arduino. This switch using Realtek rtl8309n chip, so in case of trying another switch i would like to avoid using Realtek based ones... :confused:
But keithsw1111 suggested intresting sollution with SEND_MAC, but I don't know how to use it..

Can anyone recomend switch that works with w5100?

I am using a W5100 with a cisco switch as well as with an old linksys switch/router with no problems

Normally you would send a UDP packet like this:

	byte buffer[6] = {0xDE, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
	IPAddress targetIP(192,168,0,22); 

	EthernetUDP Udp;
	Udp.begin(22222);
	Udp.beginPacket(targetIP, 22222);
	Udp.write(buffer, sizeof(buffer));
	Udp.endPacket();

To convert this to send using the mac address and skip the arp lookup we need to make some changes.

	byte targetMAC[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
	byte buffer[6] = {0xDE, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
	IPAddress targetIP(192,168,0,22); 

	EthernetUDP Udp;
	Udp.begin(22222);
	Udp.beginPacketMAC(targetIP, targetMAC, 22222);
	Udp.write(buffer, sizeof(buffer));
	Udp.endPacketMAC();

The beginPacketMAC and endPacketMAC functions dont exist so lets add them to libraries\ethernet\src\ethernetudp.cpp and the header file

int EthernetUDP::beginPacketMAC(IPAddress ip, uint8_t* mac, uint16_t port)
{
  _offset = 0;
  return startUDPMAC(_sock, rawIPAddress(ip), mac, port);
}

int EthernetUDP::endPacketMAC()
{
  return sendUDPMAC(_sock);
}

The startUDPMAC and sendUDPMAC functions also dont exist so lets add them to libraries\ethernet\src\utility\socket.h and the header file ... this is where the real work gets done.

int startUDPMAC(SOCKET s, uint8_t* addr, uint8_t* mac, uint16_t port)
{
  if
    (((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00)) ||
	 ((mac[0] == 0x00) && (mac[1] == 0x00) && (mac[2] == 0x00) && (mac[3] == 0x00) && (mac[4] == 0x00) && (mac[5] == 0x00)) ||
     (port == 0x00)
    ) 
  {
    return 0;
  }
  else
  {
    SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
    W5100.writeSnDIPR(s, addr);
	// this is where we tell it the mac address we are sending to
	W5100.writeSnDHAR(s, mac);
    W5100.writeSnDPORT(s, port);
    SPI.endTransaction();
    return 1;
  }
}

int sendUDPMAC(SOCKET s)
{
  SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
  W5100.execCmdSn(s, Sock_SEND_MAC);
		
  /* +2008.01 bj */
  while ( (W5100.readSnIR(s) & SnIR::SEND_OK) != SnIR::SEND_OK ) 
  {
    if (W5100.readSnIR(s) & SnIR::TIMEOUT)
    {
      /* +2008.01 [bj]: clear interrupt */
      W5100.writeSnIR(s, (SnIR::SEND_OK|SnIR::TIMEOUT));
      SPI.endTransaction();
      return 0;
    }
    SPI.endTransaction();
    yield();
    SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
  }

  /* +2008.01 bj */	
  W5100.writeSnIR(s, SnIR::SEND_OK);
  SPI.endTransaction();

  /* Sent ok */
  return 1;
}

Because we are making changes to arduino files dont forget to back them up so you dont overwrite them next time you upgrade your IDE.

I dont actually use the default arduino ethernet libraries as they lack functionality that the underlying wiznet chip supports and they are slow so i have customised it. If you hit any errors let me know and i can point you in the right direction. Hopefully you will then be able to see the packets arrive on your PC in wireshark. I have experienced some problems where I cant then pick them up in my .net code ... but i have not spent a lot of time on it.

thanks keithsw1111! You are really helpful! interesting.. I will let You know if that works!

Any results?

Any result, can we get new library files?

I have TP-Link SF1008D and D-Link DES-1005D. At 1st one there is no way to get UDP packet through them, at D-Link only few % of package missing. These is not happened with all W5100 shield, some work great with both switch.

These MAC solution is good only for unicast, so it's not solution for my problem.