Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP not send packet #368

Open
Avenitos opened this issue Jun 25, 2019 · 3 comments
Open

UDP not send packet #368

Avenitos opened this issue Jun 25, 2019 · 3 comments

Comments

@Avenitos
Copy link

Avenitos commented Jun 25, 2019

Hello!

sendUdp() function not send broadcast packets :(
in Wireshark no packets.

UIP library worked correctly!

#include <EtherCard.h>

const byte myMac[] PROGMEM = { 0x70, 0x69, 0x69, 0x2D, 0x30, 0x31 };
byte Ethernet::buffer[350];                          // Buffer must be 350 for DHCP to work

void setup() {
  Serial.begin(57600);
  Serial.println(F("\n[EtherCard UDP send]"));

  if (ether.begin(sizeof Ethernet::buffer, myMac, SS) == 0)
    Serial.println(F("Failed to access Ethernet controller"));

  static byte myip[] = { 172,16,1,147 };
  static byte gwip[] = { 172,16,1,1 };
  static byte dnsip[] = { 8,8,8,8 };
  static byte mask[] = { 255,255,255,0 };

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

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  char payload[] = "My UDP message";
  uint8_t nSourcePort = 6454;
  uint8_t nDestinationPort = 6454;
  uint8_t broadcast[4] = { 255,255,255,255};
  
//ether.client_arp_whohas_blocking(ipDestinationAddress);
//delay(10);
//ether.sendUdp_mac(payload, sizeof(payload), nSourcePort, ipDestinationAddress, ether.returned_mac, nDestinationPort);

  ether.sendUdp(payload, sizeof(payload), nSourcePort, broadcast, nDestinationPort);

  Serial.println("UDP sent.");  
}

void loop() {
  ether.packetLoop(ether.packetReceive());
}
@Avenitos
Copy link
Author

I did not immediately understand why the ntp demo works, but sending to my local server does not work. It turns out that any sending within the local segment does not work, sending via the gateway to the Internet address works normally. Why is that?

@njh
Copy link
Owner

njh commented Jun 25, 2019

It is probably something to do with the code that chooses the Layer 2 MAC address to send to.
When sending to the Internet, EtherCard just needs the use the routers MAC address. When sending to the local subnet, it needs to find and use the right address. Although for broadcast this should just be FF:FF:FF:FF:FF:FF.

Have you tried sending to your subnet's broadcast address ? 172.16.1.255?

See also #59

@marcin-koziol-iteo
Copy link

 uint8_t nSourcePort = 6454;
  uint8_t nDestinationPort = 6454;

is the same as byte so you're not able to set port number larger than 255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants