Skip to content

Commit fa66984

Browse files
sstaubfpistm
authored andcommitted
MAC support (#11)
Mac address support Signed-off-by: sstaub <[email protected]>
1 parent eb156a3 commit fa66984

File tree

16 files changed

+166
-68
lines changed

16 files changed

+166
-68
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Paul Stoffregen https://github.com/PaulStoffregen
3131
per1234 https://github.com/per1234
3232
Richard Sim
3333
Scott Fitzgerald https://github.com/shfitz
34+
Stefan Staub https://github.com/sstaub
3435
STMicroelectronics https://github.com/stm32duino
3536
Thibaut Viard https://github.com/aethaniel
3637
Tom Igoe https://github.com/tigoe

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ This library provides a default user defined options file named `lwipopts_defaul
2424

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

27+
28+
## New alternative init procedure **!!!**
29+
30+
There are alternative inits of the Ethernetinterface with following orders:
31+
32+
Ethernet.begin();
33+
Ethernet.begin(ip);
34+
Ethernet.begin(ip, subnet);
35+
Ethernet.begin(ip, subnet, gateway);
36+
Ethernet.begin(ip, subnet, gateway, dns);
37+
38+
This is more logical. A MAC address is no more needed and will retrieved internally by the mbed MAC address!
39+
40+
You can get the MAC address with following function, this must done after Ethernet.Begin()
41+
42+
uint8_t *mac;
43+
Ethernet.begin();
44+
mac = Ethernet.macAddress();
45+
46+
You can also set a new user based MAC address, this must done before Ethernet.begin()
47+
48+
uint8_t newMAC[] = {0x00, 0x80, 0xE1, 0x01, 0x01, 0x01};
49+
Ethernet.macAddress(newMAC);
50+
Ethernet.begin();
51+
2752
## Note
2853

2954
`EthernetClass::maintain()` in no more required to renew IP address from DHCP.<br>

examples/AdvancedChatServer/AdvancedChatServer.ino

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
by Norbert Truchsess
1818
modified 23 Jun 2017
1919
by Wi6Labs
20+
modified 1 Jun 2018
21+
by sstaub
2022
2123
*/
2224

2325
#include <LwIP.h>
2426
#include <STM32Ethernet.h>
2527

26-
// Enter a MAC address and IP address for your controller below.
28+
// Enter an IP address for your controller below.
2729
// The IP address will be dependent on your local network.
2830
// gateway and subnet are optional:
29-
byte mac[] = {
30-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
31-
};
31+
3232
IPAddress ip(192, 168, 1, 177);
3333
IPAddress myDns(192, 168, 1, 1);
3434
IPAddress gateway(192, 168, 1, 1);
@@ -42,7 +42,7 @@ EthernetClient clients[4];
4242

4343
void setup() {
4444
// initialize the Ethernet device
45-
Ethernet.begin(mac, ip, myDns, gateway, subnet);
45+
Ethernet.begin(ip, subnet, gateway, myDns);
4646
// start listening for clients
4747
server.begin();
4848
// Open serial communications and wait for port to open:

examples/BarometricPressureWebServer/BarometricPressureWebServer.ino

+3-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
by Tom Igoe
2121
modified 23 Jun 2017
2222
by Wi6Labs
23+
modified 1 Jun 2018
24+
by sstaub
2325
*/
2426

2527
#include <LwIP.h>
@@ -28,11 +30,6 @@
2830
#include <SPI.h>
2931

3032

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

@@ -62,7 +59,7 @@ void setup() {
6259
SPI.begin();
6360

6461
// start the Ethernet connection and the server:
65-
Ethernet.begin(mac, ip);
62+
Ethernet.begin(ip);
6663
server.begin();
6764

6865
// initalize the data ready and chip select pins:

examples/ChatServer/ChatServer.ino

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
by Tom Igoe
1515
modified 23 Jun 2017
1616
by Wi6Labs
17+
modified 1 Jun 2018
18+
by sstaub
1719
*/
1820

1921
#include <LwIP.h>
2022
#include <STM32Ethernet.h>
2123

22-
// Enter a MAC address and IP address for your controller below.
24+
// Enter an IP address for your controller below.
2325
// The IP address will be dependent on your local network.
2426
// gateway and subnet are optional:
25-
byte mac[] = {
26-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
27-
};
27+
2828
IPAddress ip(192, 168, 1, 177);
2929
IPAddress myDns(192,168,1, 1);
3030
IPAddress gateway(192, 168, 1, 1);
@@ -37,7 +37,7 @@ boolean alreadyConnected = false; // whether or not the client was connected pre
3737

3838
void setup() {
3939
// initialize the ethernet device
40-
Ethernet.begin(mac, ip, myDns, gateway, subnet);
40+
Ethernet.begin(ip, subnet, gateway, myDns);
4141
// start listening for clients
4242
server.begin();
4343
// Open serial communications and wait for port to open:

examples/DhcpAddressPrinter/DhcpAddressPrinter.ino

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
by Arturo Guadalupi
1515
modified 23 Jun 2017
1616
by Wi6Labs
17+
modified 1 Jun 2018
18+
by sstaub
1719
*/
1820

1921
#include <LwIP.h>
2022
#include <STM32Ethernet.h>
2123

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

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

4038
// start the Ethernet connection:
41-
if (Ethernet.begin(mac) == 0) {
39+
if (Ethernet.begin() == 0) {
4240
Serial.println("Failed to configure Ethernet using DHCP");
4341
// no point in carrying on, so do nothing forevermore:
4442
for (;;)

examples/DhcpChatServer/DhcpChatServer.ino

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@
1818
Based on ChatServer example by David A. Mellis
1919
modified 23 Jun 2017
2020
by Wi6Labs
21-
21+
modified 1 Jun 2018
22+
by sstaub
2223
*/
2324

2425
#include <LwIP.h>
2526
#include <STM32Ethernet.h>
2627

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

5149
// start the Ethernet connection:
5250
Serial.println("Trying to get an IP address using DHCP");
53-
if (Ethernet.begin(mac) == 0) {
51+
if (Ethernet.begin() == 0) {
5452
Serial.println("Failed to configure Ethernet using DHCP");
5553
// initialize the Ethernet device not using DHCP:
56-
Ethernet.begin(mac, ip, myDns, gateway, subnet);
54+
Ethernet.begin(ip, subnet, gateway, myDns);
5755
}
5856
// print your local IP address:
5957
Serial.print("My IP address: ");

examples/TelnetClient/TelnetClient.ino

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
by Tom Igoe
1818
modified 23 Jun 2017
1919
by Wi6Labs
20-
20+
modified 1 Jun 2018
21+
by sstaub
2122
*/
2223

2324
#include <LwIP.h>
2425
#include <STM32Ethernet.h>
2526

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

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

4240
void setup() {
4341
// start the Ethernet connection:
44-
Ethernet.begin(mac, ip);
42+
Ethernet.begin(ip);
4543
// Open serial communications and wait for port to open:
4644
Serial.begin(9600);
4745
while (!Serial) {

examples/UDPSendReceiveString/UDPSendReceiveString.ino

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
by Michael Margolis
1111
modified 23 Jun 2017
1212
by Wi6Labs
13-
13+
modified 1 Jun 2018
14+
by sstaub
1415
This code is in the public domain.
1516
*/
1617

@@ -19,11 +20,8 @@
1920
#include <EthernetUdp.h> // UDP library from: [email protected] 12/30/2008
2021

2122

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

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

3836
void setup() {
3937
// start the Ethernet and UDP:
40-
Ethernet.begin(mac, ip);
38+
Ethernet.begin(ip);
4139
Udp.begin(localPort);
4240

4341
Serial.begin(9600);

examples/UdpNtpClient/UdpNtpClient.ino

+3-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
by Arturo Guadalupi
1616
modified 23 Jun 2017
1717
by Wi6Labs
18-
18+
modified 1 Jun 2018
19+
by sstaub
1920
This code is in the public domain.
2021
2122
*/
@@ -24,11 +25,6 @@
2425
#include <STM32Ethernet.h>
2526
#include <EthernetUdp.h>
2627

27-
// Enter a MAC address for your controller below.
28-
byte mac[] = {
29-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
30-
};
31-
3228
unsigned int localPort = 8888; // local port to listen for UDP packets
3329

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

5046

5147
// start Ethernet and UDP
52-
if (Ethernet.begin(mac) == 0) {
48+
if (Ethernet.begin() == 0) {
5349
Serial.println("Failed to configure Ethernet using DHCP");
5450
// no point in carrying on, so do nothing forevermore:
5551
for (;;)

examples/WebClient/WebClient.ino

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
by Tom Igoe, based on work by Adrian McEwen
1313
modified 23 Jun 2017
1414
by Wi6Labs
15-
15+
modified 1 Jun 2018
16+
by sstaub
1617
*/
1718

1819
#include <LwIP.h>
1920
#include <STM32Ethernet.h>
2021

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

4342
// start the Ethernet connection:
44-
if (Ethernet.begin(mac) == 0) {
43+
if (Ethernet.begin() == 0) {
4544
Serial.println("Failed to configure Ethernet using DHCP");
4645
// try to congifure using IP address instead of DHCP:
47-
Ethernet.begin(mac, ip);
46+
Ethernet.begin(ip);
4847
}
4948
// give the Ethernet shield a second to initialize:
5049
delay(1000);

examples/WebClientRepeating/WebClientRepeating.ino

+5-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
by Federico Vanzati
1616
modified 23 Jun 2017
1717
by Wi6Labs
18-
18+
modified 1 Jun 2018
19+
by sstaub
1920
http://www.arduino.cc/en/Tutorial/WebClientRepeating
2021
This code is in the public domain.
2122
@@ -24,15 +25,11 @@
2425
#include <LwIP.h>
2526
#include <STM32Ethernet.h>
2627

27-
// assign a MAC address for the ethernet controller.
28-
// fill in your address here:
29-
byte mac[] = {
30-
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
31-
};
3228
// fill in an available IP address on your network here,
3329
// for manual configuration:
3430
IPAddress ip(192, 168, 1, 177);
35-
31+
IPAddress gateway(192, 168, 1, 1);
32+
IPAddress subnet(255, 255, 0, 0);
3633
// fill in your Domain Name Server address here:
3734
IPAddress myDns(1, 1, 1, 1);
3835

@@ -56,7 +53,7 @@ void setup() {
5653
// give the ethernet module time to boot up:
5754
delay(1000);
5855
// start the Ethernet connection using a fixed IP address and DNS server:
59-
Ethernet.begin(mac, ip, myDns);
56+
Ethernet.begin(ip, subnet, gateway, myDns);
6057
// print the Ethernet board/shield's IP address:
6158
Serial.print("My IP address: ");
6259
Serial.println(Ethernet.localIP());

examples/WebServer/WebServer.ino

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
by Arturo Guadalupi
1616
modified 23 Jun 2017
1717
by Wi6Labs
18-
18+
modified 1 Jun 2018
19+
by sstaub
1920
*/
2021

2122
#include <LwIP.h>
2223
#include <STM32Ethernet.h>
2324

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

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

4341

4442
// start the Ethernet connection and the server:
45-
Ethernet.begin(mac, ip);
43+
Ethernet.begin(ip);
4644
server.begin();
4745
Serial.print("server is at ");
4846
Serial.println(Ethernet.localIP());

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ remoteIP KEYWORD2
3232
remotePort KEYWORD2
3333
getSocketNumber KEYWORD2
3434
localIP KEYWORD2
35+
macAddress KEYWORD2
3536
maintain KEYWORD2
3637

3738
#######################################

0 commit comments

Comments
 (0)