c - Microduino ENC28J60 Ethernet Module (Arduino compatible) UDP Send not working -
i using new microduino enc28j60 ethernet module (arduino compatible).
i using udplistener sketch , want echo message sender when udp packet arrives.
i receiving messages ok, udpsend in callback method not work.
this works fine on arduino uno ethernet shield
can help.
thanks in advance
here code:
// demonstrates usage of new udpserver feature. //you can register same function multiple ports, , multiple functions same port. // // 2013-4-7 brian lee cybexsoft@hotmail.com #include #include #define static 1 // set 1 disable dhcp (adjust myip/gwip values below) #if static // ethernet interface ip address static byte myip[] = { 192,168,0,201 }; // gateway ip address static byte gwip[] = { 192,168,0,1 }; static byte ipdestination[] = {192, 168, 0, 9}; unsigned int portmy = 8888; unsigned int portdestination = 9000; #endif // ethernet mac address - must unique on network static byte mymac[] = { 0x70,0x69,0x69,0x2d,0x30,0x31 }; byte ethernet::buffer[500]; // tcp/ip send , receive buffer char msg[] = {"hello world"}; //callback prints received packets serial port void udpserialprint(word port, byte ip[4], const char *data, word len) { ipaddress src(ip[0], ip[1], ip[2], ip[3]); serial.println(src); serial.println(port); serial.println(data); serial.println(len); //i added echo packet <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ether.sendudp(msg, sizeof msg, portmy, ipdestination, portdestination); serial.println("udp sent !!"); } void setup(){ serial.begin(9600); serial.println("\n[backsoon]"); if (ether.begin(sizeof ethernet::buffer, mymac) == 0) serial.println( "failed access ethernet controller"); #if static ether.staticsetup(myip, gwip); serial.println("serial started on fixedip"); #else if (!ether.dhcpsetup()) serial.println("dhcp failed"); #endif ether.printip("ip: ", ether.myip); ether.printip("gw: ", ether.gwip); ether.printip("dns: ", ether.dnsip); //register udpserialprint() port 1337 ether.udpserverlistenonport(&udpserialprint, portmy); //register udpserialprint() port 42. //ether.udpserverlistenonport(&udpserialprint, 42); } void loop(){ //this must called ethercard functions work. ether.packetloop(ether.packetreceive()); }
===== additional information ====
hi,
sorry includes are:
include ethercard.h include ipaddress.h seem removed text left arrow & right arrow symbol used in c++.
i take note ether class. used example ethercard folder called "udplistener" , puzzled class not being declared. assumed in done in ethercard.h.
the program work , listens , displays correctly received udp packets udpserialprint method, listening side works. wanted echo sender of udp packet , udpsend not work.
the shield using on link: http://hobbycomponents.com/index.php/microduino-enc28j60-ethernet-module-arduino-compatible.html
the compatible libraries found through same webpage:
https://github.com/jcw/ethercard
i hope provides further info necessary.
first of all, posted code doesn't seem complete. there several incomplete #include
's, also, don't see ether
class defined.
next, if code use work on ethernet shield, libs used , more chip on ethernet shield?
the encj2860 "its own" chip. is, libs required control encj2860 might different ones used on ethernet shield, if , if, chip on ethernet shield not encj2860.
it impossible determine information given in question. but, first thing at.
p.s. working on sprucing libs encj2860, , waiting ethernet shield has encj2860, can this, or send libs (still debugged!!).
Comments
Post a Comment