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:
- Black Box connected to Wiznet through Crossed-Ethernet Cable
- Black Box connected to Wiznet through Regular-Ethernet Cable
- 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