Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15346

Can't catch UDP datagrams from NANO + ENC28J60 to pc

$
0
0

I can't get UDP datagrams from nano + ENC28J60 to my pc. Working with this hardware like a server is brilliant, I even can recieve dgrams and turn on/off light. But I need to know, how I can send UDP packages. Dgrams even have been seen in wireshark. Could you help me?

#include <EtherCard.h>
#include <IPAddress.h>
#include <string.h>

#define LIGHT 6

static byte myip[] = { 192,168,1,3 };
static byte gwip[] = { 10,21,224,1 };
static byte dnsip[] = { 195,98,64,65 };
static byte mask[] = {255,255,255,0};

static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

// //callback that prints received packets to the serial port
// void handler(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
//   IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);

//   Serial.println("Connection from:");
//   Serial.print("dest_port: ");
//   Serial.println(dest_port);
//   Serial.print("src_port: ");
//   Serial.println(src_port);
//   Serial.print("src_ip: ");
//   ether.printIp(src_ip);
//   Serial.println();
//   Serial.print("data: ");
//   Serial.println(data);

//   if (strcmp("1", data) == 0) {
//     digitalWrite(LIGHT, HIGH);
//   }
//   else if (strcmp("0", data) == 0) {
//     digitalWrite(LIGHT, LOW);
//   }
//   else {
//     Serial.println("Invalid command!");
//   }
// }

void setup(){
  pinMode(LIGHT, OUTPUT);

  Serial.begin(57600);
  Serial.println(F("\n[backSoon]"));

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
  ether.staticSetup(myip, gwip, dnsip, mask);
  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("MASK: ", ether.netmask);
  ether.printIp("DNS: ", ether.dnsip);
  
  ether.parseIp(ether.hisip, "192.168.1.2");
  ether.printIp("HISIP: ", ether.hisip);

  // //register udpSerialPrint() to port 1234
  // ether.udpServerListenOnPort(&handler, 12345);
}

void loop(){
  //this must be called for ethercard functions to work.
  // ether.packetLoop(ether.packetReceive()); - don't work with/without it
  ether.sendUdp("1", sizeof("1"), 55555, ether.hisip, 10002);
  Serial.println("1");
  delay(1000);
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15346

Trending Articles