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:
11:647d53d146f1
Parent:
9:a156d3de5647
Child:
14:7648334eb41b
--- a/UdpSocket.cpp	Tue Aug 27 22:08:54 2019 +0000
+++ b/UdpSocket.cpp	Fri Aug 30 08:11:40 2019 +0000
@@ -60,9 +60,9 @@
         uip_udp_remove(_uip_udp_conn);
         _uip_udp_conn->appstate = NULL;
         _uip_udp_conn = NULL;
-        UipEthernet::ethernet->phy.freeBlock(appdata.packet_in);
-        UipEthernet::ethernet->phy.freeBlock(appdata.packet_next);
-        UipEthernet::ethernet->phy.freeBlock(appdata.packet_out);
+        UipEthernet::ethernet->enc28j60Eth.freeBlock(appdata.packet_in);
+        UipEthernet::ethernet->enc28j60Eth.freeBlock(appdata.packet_next);
+        UipEthernet::ethernet->enc28j60Eth.freeBlock(appdata.packet_out);
         memset(&appdata, 0, sizeof(appdata));
     }
 }
@@ -109,7 +109,7 @@
 
     if (_uip_udp_conn) {
         if (appdata.packet_out == NOBLOCK) {
-            appdata.packet_out = UipEthernet::ethernet->phy.allocBlock(UIP_UDP_MAXPACKETSIZE);
+            appdata.packet_out = UipEthernet::ethernet->enc28j60Eth.allocBlock(UIP_UDP_MAXPACKETSIZE);
             appdata.out_pos = UIP_UDP_PHYH_LEN;
             if (appdata.packet_out != NOBLOCK)
                 return 1;
@@ -155,7 +155,7 @@
 {
     if (_uip_udp_conn && appdata.packet_out != NOBLOCK) {
         appdata.send = true;
-        UipEthernet::ethernet->phy.resizeBlock(appdata.packet_out, 0, appdata.out_pos);
+        UipEthernet::ethernet->enc28j60Eth.resizeBlock(appdata.packet_out, 0, appdata.out_pos);
         uip_udp_periodic_conn(_uip_udp_conn);
         if (uip_len > 0) {
             _send(&appdata);
@@ -176,7 +176,7 @@
 size_t UdpSocket::write(const uint8_t* buffer, size_t size)
 {
     if (appdata.packet_out != NOBLOCK) {
-        size_t  ret = UipEthernet::ethernet->phy.writePacket
+        size_t  ret = UipEthernet::ethernet->enc28j60Eth.writePacket
             (
                 appdata.packet_out,
                 appdata.out_pos,
@@ -201,7 +201,7 @@
         printf("udp parsePacket freeing previous packet: %d\r\n", appdata.packet_in);
     }
 #endif
-    UipEthernet::ethernet->phy.freeBlock(appdata.packet_in);
+    UipEthernet::ethernet->enc28j60Eth.freeBlock(appdata.packet_in);
 
     appdata.packet_in = appdata.packet_next;
     appdata.packet_next = NOBLOCK;
@@ -212,7 +212,7 @@
     }
 #endif
 
-    int size = UipEthernet::ethernet->phy.blockSize(appdata.packet_in);
+    int size = UipEthernet::ethernet->enc28j60Eth.blockSize(appdata.packet_in);
 #ifdef UIPETHERNET_DEBUG_UDP
     if (appdata.packet_in != NOBLOCK) {
         printf(", size: %d\r\n", size);
@@ -225,7 +225,7 @@
 int UdpSocket::available()
 {
     UipEthernet::ethernet->tick();
-    return UipEthernet::ethernet->phy.blockSize(appdata.packet_in);
+    return UipEthernet::ethernet->enc28j60Eth.blockSize(appdata.packet_in);
 }
 
 // Read a single byte from the current packet
@@ -246,13 +246,13 @@
 {
     UipEthernet::ethernet->tick();
     if (appdata.packet_in != NOBLOCK) {
-        memaddress  read = UipEthernet::ethernet->phy.readPacket(appdata.packet_in, 0, buffer, len);
-        if (read == UipEthernet::ethernet->phy.blockSize(appdata.packet_in)) {
-            UipEthernet::ethernet->phy.freeBlock(appdata.packet_in);
+        memaddress  read = UipEthernet::ethernet->enc28j60Eth.readPacket(appdata.packet_in, 0, buffer, len);
+        if (read == UipEthernet::ethernet->enc28j60Eth.blockSize(appdata.packet_in)) {
+            UipEthernet::ethernet->enc28j60Eth.freeBlock(appdata.packet_in);
             appdata.packet_in = NOBLOCK;
         }
         else
-            UipEthernet::ethernet->phy.resizeBlock(appdata.packet_in, read);
+            UipEthernet::ethernet->enc28j60Eth.resizeBlock(appdata.packet_in, read);
         return read;
     }
 
@@ -265,7 +265,7 @@
     UipEthernet::ethernet->tick();
     if (appdata.packet_in != NOBLOCK) {
         unsigned char   c;
-        if (UipEthernet::ethernet->phy.readPacket(appdata.packet_in, 0, &c, 1) == 1)
+        if (UipEthernet::ethernet->enc28j60Eth.readPacket(appdata.packet_in, 0, &c, 1) == 1)
             return c;
     }
 
@@ -276,7 +276,7 @@
 void UdpSocket::flush()
 {
     UipEthernet::ethernet->tick();
-    UipEthernet::ethernet->phy.freeBlock(appdata.packet_in);
+    UipEthernet::ethernet->enc28j60Eth.freeBlock(appdata.packet_in);
     appdata.packet_in = NOBLOCK;
 }
 
@@ -300,18 +300,18 @@
             if (data->packet_next == NOBLOCK) {
                 uip_udp_conn->rport = UDPBUF->srcport;
                 uip_ipaddr_copy(uip_udp_conn->ripaddr, UDPBUF->srcipaddr);
-                data->packet_next = UipEthernet::ethernet->phy.allocBlock(ntohs(UDPBUF->udplen) - UIP_UDPH_LEN);
+                data->packet_next = UipEthernet::ethernet->enc28j60Eth.allocBlock(ntohs(UDPBUF->udplen) - UIP_UDPH_LEN);
 
                 //if we are unable to allocate memory the packet is dropped. udp doesn't guarantee packet delivery
                 if (data->packet_next != NOBLOCK) {
                     //discard Linklevel and IP and udp-header and any trailing bytes:
-                    UipEthernet::ethernet->phy.copyPacket
+                    UipEthernet::ethernet->enc28j60Eth.copyPacket
                         (
                             data->packet_next,
                             0,
                             UipEthernet::inPacket,
                             UIP_UDP_PHYH_LEN,
-                            UipEthernet::ethernet->phy.blockSize(data->packet_next)
+                            UipEthernet::ethernet->enc28j60Eth.blockSize(data->packet_next)
                         );
 #ifdef UIPETHERNET_DEBUG_UDP
                     printf