Mbed library for ENC28J60 Ethernet modules. Full support for TCP/IP and UDP Server, Client and HTTP server (webserver). DHCP and DNS is included.

Dependents:   mBuino_ENC28_MQTT Nucleo_Web_ENC28J60 Nucleo_Web_ENC28J60_ADC Serial_over_Ethernet ... more

Library for ENC28J60 Ethernet modules.

/media/uploads/hudakz/enc28j60_module01.jpg

Ported to mbed from Norbert Truchsess's UIPEthernet library for Arduino. Thank you Norbert!

  • Full support for persistent (streaming) TCP/IP and UDP connections Client and Server each, ARP, ICMP, DHCP and DNS.
  • Works with both Mbed OS 2 and Mbed OS 5.

Usage:

  • Import the library into your project.
  • Add #include "UipEthernet.h" to main.cpp
  • Create one instance of the UipEthernet class initialized with the MAC address you'd like to use and SPI pins of the connected Mbed board.

Example programs:

Import programWebSwitch_ENC28J60

HTTP Server serving a simple webpage which enables to remotely turn a digital output on/off. Compile, download, run and type 'IP_address/secret/' (don't forget the last '/') into your web browser and hit ENTER.

Import programHTTPServer_Echo_ENC28J60

A simple HTTP server echoing received requests. Ethernet connection is over an ENC28J60 board. Usage: Type the server's IP address into you web browser and hit <ENTER>.

Import programTcpServer_ENC28J60

Simple TCP/IP Server using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programTcpClient_ENC28J60

Simple TCP/IP Client using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programUdpServer_ENC28J60

Simple UDP Server using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programUdpClient_ENC28J60

Simple UDP Client using the UIPEthernet library for ENC28J60 Ethernet boards.

Import programMQTT_Hello_ENC28J60

MQTT Client example program. Ethernet connection is via an ENC28J60 module.

Revision:
9:a156d3de5647
Parent:
8:4acb22344932
--- a/utility/uip_debug.cpp	Fri Jun 30 19:51:28 2017 +0000
+++ b/utility/uip_debug.cpp	Tue Aug 27 15:01:10 2019 +0000
@@ -7,7 +7,7 @@
 extern "C"
 {
 #include "uip.h"
-} extern Serial     pc;
+}
 struct uip_conn con[UIP_CONNS];
 
 /**
@@ -19,9 +19,9 @@
 void UIPDebug::uip_debug_printconns(void) {
     for (uint8_t i = 0; i < UIP_CONNS; i++) {
         if (uip_debug_printcon(&con[i], &uip_conns[i])) {
-            pc.printf("connection[");
-            pc.printf("%d", i);
-            pc.printf("] changed.\r\n");
+            printf("connection[");
+            printf("%d", i);
+            printf("] changed.\r\n");
         }
     }
 }
@@ -35,130 +35,130 @@
 bool UIPDebug::uip_debug_printcon(struct uip_conn* lhs, struct uip_conn* rhs) {
     bool    changed = false;
     if (!uip_ipaddr_cmp(lhs->ripaddr, rhs->ripaddr)) {
-        pc.printf(" ripaddr: ");
+        printf(" ripaddr: ");
         uip_debug_printbytes((const uint8_t*)lhs->ripaddr, 4);
-        pc.printf(" -> ");
+        printf(" -> ");
         uip_debug_printbytes((const uint8_t*)rhs->ripaddr, 4);
-        pc.printf("\r\n");
+        printf("\r\n");
         uip_ipaddr_copy(lhs->ripaddr, rhs->ripaddr);
         changed = true;
     }
 
     if (lhs->lport != rhs->lport) {
-        pc.printf(" lport: ");
-        pc.printf("%d", htons(lhs->lport));
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", htons(rhs->lport));
+        printf(" lport: ");
+        printf("%d", htons(lhs->lport));
+        printf(" -> ");
+        printf("%d\r\n", htons(rhs->lport));
         lhs->lport = rhs->lport;
         changed = true;
     }
 
     if (lhs->rport != rhs->rport) {
-        pc.printf(" rport: ");
-        pc.printf("%d", htons(lhs->rport));
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", htons(rhs->rport));
+        printf(" rport: ");
+        printf("%d", htons(lhs->rport));
+        printf(" -> ");
+        printf("%d\r\n", htons(rhs->rport));
         lhs->rport = rhs->rport;
         changed = true;
     }
 
     if ((uint32_t) lhs->rcv_nxt[0] != (uint32_t) rhs->rcv_nxt[0]) {
-        pc.printf(" rcv_nxt: ");
+        printf(" rcv_nxt: ");
         uip_debug_printbytes(lhs->rcv_nxt, 4);
-        pc.printf(" -> ");
+        printf(" -> ");
         uip_debug_printbytes(rhs->rcv_nxt, 4);
         *((uint32_t*) &lhs->rcv_nxt[0]) = (uint32_t) rhs->rcv_nxt[0];
-        pc.printf("\r\n");
+        printf("\r\n");
         changed = true;
     }
 
     if ((uint32_t) lhs->snd_nxt[0] != (uint32_t) rhs->snd_nxt[0]) {
-        pc.printf(" snd_nxt: ");
+        printf(" snd_nxt: ");
         uip_debug_printbytes(lhs->snd_nxt, 4);
-        pc.printf(" -> ");
+        printf(" -> ");
         uip_debug_printbytes(rhs->snd_nxt, 4);
         *((uint32_t*) &lhs->snd_nxt[0]) = (uint32_t) rhs->snd_nxt[0];
-        pc.printf("\r\n");
+        printf("\r\n");
         changed = true;
     }
 
     if (lhs->len != rhs->len) {
-        pc.printf(" len: ");
-        pc.printf("%d", lhs->len);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->len);
+        printf(" len: ");
+        printf("%d", lhs->len);
+        printf(" -> ");
+        printf("%d\r\n", rhs->len);
         lhs->len = rhs->len;
         changed = true;
     }
 
     if (lhs->mss != rhs->mss) {
-        pc.printf(" mss: ");
-        pc.printf("%d", lhs->mss);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->mss);
+        printf(" mss: ");
+        printf("%d", lhs->mss);
+        printf(" -> ");
+        printf("%d\r\n", rhs->mss);
         lhs->mss = rhs->mss;
         changed = true;
     }
 
     if (lhs->initialmss != rhs->initialmss) {
-        pc.printf(" initialmss: ");
-        pc.printf("%d", lhs->initialmss);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->initialmss);
+        printf(" initialmss: ");
+        printf("%d", lhs->initialmss);
+        printf(" -> ");
+        printf("%d\r\n", rhs->initialmss);
         lhs->initialmss = rhs->initialmss;
         changed = true;
     }
 
     if (lhs->sa != rhs->sa) {
-        pc.printf(" sa: ");
-        pc.printf("%d", lhs->sa);
-        pc.printf(" -> ");
-        pc.printf("%d", rhs->sa);
+        printf(" sa: ");
+        printf("%d", lhs->sa);
+        printf(" -> ");
+        printf("%d", rhs->sa);
         lhs->sa = rhs->sa;
         changed = true;
     }
 
     if (lhs->sv != rhs->sv) {
-        pc.printf(" sv: ");
-        pc.printf("%d", lhs->sv);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->sv);
+        printf(" sv: ");
+        printf("%d", lhs->sv);
+        printf(" -> ");
+        printf("%d\r\n", rhs->sv);
         lhs->sv = rhs->sv;
         changed = true;
     }
 
     if (lhs->rto != rhs->rto) {
-        pc.printf(" rto: ");
-        pc.printf("%d", lhs->rto);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->rto);
+        printf(" rto: ");
+        printf("%d", lhs->rto);
+        printf(" -> ");
+        printf("%d\r\n", rhs->rto);
         lhs->rto = rhs->rto;
         changed = true;
     }
 
     if (lhs->tcpstateflags != rhs->tcpstateflags) {
-        pc.printf(" tcpstateflags: ");
-        pc.printf("%d", lhs->tcpstateflags);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->tcpstateflags);
+        printf(" tcpstateflags: ");
+        printf("%d", lhs->tcpstateflags);
+        printf(" -> ");
+        printf("%d\r\n", rhs->tcpstateflags);
         lhs->tcpstateflags = rhs->tcpstateflags;
         changed = true;
     }
 
     if (lhs->timer != rhs->timer) {
-        pc.printf(" timer: ");
-        pc.printf("%d", lhs->timer);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->timer);
+        printf(" timer: ");
+        printf("%d", lhs->timer);
+        printf(" -> ");
+        printf("%d\r\n", rhs->timer);
         lhs->timer = rhs->timer;
         changed = true;
     }
 
     if (lhs->nrtx != rhs->nrtx) {
-        pc.printf(" nrtx: ");
-        pc.printf("%d", lhs->nrtx);
-        pc.printf(" -> ");
-        pc.printf("%d\r\n", rhs->nrtx);
+        printf(" nrtx: ");
+        printf("%d", lhs->nrtx);
+        printf(" -> ");
+        printf("%d\r\n", rhs->nrtx);
         lhs->nrtx = rhs->nrtx;
         changed = true;
     }
@@ -174,9 +174,9 @@
  */
 void UIPDebug::uip_debug_printbytes(const uint8_t* data, uint8_t len) {
     for (uint8_t i = 0; i < len; i++) {
-        pc.printf("%d", data[i]);
+        printf("%d", data[i]);
         if (i < len - 1)
-            pc.printf(",");
+            printf(",");
     }
 }
 #endif