dfr0850 with PoE board UDP problem
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
Hello
I am doing udp communication by installing dfr0850 ethernet shield on arduino uno r3 board. However, in the process of udpRead, packets and data are broken. What's the problem?
The following is my code and serial communication monitor screen.
My PC IP is 192.168.0.5 , the port is 11000.
The board IP is 192.168.0.177 , and the port is 11901.
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress localIP(192, 168, 0, 177);
unsigned int localPort = 11901;
IPAddress remoteIP(192, 168, 0, 5);
unsigned int remotePort = 11000;
// buffers for receiving and sending data
//char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char packetBuffer[4];
char ReplyBuffer[] = "acknowledged";
EthernetUDP Udp;
void setup()
{
// start the Ethernet and UDP:
Ethernet.begin(mac, localIP);
Udp.begin(localPort);
Serial.begin(9600);
delay(1000);
Serial.println("start");
}
void loop()
{
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
for (int i = 0; i < 4; i++)
{
Serial.print(remoteIP, DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(remotePort);
// read the packet into packetBufffer
Udp.read(packetBuffer, packetSize);
Serial.print("Contents:");
Serial.println(packetBuffer);
memset(&packetBuffer,0,sizeof(packetBuffer));
//memset(packetSize,0,sizeof(packetSize));
// send a reply, to the IP address and port that sent us the packet we received
//Udp.beginPacket(remoteIP, remotePort);
//Udp.write(ReplyBuffer);
//Udp.endPacket();
}
delay(2000);
}
I am doing udp communication by installing dfr0850 ethernet shield on arduino uno r3 board. However, in the process of udpRead, packets and data are broken. What's the problem?
The following is my code and serial communication monitor screen.
My PC IP is 192.168.0.5 , the port is 11000.
The board IP is 192.168.0.177 , and the port is 11901.
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress localIP(192, 168, 0, 177);
unsigned int localPort = 11901;
IPAddress remoteIP(192, 168, 0, 5);
unsigned int remotePort = 11000;
// buffers for receiving and sending data
//char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char packetBuffer[4];
char ReplyBuffer[] = "acknowledged";
EthernetUDP Udp;
void setup()
{
// start the Ethernet and UDP:
Ethernet.begin(mac, localIP);
Udp.begin(localPort);
Serial.begin(9600);
delay(1000);
Serial.println("start");
}
void loop()
{
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
for (int i = 0; i < 4; i++)
{
Serial.print(remoteIP, DEC);
if (i < 3)
{
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(remotePort);
// read the packet into packetBufffer
Udp.read(packetBuffer, packetSize);
Serial.print("Contents:");
Serial.println(packetBuffer);
memset(&packetBuffer,0,sizeof(packetBuffer));
//memset(packetSize,0,sizeof(packetSize));
// send a reply, to the IP address and port that sent us the packet we received
//Udp.beginPacket(remoteIP, remotePort);
//Udp.write(ReplyBuffer);
//Udp.endPacket();
}
delay(2000);
}