Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d7cb41b
ethernet lib: set mac address, log module fix
leonardocavagnis Jul 31, 2025
76402c0
Ethernet lib: move Ethernet functions implementation in .cpp
leonardocavagnis Aug 1, 2025
b6f0564
Ethernet lib: tentative set manual IP,subnet,gateway
leonardocavagnis Aug 1, 2025
b33e1e2
Ethernet lib: add set IP, Subnet, Gateway functions
leonardocavagnis Aug 4, 2025
c780380
Ethernet lib: add disconnect fun
leonardocavagnis Aug 4, 2025
f6a58f2
Ethernet lib: extract Ethernet lib from SocketWrapper lib
leonardocavagnis Aug 5, 2025
b9941ee
Ethernet lib: add default examples
leonardocavagnis Aug 5, 2025
08d3bcc
ethernet lib: fix examples
leonardocavagnis Aug 6, 2025
d976791
eth lib: disable log print in SocketWrapper module
leonardocavagnis Aug 6, 2025
0566080
eth lib: add new line at end of file
leonardocavagnis Aug 6, 2025
100ac13
ethernet lib: add only zephyr architecture in library properties
leonardocavagnis Sep 3, 2025
648b1b7
ethernet lib: remove no-standard example
leonardocavagnis Sep 3, 2025
d589d60
ethernet lib: remove wiznet stuff
leonardocavagnis Sep 3, 2025
8678d18
socket wrapper: cosmetics clang
leonardocavagnis Sep 3, 2025
c5420cf
ethernet lib: cosmetics clang
leonardocavagnis Sep 3, 2025
f59cbae
ethernet lib: restore default WebClientRepeating.ino example
leonardocavagnis Sep 4, 2025
3be4ea0
ethernet lib: restore default WebServer.ino example
leonardocavagnis Sep 4, 2025
2bdc914
ethernet lib: move examples to arduino.tips
leonardocavagnis Sep 4, 2025
1eff286
ethernet: fix ethernet in variant MCXN947
leonardocavagnis Sep 4, 2025
621ab56
ethernet: fix architecture in library properties
pennam Oct 10, 2025
aae3937
ethernet: fix interface discovery on c33
pennam Oct 10, 2025
c9cfdeb
ethernet: fix MACAddress(uint8_t *mac)
pennam Oct 10, 2025
7a10967
ethernet: fix setMACAddress
pennam Oct 10, 2025
b15ccf2
ethernet: remove setter overloads
pennam Oct 10, 2025
8782a24
ethernet: remove disconnect overload
pennam Oct 10, 2025
b635f92
ethernet: remove getters overloads
pennam Oct 13, 2025
cd9baae
networkInterface: rename setLocalIPFull to config
pennam Oct 13, 2025
35998e9
ethernet: refactor begin()
pennam Oct 13, 2025
6479087
ethernet: remove init()
pennam Oct 13, 2025
98aba73
ethernet: add maintain() dummy implementation
pennam Oct 13, 2025
21553b3
ethernet: add dummy implementation of setRetransmissionTimeout
pennam Oct 13, 2025
17485b7
ethernet: add dummy implementation of setRetransmissionCount
pennam Oct 13, 2025
2c8f287
ethernet: uniform example Waiting for link on
pennam Oct 13, 2025
0ad6fc0
ethernet: format examples
pennam Oct 13, 2025
464ab15
NetworkInterface: make dtor virtual
pennam Oct 13, 2025
51848ac
ethernet: UdpNtpClient, avoid double checking link status
pennam Oct 14, 2025
076840f
ethernet: remove examples that need more testing
pennam Oct 14, 2025
7b6f193
ethernet: fix TelnetClient wait for serial
pennam Oct 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libraries/Ethernet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ethernet Library for Arduino

Provides Ethernet connectivity for Arduino boards using the Arduino Zephyr core, together with a shield or carrier featuring an Ethernet connector.

📖 For more information about this library please read the documentation [here](http://www.arduino.cc/en/Reference/Ethernet).

## License

Copyright (c) 2025 Arduino SA. All rights reserved.

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
28 changes: 28 additions & 0 deletions libraries/Ethernet/examples/LinkStatus/LinkStatus.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Link Status
This sketch prints the ethernet link status. When the
ethernet cable is connected the link status should go to "ON".
*/

#include <ZephyrEthernet.h>

void setup() {
Serial.begin(9600);
}

void loop() {
auto link = Ethernet.linkStatus();
Serial.print("Link status: ");
switch (link) {
case Unknown:
Serial.println("Unknown");
break;
case LinkON:
Serial.println("ON");
break;
case LinkOFF:
Serial.println("OFF");
break;
}
delay(1000);
}
94 changes: 94 additions & 0 deletions libraries/Ethernet/examples/TelnetClient/TelnetClient.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Telnet client

This sketch connects to a telnet server.
You need a telnet server to test this.
*/

#include "ZephyrClient.h"
#include "ZephyrEthernet.h"

// The IP address will be dependent on your local network:
IPAddress ip(192, 168, 1, 177);

// Example: To get the IP address of telehack.com (an example telnet server), run in a terminal:
// ping telehack.com
// or
// nslookup telehack.com
// Then use the returned IP address in the code.

// Enter the IP address of the server you're connecting to:
IPAddress server(1, 1, 1, 1);
int port = 23; // Telnet port

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use port 10002):
ZephyrClient client;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}

