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:
15:53715cc81c63
Parent:
14:7648334eb41b
Child:
16:269f652b4d0b
--- a/UipEthernet.cpp	Tue Sep 03 09:16:55 2019 +0000
+++ b/UipEthernet.cpp	Sat Sep 07 17:42:42 2019 +0000
@@ -113,7 +113,7 @@
  * @param
  * @retval
  */
-int UipEthernet::connect()
+int UipEthernet::connect(unsigned long timeout)
 {
     // Inicialize static pointer to the UIPEthernet instance
     ethernet = this;
@@ -124,7 +124,7 @@
     // If no local IP address has been set ask DHCP server to provide one
     if (_ip == IpAddress()) {
         // Now try to get our config info from a DHCP server
-        int ret = dhcpClient.begin((uint8_t*)_mac);
+        int ret = dhcpClient.begin((uint8_t*)_mac, timeout);
 
         if (ret == 1) {
             // We've successfully found a DHCP server and got our configuration info, so set things
@@ -352,8 +352,8 @@
     if (inPacket == NOBLOCK) {
         inPacket = enc28j60Eth.receivePacket();
 #ifdef UIPETHERNET_DEBUG
-        if (in_packet != NOBLOCK) {
-            printf("--------------\r\nreceivePacket: %d\r\n", in_packet);
+        if (inPacket != NOBLOCK) {
+            printf("--------------\r\nreceivePacket: %d\r\n", inPacket);
         }
 #endif
     }
@@ -391,7 +391,7 @@
         if (inPacket != NOBLOCK && (packetState & UIPETHERNET_FREEPACKET))
         {
 #ifdef UIPETHERNET_DEBUG
-            printf("freeing packet: %d\r\n", in_packet);
+            printf("freeing packet: %d\r\n", inPacket);
 #endif
             enc28j60Eth.freePacket();
             inPacket = NOBLOCK;
@@ -455,7 +455,7 @@
     if (packetState & UIPETHERNET_SENDPACKET)
     {
 #ifdef UIPETHERNET_DEBUG
-        printf("Enc28J60Network_send uip_packet: %d, hdrlen: %d\r\n", uip_packet, uip_hdrlen);
+        printf("Enc28J60Network_send uipPacket: %d, hdrlen: %d\r\n", inPacket, uipHeaderLen);
 #endif
         enc28j60Eth.writePacket(uipPacket, 0, uip_buf, uipHeaderLen);
         packetState &= ~UIPETHERNET_SENDPACKET;
@@ -466,12 +466,15 @@
     if (uipPacket != NOBLOCK)
     {
 #ifdef UIPETHERNET_DEBUG
-        printf("Enc28J60Network_send uip_buf (uip_len): %d, packet: %d\r\n", uip_len, uip_packet);
+        printf("Enc28J60Network_send uip_buf (uip_len): %d, packet: %d\r\n", uip_len, uipPacket);
 #endif
         enc28j60Eth.writePacket(uipPacket, 0, uip_buf, uip_len);
         goto sendandfree;
     }
 
+#ifdef UIPETHERNET_DEBUG
+        printf("Enc28J60Network_send return false\r\n");
+#endif
     return false;
 sendandfree:
     enc28j60Eth.sendPacket(uipPacket);
@@ -635,7 +638,7 @@
 #ifdef UIPETHERNET_DEBUG_CHKSUM
         printf
             (
-                "chksum uip_packet(%d)[%d-%d]: %d\r\n", uip_packet, UIP_IPH_LEN +
+                "chksum uipPacket(%d)[%d-%d]: %d\r\n", uipPacket, UIP_IPH_LEN +
                 UIP_LLH_LEN +
                 upper_layer_memlen, UIP_IPH_LEN +
                 UIP_LLH_LEN +