EtherCard icon indicating copy to clipboard operation
EtherCard copied to clipboard

UDP packet is not sent - NOT STATIC IP

Open DexasElectronics opened this issue 3 years ago • 1 comments

Hello. Im trying to send some test strings using example sketch provided in the description of the library. I have checked all the mentioned issues, but they all seem to share same thing - static ip. I told that also, while using static ip i cannot neither send single packet to specific adress, neither broadcast. When using DHCP, i can broadcast, but cannot send packet to single adress (packet never arrives).

Tried using code provided in Add ARP cache #351, but that gives error about "no member named 'clientResolveIp'", from what i see those functions are deleted from the latest version, not sure why.

Snippets from code i am using:

static byte myip[] = { 192,168,1,200 };
static byte gwip[] = { 192,168,1,254 };
static byte dnsip[] = { 8,8,8,8 };
static byte mask[] = { 255,255,255,0 };
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };

ether.staticSetup(myip, gwip, 0, mask);

char payload[] = "My UDP message";
uint8_t nSourcePort = 11;
uint8_t nDestinationPort = 11;
uint8_t ipDestinationAddress[IP_LEN];
ether.parseIp(ipDestinationAddress, "192.168.1.103");
ether.sendUdp(payload, sizeof(payload), nSourcePort, ipDestinationAddress, nDestinationPort);

void loop() // run over and over { ether.packetLoop(ether.packetReceive()); }

Tried changing ports, etc, both static and dynamic ip, no luck in any case.

DexasElectronics avatar Oct 05 '21 21:10 DexasElectronics

The library was not able to get the destination MAC address correctly, so the computer ignored the UDP packet. Open the file tcpip.cpp and locate the function void EtherCard::udpPrepare (uint16_t sport, const uint8_t *dip, uint16_t dport) on line 376 Please replace destmacaddr with gwmacaddr

if(is_lan(myip, dip)) { //setMACandIPs(destmacaddr, dip); setMACandIPs(gwmacaddr, dip); }

daonguyen207 avatar Nov 17 '21 20:11 daonguyen207