// in Zephyr system check if Ethernet is ready before proceeding to initialize
while (Ethernet.linkStatus() != LinkON) {
Serial.println("Waiting for link on");
delay(100);
}

// start the Ethernet connection:
Ethernet.begin(ip);

// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");

// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected");
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}

void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}

// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:
while (Serial.available() > 0) {
char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
}
}

// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing:
while (true) {
delay(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
UDPSendReceiveString:
This sketch receives UDP message strings, prints them to the serial port
and sends an "acknowledge" string back to the sender

A Processing sketch is included at the end of file that can be used to send
and received messages for testing with a computer.
*/

#include <ZephyrEthernet.h>
#include <ZephyrUDP.h>

// The IP address will be dependent on your local network:
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888; // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
ZephyrUDP Udp;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// in Zephyr system check if Ethernet is ready before proceeding to initialize
while (Ethernet.linkStatus() != LinkON) {
Serial.println("Waiting for link on");
delay(100);
}

// start the Ethernet
Ethernet.begin(ip);

// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}

// start UDP
Udp.begin(localPort);
}

void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(Udp.remotePort());

// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);

// send a reply to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
delay(10);
}


/*
Processing sketch to run with this example
=====================================================

// Processing UDP example to send and receive string data from Arduino
// press any key to send the "Hello Arduino" message


import hypermedia.net.*;

UDP udp; // define the UDP object


void setup() {
udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
//udp.log( true ); // <-- printout the connection activity
udp.listen( true ); // and wait for incoming message
}

void draw()
{
}

void keyPressed() {
String ip = "192.168.1.177"; // the remote IP address
int port = 8888; // the destination port

udp.send("Hello World", ip, port ); // the message to send

}

void receive( byte[] data ) { // <-- default handler
//void receive( byte[] data, String ip, int port ) { // <-- extended handler

for(int i=0; i < data.length; i++)
print(char(data[i]));
println();
}
*/
128 changes: 128 additions & 0 deletions libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*

Udp NTP Client

Get the time from a Network Time Protocol (NTP) time server
Demonstrates use of UDP sendPacket and ReceivePacket
For more on NTP time servers and the messages needed to communicate with them,
see http://en.wikipedia.org/wiki/Network_Time_Protocol

*/

#include <ZephyrEthernet.h>
#include <ZephyrUDP.h>

unsigned int localPort = 8888; // local port to listen for UDP packets

const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server

const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

// A UDP instance to let us send and receive packets over UDP
ZephyrUDP Udp;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

// in Zephyr system check if Ethernet is ready before proceeding to initialize
while (Ethernet.linkStatus() != LinkON) {
Serial.println("Waiting for link on");
delay(100);
}

// start Ethernet and UDP
if (Ethernet.begin() == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
} else if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// no point in carrying on, so do nothing forevermore:
while (true) {
delay(1);
}
}
Udp.begin(localPort);
}

void loop() {
// send an NTP packet to a time server
sendNTPpacket(timeServer);

// wait to see if a reply is available
delay(1000);
if (Udp.parsePacket()) {
// We've received a packet, read the data from it
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer

// the timestamp starts at byte 40 of the received packet and is four bytes,
// or two words, long. First, extract the two words:

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
Serial.print("Seconds since Jan 1 1900 = ");
Serial.println(secsSince1900);

// now convert NTP time into everyday time:
Serial.print("Unix time = ");
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
unsigned long epoch = secsSince1900 - seventyYears;
// print Unix time:
Serial.println(epoch);


// print the hour, minute and second:
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
Serial.print(':');
if (((epoch % 3600) / 60) < 10) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Serial.print('0');
}
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Serial.print(':');
if ((epoch % 60) < 10) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Serial.print('0');
}
Serial.println(epoch % 60); // print the second
}
// wait ten seconds before asking for the time again
delay(10000);
}

// send an NTP request to the time server at the given address
void sendNTPpacket(const char* address) {
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;

// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); // NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
Loading
Loading