QNEthernet
An lwIP-based Ethernet library for Teensy 4.1 and other platforms
Install / Use
/learn @ssilverman/QNEthernetREADME
QNEthernet, an lwIP-Based Ethernet Library For Teensy 4.1 and other platforms
Version: 0.36.0-snapshot
The QNEthernet library provides Ethernet functionality for the Teensy 4.1 and possibly some other platforms. It's designed to be compatible with the Arduino-style Ethernet API.
This library is distributed under the "AGPL-3.0-or-later" license. Please contact the author if you wish to inquire about other license options.
Please see the lwip-info/ directory for the info files provided with the lwIP release.
Table of contents
- Introduction
- Additional functions and features not in the Arduino-style API
- How to run
- How to write data to connections
- A note on the examples
- A survey of how connections (aka
EthernetClient) work - How to use multicast
- How to use listeners
- How to change the number of sockets
- UDP receive buffering
- mDNS services
- DNS
- stdio
- Raw Ethernet frames
- How to implement VLAN tagging
- Application layered TCP: TLS, proxies, etc.
- On connections that hang around after cable disconnect
- Notes on ordering and timing
- Notes on RAM1 usage (Teensy 4)
- Heap memory use
- Entropy generation
- Interference mitigation
- Security features
- Configuration macros
- Auxiliary tools
- Complete list of features
- Compatibility with other APIs
- Other notes
- To do
- Code style
- References
Introduction
The QNEthernet library is designed to be a drop-in replacement for code using the Arduino-style Ethernet API.
Note: Please read the function docs in the relevant header files for more information.
Three notes
There are three notes, as follows:
- The
QNEthernet.hheader must be included instead ofEthernet.h. - Everything is inside the
qindesign::networknamespace. In many cases, adding the following at the top of your program will obviate the need to qualify any object uses or make any other changes:using namespace qindesign::network; - On non-Teensy platforms:
Ethernet.loop()must be called regularly, either at the end of the mainloop()function, or by hooking intoyield(). (This is already done for you on the Teensy platform by hooking intoyield()viaEventResponder.)
See: How to move the stack forward and receive data
For API additions beyond what the Arduino-style API provides, see:
Additional functions and features not in the Arduino-style API
Other differences and notes
- UDP support is already included in QNEthernet.h. There's no need to also include QNEthernetUDP.h.
- Ethernet
loop()is called fromyield()(automatically on the Teensy platform). The functions that wait for timeouts rely on this. This also means that you must usedelay(ms)(assuming it internally callsyield()),yield(), orEthernet.loop()when waiting on conditions; waiting without calling these functions will cause the TCP/IP stack to never refresh. Note that many of the I/O functions callloop()so that there's less burden on the calling code. - All but one of the
Ethernet.begin(...)functions don't block.Ethernet.begin(mac[, timeout])blocks, while waiting for an IP address, to match the Arduino-style API. It uses a default timeout of 60 seconds. This behaviour can be emulated by following a call tobegin()with a loop that checksEthernet.localIP()for a valid IP. See also the newEthernet.waitForLocalIP(timeout)orEthernet.onAddressChanged(cb). - The Arduino-style
Ethernet.begin(mac, ...)functions all accept a NULL MAC address. If the address is NULL then the internal or system default MAC address will be used. As well, if Ethernet fails to start then the MAC address will not be changed. EthernetServer::write(...)functions always return the write size requested. This is because different clients may behave differently.- The examples at
server.accept()
and
if (EthernetClient)
directly contradict each other with regard to what
operator bool()means inEthernetClient. The first example uses it as "already connected", while the second uses it as "available to connect". "Connected" is the chosen concept, but different fromconnected()in that it doesn't check for unread data. - The three Arduino-defined
Ethernet.begin(...)functions that use the MAC address and that don't specify a subnet are deprecated because they make some incorrect assumptions about the subnet and gateway. Ethernet.hardwareStatus(): AddsEthernetOtherHardwareandEthernetTeensy41to the list of possible return values. Note that these values are not defined in the Arduino-style API.- The following
Ethernetfunctions are deprecated and do nothing or return some default value:maintain(): Returns zero.setRetransmissionCount(uint8_t number): Does nothing.- `setRet
