Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
v1.8.0 to fix macAddress bug, etc.
Browse files Browse the repository at this point in the history
### Releases v1.8.0

1. Fix `macAddress` bug. Check [Unable so set MAC Address #2](#2)
2. Permit setting `macAddress` for supporting Ethernet shields W5x00 and ENC28J60
3. Add functions relating to `macAddress`
4. Rewrite all the examples to support new features
5. Drop support to `Ethernet_ESP8266`
6. Update `Packages' Patches`
  • Loading branch information
khoih-prog authored Sep 8, 2022
1 parent cbee093 commit d04bc0f
Show file tree
Hide file tree
Showing 32 changed files with 690 additions and 1,218 deletions.
40 changes: 30 additions & 10 deletions examples/AM2315_Ethernet/AM2315_Ethernet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,39 @@ void heartBeatPrint()

localEthernetIP = Ethernet.localIP();

#if ( (USE_ETHERNET2 || USE_ETHERNET3) && !(USE_NATIVE_ETHERNET) )
// To modify Ethernet2 library
#if (USE_ETHERNET_GENERIC)

#if USE_W5100
// The linkStatus() is not working with W5100. Just using IP != 0.0.0.0
if ( (uint32_t) localEthernetIP != 0 )
#else
linkStatus = Ethernet.link();
ET_LOGINFO3("localEthernetIP = ", localEthernetIP, ", linkStatus = ", (linkStatus == 1) ? "LinkON" : "LinkOFF" );
ETM_LOGINFO1("localEthernetIP = ", localEthernetIP);

if ( ( linkStatus == 1 ) || ((uint32_t) localEthernetIP != 0) )
#endif

if ( ( linkStatus == 1 ) && ((uint32_t) localEthernetIP != 0) )
#else

// The linkStatus() is not working with W5100. Just using IP != 0.0.0.0
// Better to use ping for W5100
linkStatus = (int) Ethernet.linkStatus();
ET_LOGINFO3("localEthernetIP = ", localEthernetIP, ", linkStatus = ", (linkStatus == LinkON) ? "LinkON" : "LinkOFF" );
if ( ( (linkStatus == LinkON) || !isW5500 ) && ((uint32_t) localEthernetIP != 0) )
ETM_LOGINFO1("localEthernetIP = ", localEthernetIP);

if ( ( (linkStatus == LinkON) || !isW5500 ) || ((uint32_t) localEthernetIP != 0) )
#endif
{
Serial.print(F("H"));
}
else
Serial.print(F("F"));
Serial.print(F("F"));

if (num == 80)
{
Serial.println();

ethernet_manager.printMacAddress();

num = 1;
}
else if (num++ % 10 == 0)
Expand Down Expand Up @@ -127,8 +136,6 @@ void initEthernet()
ET_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
#elif USE_ETHERNET_GENERIC
ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
#elif USE_ETHERNET_ESP8266
ET_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
#elif USE_ETHERNET_ENC
ET_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
#else
Expand Down Expand Up @@ -321,6 +328,19 @@ void setup()
ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin");
#endif

//////////////////////////////////////////////

#define USING_CUSTOM_MAC_ADDRESS false

#if USING_CUSTOM_MAC_ADDRESS
// To use your specified macAddress
byte newMacAddress[6] = { 0xFE, 0xED, 0xDE, 0xAD, 0xBE, 0xEF };

ethernet_manager.setMacAddress(newMacAddress);
#endif

//////////////////////////////////////////////

ethernet_manager.begin();

//////////////////////////////////////////////
Expand Down
33 changes: 21 additions & 12 deletions examples/AM2315_Ethernet/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// Debug Level from 0 to 4
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2
#define _ETHERNET_MANAGER_LOGLEVEL_ 2
#define _ETHERNET_MANAGER_LOGLEVEL_ 4

#define DRD_GENERIC_DEBUG true

Expand Down Expand Up @@ -80,11 +80,27 @@

#if defined(ETHERNET_USE_SAMD)
// For SAMD
// Default pin 10 to SS/CS
#define USE_THIS_SS_PIN 10
// Default pin SS/CS,if no SS pin, use pin 10
#if defined(PIN_SPI_MOSI)
//#warning Using SS pin
#define USE_THIS_SS_PIN 10 //SS
#else
#define USE_THIS_SS_PIN 10
#endif

#if ( defined(ARDUINO_SAMD_ZERO) && !defined(SEEED_XIAO_M0) )
#define BOARD_TYPE "SAMD Zero"

// Default to use W5100. Must change to false for W5500, W5100S, for faster SPI clock
// Must use true for SAMD21, such as Zero, SAMD_FEATHER_M0_EXPRESS, etc.
#define USE_W5100 true

// Use this for ARDUINO_SAMD_ZERO, etc. if can't print to terminal with Serial.print
#if defined(SERIAL_PORT_USBVIRTUAL)
#define Serial SERIAL_PORT_USBVIRTUAL
#warning Using SAMD Zero SerialUSB
#endif

#elif defined(ARDUINO_SAMD_MKR1000)
#define BOARD_TYPE "SAMD MKR1000"
#elif defined(ARDUINO_SAMD_MKRWIFI1010)
Expand Down Expand Up @@ -226,6 +242,7 @@
#endif

#elif ( defined(CORE_TEENSY) )
#error Teensy not supported
// Default pin 10 to SS/CS
#define USE_THIS_SS_PIN 10

Expand Down Expand Up @@ -335,8 +352,6 @@
//#define USE_UIP_ETHERNET true
#define USE_UIP_ETHERNET false

// Note: To rename ESP628266 Ethernet lib files to Ethernet_ESP8266.h and Ethernet_ESP8266.cpp
// In order to USE_ETHERNET_ESP8266
#if ( !defined(USE_UIP_ETHERNET) || !USE_UIP_ETHERNET )

// To override the default CS/SS pin. Don't use unless you know exactly which pin to use
Expand All @@ -346,11 +361,10 @@

// Only one if the following to be true
#define USE_ETHERNET_GENERIC true
#define USE_ETHERNET_ESP8266 false
#define USE_ETHERNET_ENC false
#define USE_CUSTOM_ETHERNET false

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
#ifdef USE_CUSTOM_ETHERNET
#undef USE_CUSTOM_ETHERNET
#endif
Expand All @@ -375,11 +389,6 @@

#include "Ethernet_Generic.h"
#warning Using Ethernet_Generic lib

#elif USE_ETHERNET_ESP8266
#include "Ethernet_ESP8266.h"
#warning Using Ethernet_ESP8266 lib
#define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library"

#elif USE_ETHERNET_ENC
#include "EthernetENC.h"
Expand Down
90 changes: 56 additions & 34 deletions examples/Ethernet_Generic/Ethernet_Generic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ void heartBeatPrint()
localEthernetIP = Ethernet.localIP();

#if (USE_ETHERNET_GENERIC)

#if USE_W5100
// The linkStatus() is not working with W5100. Just using IP != 0.0.0.0
if ( (uint32_t) localEthernetIP != 0 )
#else
linkStatus = Ethernet.link();
ET_LOGINFO3("localEthernetIP = ", localEthernetIP, ", linkStatus = ", (linkStatus == 1) ? "LinkON" : "LinkOFF" );
ETM_LOGINFO1("localEthernetIP = ", localEthernetIP);

if ( ( linkStatus == 1 ) || ((uint32_t) localEthernetIP != 0) )
#endif

if ( ( linkStatus == 1 ) && ((uint32_t) localEthernetIP != 0) )
#else

// The linkStatus() is not working with W5100. Just using IP != 0.0.0.0
// Better to use ping for W5100
linkStatus = (int) Ethernet.linkStatus();
ET_LOGINFO3("localEthernetIP = ", localEthernetIP, ", linkStatus = ", (linkStatus == LinkON) ? "LinkON" : "LinkOFF" );
if ( ( (linkStatus == LinkON) || !isW5500 ) && ((uint32_t) localEthernetIP != 0) )
ETM_LOGINFO1("localEthernetIP = ", localEthernetIP);

if ( ( (linkStatus == LinkON) || !isW5500 ) || ((uint32_t) localEthernetIP != 0) )
#endif
{
Serial.print(F("H"));
Expand All @@ -52,6 +59,9 @@ void heartBeatPrint()
if (num == 80)
{
Serial.println();

ethernet_manager.printMacAddress();

num = 1;
}
else if (num++ % 10 == 0)
Expand All @@ -70,32 +80,31 @@ void check_status()
if ((millis() > checkstatus_timeout))
{
heartBeatPrint();

checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
}
}

void initEthernet()
{
#if ( defined(USE_UIP_ETHERNET) && USE_UIP_ETHERNET )
ET_LOGWARN(F("======== USE_UIP_ETHERNET ========"));
ETM_LOGWARN(F("======== USE_UIP_ETHERNET ========"));
#elif USE_NATIVE_ETHERNET
ET_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
ETM_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
#elif USE_ETHERNET_GENERIC
ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
#elif USE_ETHERNET_ESP8266
ET_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
ETM_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
#elif USE_ETHERNET_ENC
ET_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
ETM_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
#else
ET_LOGWARN(F("========================="));
ETM_LOGWARN(F("========================="));
#endif

ET_LOGWARN(F("Default SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));
ETM_LOGWARN(F("Default SPI pinout:"));
ETM_LOGWARN1(F("MOSI:"), MOSI);
ETM_LOGWARN1(F("MISO:"), MISO);
ETM_LOGWARN1(F("SCK:"), SCK);
ETM_LOGWARN1(F("SS:"), SS);
ETM_LOGWARN(F("========================="));

#if defined(ESP8266)

Expand All @@ -111,7 +120,7 @@ void initEthernet()
#define USE_THIS_SS_PIN D2 // For ESP8266
#endif

ET_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);
ETM_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// For ESP8266
Expand Down Expand Up @@ -160,7 +169,7 @@ void initEthernet()
#endif
#endif

ET_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);
ETM_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);

// For other boards, to change if necessary
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
Expand All @@ -186,9 +195,9 @@ void initEthernet()
#endif

#if defined(BOARD_NAME)
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
ETM_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
#else
ET_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);
ETM_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);
#endif

// For other boards, to change if necessary
Expand All @@ -209,20 +218,20 @@ void initEthernet()

// Just info to know how to connect correctly
#if defined(CUR_PIN_MISO)
ET_LOGWARN(F("Currently Used SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ET_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ET_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
ET_LOGWARN1(F("SS:"), CUR_PIN_SS);
ETM_LOGWARN(F("Currently Used SPI pinout:"));
ETM_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
ETM_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
ETM_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
ETM_LOGWARN1(F("SS:"), CUR_PIN_SS);
#else
ET_LOGWARN(F("Currently Used SPI pinout:"));
ET_LOGWARN1(F("MOSI:"), MOSI);
ET_LOGWARN1(F("MISO:"), MISO);
ET_LOGWARN1(F("SCK:"), SCK);
ET_LOGWARN1(F("SS:"), SS);
ETM_LOGWARN(F("Currently Used SPI pinout:"));
ETM_LOGWARN1(F("MOSI:"), MOSI);
ETM_LOGWARN1(F("MISO:"), MISO);
ETM_LOGWARN1(F("SCK:"), SCK);
ETM_LOGWARN1(F("SS:"), SS);
#endif

ET_LOGWARN(F("========================="));
ETM_LOGWARN(F("========================="));
}

#if USING_CUSTOMS_STYLE
Expand All @@ -234,7 +243,7 @@ void setup()
{
// Debug console
Serial.begin(115200);
while (!Serial);
while (!Serial && millis() < 5000);

delay(200);

Expand Down Expand Up @@ -272,6 +281,19 @@ void setup()
ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin");
#endif

//////////////////////////////////////////////

#define USING_CUSTOM_MAC_ADDRESS true //false

#if USING_CUSTOM_MAC_ADDRESS
// To use your specified macAddress
byte newMacAddress[6] = { 0xFE, 0xED, 0xDE, 0xAD, 0xBE, 0xEF };

ethernet_manager.setMacAddress(newMacAddress);
#endif

//////////////////////////////////////////////

ethernet_manager.begin();

//////////////////////////////////////////////
Expand Down
Loading

0 comments on commit d04bc0f

Please sign in to comment.