Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAC support #11

Merged
merged 9 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Paul Stoffregen https://github.com/PaulStoffregen
per1234 https://github.com/per1234
Richard Sim
Scott Fitzgerald https://github.com/shfitz
Stefan Staub https://github.com/sstaub
STMicroelectronics https://github.com/stm32duino
Thibaut Viard https://github.com/aethaniel
Tom Igoe https://github.com/tigoe
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ This library provides a default user defined options file named `lwipopts_defaul

User can provide his own defined options at sketch level by adding his configuration in a file named `STM32lwipopts.h`.


## New alternative init procedure **!!!**

There are alternative inits of the Ethernetinterface with following orders:

Ethernet.begin();
Ethernet.begin(ip);
Ethernet.begin(ip, subnet);
Ethernet.begin(ip, subnet, gateway);
Ethernet.begin(ip, subnet, gateway, dns);

This is more logical. A MAC address is no more needed and will retrieved internally by the mbed MAC address!

You can get the MAC address with following function, this must done after Ethernet.Begin()

uint8_t *mac;
Ethernet.begin();
mac = Ethernet.macAddress();

You can also set a new user based MAC address, this must done before Ethernet.begin()

uint8_t newMAC[] = {0x00, 0x80, 0xE1, 0x01, 0x01, 0x01};
Ethernet.macAddress(newMAC);
Ethernet.begin();

## Note

`EthernetClass::maintain()` in no more required to renew IP address from DHCP.<br>
Expand Down
10 changes: 5 additions & 5 deletions examples/AdvancedChatServer/AdvancedChatServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
by Norbert Truchsess
modified 23 Jun 2017
by Wi6Labs
modified 1 Jun 2018
by sstaub

*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
Expand All @@ -42,7 +42,7 @@ EthernetClient clients[4];

void setup() {
// initialize the Ethernet device
Ethernet.begin(mac, ip, myDns, gateway, subnet);
Ethernet.begin(ip, subnet, gateway, myDns);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
by Tom Igoe
modified 23 Jun 2017
by Wi6Labs
modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
Expand All @@ -28,11 +30,6 @@
#include <SPI.h>


// assign a MAC address for the Ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(192, 168, 1, 20);

Expand Down Expand Up @@ -62,7 +59,7 @@ void setup() {
SPI.begin();

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
Ethernet.begin(ip);
server.begin();

// initalize the data ready and chip select pins:
Expand Down
10 changes: 5 additions & 5 deletions examples/ChatServer/ChatServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
by Tom Igoe
modified 23 Jun 2017
by Wi6Labs
modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192,168,1, 1);
IPAddress gateway(192, 168, 1, 1);
Expand All @@ -37,7 +37,7 @@ boolean alreadyConnected = false; // whether or not the client was connected pre

void setup() {
// initialize the ethernet device
Ethernet.begin(mac, ip, myDns, gateway, subnet);
Ethernet.begin(ip, subnet, gateway, myDns);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Expand Down
8 changes: 3 additions & 5 deletions examples/DhcpAddressPrinter/DhcpAddressPrinter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
by Arturo Guadalupi
modified 23 Jun 2017
by Wi6Labs
modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address for your controller below.
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

// Initialize the Ethernet client library
// with the IP address and port of the server
Expand All @@ -38,7 +36,7 @@ void setup() {
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
if (Ethernet.begin() == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
Expand Down
12 changes: 5 additions & 7 deletions examples/DhcpChatServer/DhcpChatServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
Based on ChatServer example by David A. Mellis
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192,168,1, 1);
IPAddress gateway(192, 168, 1, 1);
Expand All @@ -50,10 +48,10 @@ void setup() {

// start the Ethernet connection:
Serial.println("Trying to get an IP address using DHCP");
if (Ethernet.begin(mac) == 0) {
if (Ethernet.begin() == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// initialize the Ethernet device not using DHCP:
Ethernet.begin(mac, ip, myDns, gateway, subnet);
Ethernet.begin(ip, subnet, gateway, myDns);
}
// print your local IP address:
Serial.print("My IP address: ");
Expand Down
10 changes: 4 additions & 6 deletions examples/TelnetClient/TelnetClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
by Tom Igoe
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

// Enter the IP address of the server you're connecting to:
Expand All @@ -41,7 +39,7 @@ EthernetClient client;

void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
Ethernet.begin(ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
Expand Down
10 changes: 4 additions & 6 deletions examples/UDPSendReceiveString/UDPSendReceiveString.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
by Michael Margolis
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
This code is in the public domain.
*/

Expand All @@ -19,11 +20,8 @@
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888; // local port to listen on
Expand All @@ -37,7 +35,7 @@ EthernetUDP Udp;

void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac, ip);
Ethernet.begin(ip);
Udp.begin(localPort);

Serial.begin(9600);
Expand Down
10 changes: 3 additions & 7 deletions examples/UdpNtpClient/UdpNtpClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
by Arturo Guadalupi
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
This code is in the public domain.

*/
Expand All @@ -24,11 +25,6 @@
#include <STM32Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address for your controller below.
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

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

char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server
Expand All @@ -49,7 +45,7 @@ void setup() {


// start Ethernet and UDP
if (Ethernet.begin(mac) == 0) {
if (Ethernet.begin() == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for (;;)
Expand Down
9 changes: 4 additions & 5 deletions examples/WebClient/WebClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
by Tom Igoe, based on work by Adrian McEwen
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address for your controller below.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
Expand All @@ -41,10 +40,10 @@ void setup() {
}

// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
if (Ethernet.begin() == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
Ethernet.begin(ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Expand Down
13 changes: 5 additions & 8 deletions examples/WebClientRepeating/WebClientRepeating.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
by Federico Vanzati
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
http://www.arduino.cc/en/Tutorial/WebClientRepeating
This code is in the public domain.

Expand All @@ -24,15 +25,11 @@
#include <LwIP.h>
#include <STM32Ethernet.h>

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192, 168, 1, 177);

IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
// fill in your Domain Name Server address here:
IPAddress myDns(1, 1, 1, 1);

Expand All @@ -56,7 +53,7 @@ void setup() {
// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection using a fixed IP address and DNS server:
Ethernet.begin(mac, ip, myDns);
Ethernet.begin(ip, subnet, gateway, myDns);
// print the Ethernet board/shield's IP address:
Serial.print("My IP address: ");
Serial.println(Ethernet.localIP());
Expand Down
10 changes: 4 additions & 6 deletions examples/WebServer/WebServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
by Arturo Guadalupi
modified 23 Jun 2017
by Wi6Labs

modified 1 Jun 2018
by sstaub
*/

#include <LwIP.h>
#include <STM32Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// Enter an IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

// Initialize the Ethernet server library
Expand All @@ -42,7 +40,7 @@ void setup() {


// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
Ethernet.begin(ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ remoteIP KEYWORD2
remotePort KEYWORD2
getSocketNumber KEYWORD2
localIP KEYWORD2
macAddress KEYWORD2
maintain KEYWORD2

#######################################
Expand Down
Loading