Wiznet W5100 sends only Broadcast messages

I can’t make the Wiznet send Multicast messages.
I’m trying to make Arduino duemilanove with ATmega328p Microcontroller, connected to Wiznet5100 talking to a black box (sensor application-set) over UDP over Ethernet (Attached a rough scheme of my module).

I use arduino version 0022 with the built-in Ethernet library designed to work with wiznet5100.

I made several tests:

  1. Black Box connected to Wiznet through Crossed-Ethernet Cable
  2. Black Box connected to Wiznet through Regular-Ethernet Cable
  3. PC used as a gateway between Black Box and Wiznet through a router.

In the first 2 tests, Only broadcast messages arrived from Wiznet to Black Box and multicast messages arrived from Black Box to Wiznet.
In test 3 all of the communication went through a program I wrote in my PC to pass the messages arriving from the Wiznet to the Black Box and visa versa, All the messages arrived (Broadcast and Multicast) with no problem.

#include <SPI.h>        
#include <Ethernet.h>
#include <Udp.h>    

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte bcip[] = { 
  255,255,255,255 };
byte localIp[] = { 
  192,168,2,10 };
byte ip[] = { 
  192,168,2,100 };
byte gateway[] = { 
  192, 168, 2, 1 };
byte subnet[] = { 
  255, 255, 255, 0 };
byte sensorIp[] = { 
  192,168,240,12 };

unsigned int localPort = 30444;      // local port to listen on

// the next two variables are set when a packet is received
byte remoteIp[4];        // holds received packet's originating IP
unsigned int remotePort; // holds received packet's originating port

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

void main() {

  Serial.begin(9600);
  // start the Ethernet and UDP:
  Ethernet.begin(mac, ip, gateway, subnet);
  Udp.begin(localPort);
  Connect();
}

boolean Connect()
{
  boolean retVal = false;
  Udp.sendPacket(CallSensor, bcip, localPort);
  delay(2000);

  int packetSize =Udp.available();
  if(packetSize)
  {
       memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
     // read the packet into packetBufffer and get the senders IP addr and port number
      Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
      delay(50);
      packetSize =Udp.available();
      memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
      // read the packet into packetBufffer and get the senders IP addr and port number
      Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
      delay(50);
      packetSize =Udp.available();
      memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
      // read the packet into packetBufffer and get the senders IP addr and port number
      Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
}

  Udp.sendPacket(BindSensor, remoteIp, remotePort);
  delay(100);
  packetSize =Udp.available();
  if(packetSize)
  {
    memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
    // read the packet into packetBufffer and get the senders IP addr and port number
    Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
  }

  delay(100);
  Udp.sendPacket("k", remoteIp, remotePort);
  delay(100);

  packetSize = Udp.available();
  if(packetSize)
  {
    memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
    // read the packet into packetBufffer and get the senders IP addr and port number
    Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
  }

  delay(100);
  Udp.sendPacket("K", remoteIp, remotePort);
  delay(100);

  packetSize = Udp.available();

  if(packetSize)
  {
    memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);
    // read the packet into packetBufffer and get the senders IP addr and port number
    Udp.readPacket(packetBuffer,UDP_TX_PACKET_MAX_SIZE, remoteIp, remotePort);
    delay(100);
  }
  return true;
}

Did anyone encounter this problem?

Many thanks,
Yoel

ModuleSet.gif

There shouldn't be too much difference between regular UDP packet and multi-cast UDP packet, and I've no experience with either on arduino/wiznet. Can you get a sniffer trace to see whether anything is going on? The one main difference I can think of would be that for a normal UDP packet, I'd imagine the sender would need to ARP the receiver's address to find the MAC address to fill in the packet. And with a multi-cast, there won't be someone to respond. It would be interesting to see if an ARP was going out, as perhaps it would indicate that either no thought went into multi-cast support, or just that something else needs to be done. Have you looked at the doc for the module itself? Maybe something's there that just hasn't been exposed by the library...

I was wrong in terminology, I meant uni-cast (There are only 2 devices in the LAN anyway). I rechecked and did some polish debugging (lots of return values and println's) and the Ethernet library claims that it succeeds in sending the messages but doesn't get any replies from the black box. I don't have a sniffer except for my PC and that is why I did test no. 3 and it worked fine. Any thoughts???

Does your black box have an assigned IP address or is it supposed to get it via DHCP? If the latter, it could be that connecting directly to the Arduino would cause that to fail.

In test 3, which worked completely, what was different in the sketch? Presumably at least the IP address.

BTW, both the current version of MS Netmon and WireShark are freely downloadable.

I have wireshark but I can't sniff packets that don't go through my PC, unless you know how to sniff the router, I would be glad to learn. The black box has an assigned IP which I know and there is one message that go all the way from the arduino to the black-box (I know that because it's suppose to bind the black-box to the arduino and I can see it does) but afterwards, I don't see response even tough the Wiznet tells me that the message has been sent (the udp.available == 0).

The only difference in the sketch is as you say, the remoteIP which is always the PC IP.

Do you think there's a difference between the PC datagram and the Arduino's? Maybe the PC knows how to handle faulted datagrams and that is why the communication carries on...

unless you know how to sniff the router, I would be glad to learn

maybe you can config it as repeater?

I use a 8 port network repeater/extender 100mbit for such jobs. maybe that's an option

Agree with Rob here -- a repeater ("hub") is handy in these cases. Old 10-Mb ones can be had pretty reasonably second hand. Most non-enterprise class 10 Mb multiport boxes are hubs/repeaters while most 100 Mb ones are switches, so useless for this. If you can get a repeater, you set the sniffer software to "promiscuous" mode and it sees everything on the wire.

I haven't done any UDP programming with the shield, but I'm aware of NTP sketches/libraries which I believe use UDP.

If you have a second PC at your disposal, you could have both the original PC and the Arduino target it with UDP packets, and sniff them. That way, you could compare the packets byte-for-byte.

I have a hub, I'll try to use it. I'll keep you updated.

Thanks for the help !

Note that establishing IP communications to a unicast address will involve sending an ARP packet, which is a broadcast. If the blackbox does not manage to get the correct IP address, it would probably not respond to the ARP packet, and the Wiznet would never send the actual IP packet...