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.

Committer:
hudakz
Date:
Fri Aug 30 08:11:40 2019 +0000
Revision:
11:647d53d146f1
Parent:
9:a156d3de5647
Child:
16:269f652b4d0b
"set_network" method of Mbed style added.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 9:a156d3de5647 1 /*
hudakz 9:a156d3de5647 2 IpAddress.h - Base class that provides IPAddress
hudakz 9:a156d3de5647 3 Copyright (c) 2011 Adrian McEwen. All right reserved.
hudakz 9:a156d3de5647 4
hudakz 9:a156d3de5647 5 Modified (ported to mbed) by Zoltan Hudak <hudakz@inbox.com>
hudakz 9:a156d3de5647 6
hudakz 9:a156d3de5647 7 This library is free software; you can redistribute it and/or
hudakz 9:a156d3de5647 8 modify it under the terms of the GNU Lesser General Public
hudakz 9:a156d3de5647 9 License as published by the Free Software Foundation; either
hudakz 9:a156d3de5647 10 version 2.1 of the License, or (at your option) any later version.
hudakz 9:a156d3de5647 11
hudakz 9:a156d3de5647 12 This library is distributed in the hope that it will be useful,
hudakz 9:a156d3de5647 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 9:a156d3de5647 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
hudakz 9:a156d3de5647 15 Lesser General Public License for more details.
hudakz 9:a156d3de5647 16
hudakz 9:a156d3de5647 17 You should have received a copy of the GNU Lesser General Public
hudakz 9:a156d3de5647 18 License along with this library; if not, write to the Free Software
hudakz 9:a156d3de5647 19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
hudakz 9:a156d3de5647 20 */
hudakz 11:647d53d146f1 21 #ifndef IPADDRESS_h
hudakz 11:647d53d146f1 22 #define IPADDRESS_h
hudakz 9:a156d3de5647 23
hudakz 9:a156d3de5647 24 #include <stdio.h>
hudakz 9:a156d3de5647 25
hudakz 9:a156d3de5647 26 // A class to make it easier to handle and pass around IP addresses
hudakz 9:a156d3de5647 27
hudakz 9:a156d3de5647 28 class IpAddress
hudakz 9:a156d3de5647 29 {
hudakz 9:a156d3de5647 30 private:
hudakz 9:a156d3de5647 31 uint8_t _address[4]; // IPv4 address
hudakz 9:a156d3de5647 32
hudakz 9:a156d3de5647 33 public:
hudakz 9:a156d3de5647 34 // Constructors
hudakz 9:a156d3de5647 35 IpAddress(void);
hudakz 9:a156d3de5647 36 IpAddress(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4);
hudakz 9:a156d3de5647 37 IpAddress(uint32_t address);
hudakz 9:a156d3de5647 38 IpAddress(const uint8_t address[4]);
hudakz 11:647d53d146f1 39 IpAddress(const char *str, size_t len);
hudakz 9:a156d3de5647 40
hudakz 9:a156d3de5647 41 // Overloaded cast operator to allow IPAddress objects to be used where a pointer
hudakz 9:a156d3de5647 42 // to a four-byte uint8_t array is expected
hudakz 9:a156d3de5647 43 operator uint32_t(void) const { return *((uint32_t*)_address); }
hudakz 9:a156d3de5647 44 bool operator==(const IpAddress& addr) const { return(*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }
hudakz 9:a156d3de5647 45 bool operator==(const uint8_t* addr) const;
hudakz 9:a156d3de5647 46
hudakz 9:a156d3de5647 47 // Overloaded index operator to allow getting and setting individual octets of the address
hudakz 9:a156d3de5647 48 uint8_t operator[](int index) const { return _address[index]; }
hudakz 9:a156d3de5647 49 uint8_t &operator[](int index) { return _address[index]; }
hudakz 9:a156d3de5647 50
hudakz 9:a156d3de5647 51 // Overloaded copy operators to allow initialisation of IPAddress objects from other types
hudakz 9:a156d3de5647 52 IpAddress &operator =(uint32_t address);
hudakz 11:647d53d146f1 53 IpAddress &operator =(const uint8_t* address);
hudakz 9:a156d3de5647 54
hudakz 9:a156d3de5647 55 // Returns IP Address as string of char
hudakz 9:a156d3de5647 56 const char* toString(char* buf);
hudakz 9:a156d3de5647 57
hudakz 9:a156d3de5647 58 // Access the raw byte array containing the address. Because this returns a pointer
hudakz 9:a156d3de5647 59 // to the internal structure rather than a copy of the address this function should only
hudakz 9:a156d3de5647 60 // be used when you know that the usage of the returned uint8_t* will be transient and not
hudakz 9:a156d3de5647 61 // stored.
hudakz 9:a156d3de5647 62 uint8_t* rawAddress(void) { return _address; }
hudakz 9:a156d3de5647 63
hudakz 9:a156d3de5647 64 friend class UIPEthernet;
hudakz 9:a156d3de5647 65 friend class UdpSocket;
hudakz 9:a156d3de5647 66 friend class TcpClient;
hudakz 9:a156d3de5647 67 friend class TcpServer;
hudakz 9:a156d3de5647 68 friend class DhcpClient;
hudakz 9:a156d3de5647 69 friend class DnsClient;
hudakz 9:a156d3de5647 70 };
hudakz 9:a156d3de5647 71
hudakz 9:a156d3de5647 72 const IpAddress INADDR_NONE(0, 0, 0, 0);
hudakz 9:a156d3de5647 73 #endif