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

Commit

Permalink
v1.4.1 to use Ethernet_Generic library, etc.
Browse files Browse the repository at this point in the history
### Releases v1.4.1

1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.
2. Add support to SPI1 for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico)
3. Rewrite all the examples to support new features
4. Update `Packages' Patches`
  • Loading branch information
khoih-prog authored Apr 12, 2022
1 parent 9a9cf4a commit 754935e
Show file tree
Hide file tree
Showing 23 changed files with 1,411 additions and 602 deletions.
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.12, Adafruit SAMD core v1.7.7, Seeed Studio SAMD v1.8.2)
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP32 core v2.0.2, ESP8266 core v3.0.2, ArduinoCore-mbed v3.0.1, etc.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
Expand All @@ -27,9 +27,10 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
Arduino SAMD Core Version 1.8.12
RASPBERRY_PI_PICO board
ArduinoCore-mbed v3.0.1
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
The board couldn't autoreconnect to Local Blynk Server after router power recycling.
Expand Down
364 changes: 192 additions & 172 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.4.1](#releases-v141)
* [Releases v1.4.0](#releases-v140)
* [Releases v1.3.1](#releases-v131)
* [Releases v1.3.0](#releases-v130)
Expand All @@ -28,6 +29,13 @@

## Changelog

### Releases v1.4.1

1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.
2. Add support to SPI1 for RP2040 using [arduino-pico core](https://github.com/earlephilhower/arduino-pico)
3. Rewrite all the examples to support new features
4. Update `Packages' Patches`

### Releases v1.4.0

1. Fix `multiple-definitions` linker error.
Expand Down
261 changes: 209 additions & 52 deletions examples/Ethernet/DiscoveringServices/DiscoveringServices.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,87 +35,244 @@ MDNS mdns(udp);
void serviceFound(const char* type, MDNSServiceProtocol proto, const char* name, IPAddress ip,
unsigned short port, const char* txtContent);

void setup()
uint16_t macIndex;

void initEthernet()
{
Serial.begin(115200);
while (!Serial);
#if USE_ETHERNET_PORTENTA_H7
MDNS_LOGWARN(F("======== USE_PORTENTA_H7_ETHERNET ========"));
#elif USE_NATIVE_ETHERNET
MDNS_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
#elif USE_ETHERNET_GENERIC
MDNS_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
#elif USE_ETHERNET_ESP8266
MDNS_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
#elif USE_ETHERNET_ENC
MDNS_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
#else
MDNS_LOGWARN(F("========================="));
#endif

Serial.print("\nStart DiscoveringServices on "); Serial.print(BOARD_NAME);
Serial.print(" using "); Serial.println(SHIELD_TYPE);
Serial.println(MDNS_GENERIC_VERSION);
#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)

#if (USING_SPI2)
#if defined(CUR_PIN_MISO)
MDNS_LOGWARN(F("Default SPI pinout:"));
MDNS_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
MDNS_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
MDNS_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
MDNS_LOGWARN1(F("SS:"), CUR_PIN_SS);
MDNS_LOGWARN(F("========================="));
#endif
#else
MDNS_LOGWARN(F("Default SPI pinout:"));
MDNS_LOGWARN1(F("MOSI:"), MOSI);
MDNS_LOGWARN1(F("MISO:"), MISO);
MDNS_LOGWARN1(F("SCK:"), SCK);
MDNS_LOGWARN1(F("SS:"), SS);
MDNS_LOGWARN(F("========================="));
#endif

#if defined(ESP8266)
// For ESP8266, change for other boards if necessary
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN D2 // For ESP8266
#endif

MDNS_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// For ESP8266
// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
// EthernetGeneric X X X X X 0
// Ethernet_ESP8266 0 0 0 0 0 0
// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
// Must use library patch for Ethernet, EthernetLarge libraries
Ethernet.init (USE_THIS_SS_PIN);

#elif USE_CUSTOM_ETHERNET

// You have to add initialization for your Custom Ethernet here
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#elif defined(ESP32)

Serial.println(("========================="));
Serial.println(("Default SPI pinout:"));
Serial.print("MOSI:");
Serial.println(MOSI);
Serial.print("MISO:");
Serial.println(MISO);
Serial.print("SCK:");
Serial.println(SCK);
Serial.print("SS:");
Serial.println(SS);
Serial.println(("========================="));
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet

#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 5 //22 // For ESP32
#endif

MDNS_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);

// For other boards, to change if necessary
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, EthernetLarge libraries
// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3

//Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (USE_THIS_SS_PIN);

#elif USE_CUSTOM_ETHERNET

// You have to add initialization for your Custom Ethernet here
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#elif ETHERNET_USE_RPIPICO

pinMode(USE_THIS_SS_PIN, OUTPUT);
digitalWrite(USE_THIS_SS_PIN, HIGH);

// ETHERNET_USE_RPIPICO, use default SS = 5 or 17
#ifndef USE_THIS_SS_PIN
#if defined(ARDUINO_ARCH_MBED)
#define USE_THIS_SS_PIN 5 // For Arduino Mbed core
#else
#define USE_THIS_SS_PIN 17 // For E.Philhower core
#endif
#endif

MDNS_LOGWARN1(F("RPIPICO setCsPin:"), USE_THIS_SS_PIN);

// For other boards, to change if necessary
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, EthernetLarge libraries
// For RPI Pico using Arduino Mbed RP2040 core
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
// For RPI Pico using E. Philhower RP2040 core
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
// Default pin 5/17 to SS/CS

//Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#else //defined(ESP8266)
// unknown board, do nothing, use default SS = 10
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 10 // For other boards
#endif
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 10 // For other boards
#endif

MDNS_LOGERROR3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
#if defined(BOARD_NAME)
MDNS_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
#else
MDNS_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);
#endif

// For other boards, to change if necessary
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 )
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries

Ethernet.init (USE_THIS_SS_PIN);

#elif USE_ETHERNET3
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
#ifndef ETHERNET3_MAX_SOCK_NUM
#define ETHERNET3_MAX_SOCK_NUM 4
#endif
#elif USE_CUSTOM_ETHERNET

Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
// You have to add initialization for your Custom Ethernet here
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#endif // defined(ESP8266)

#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
#endif // #if !(USE_NATIVE_ETHERNET)

// start the ethernet connection and the server:
// Use Static IP
//Ethernet.begin(mac, ip);
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;
//uint16_t macIndex = millis() % NUMBER_OF_MAC;
macIndex = millis() % NUMBER_OF_MAC;
// Use Static IP
//Ethernet.begin(mac[macIndex], ip);
Ethernet.begin(mac[macIndex]);

#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)
MDNS_LOGWARN(F("========================="));

#if defined( ESP32 )
// Just info to know how to connect correctly
// To change for other SPI
MDNS_LOGWARN(F("Currently Used SPI pinout:"));
MDNS_LOGWARN1(F("MOSI:"), PIN_MOSI);
MDNS_LOGWARN1(F("MISO:"), PIN_MISO);
MDNS_LOGWARN1(F("SCK:"), PIN_SCK);
MDNS_LOGWARN1(F("SS:"), PIN_SS);
#else
#if defined(CUR_PIN_MISO)
MDNS_LOGWARN(F("Currently Used SPI pinout:"));
MDNS_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
MDNS_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
MDNS_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
MDNS_LOGWARN1(F("SS:"), CUR_PIN_SS);
#else
MDNS_LOGWARN(F("Currently Used SPI pinout:"));
MDNS_LOGWARN1(F("MOSI:"), MOSI);
MDNS_LOGWARN1(F("MISO:"), MISO);
MDNS_LOGWARN1(F("SCK:"), SCK);
MDNS_LOGWARN1(F("SS:"), SS);
#endif
#endif

MDNS_LOGWARN(F("========================="));

#elif (USE_ETHERNET_PORTENTA_H7)
if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("No Ethernet found. Stay here forever");

while (true)
{
delay(1); // do nothing, no point running without Ethernet hardware
}
}

if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println("Not connected Ethernet cable");
}
#endif

Serial.print(F("Using mac index = "));
Serial.println(macIndex);

Serial.print(F("Connected! IP address: "));
Serial.println(Ethernet.localIP());
}

Ethernet.begin(mac[index]);
void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);

// Just info to know how to connect correctly
Serial.println("=========================");
Serial.println("Currently Used SPI pinout:");
Serial.print("MOSI:");
Serial.println(MOSI);
Serial.print("MISO:");
Serial.println(MISO);
Serial.print("SCK:");
Serial.println(SCK);
Serial.print("SS:");
Serial.println(SS);
Serial.println("=========================");
Serial.print("\nStart DiscoveringServices on "); Serial.print(BOARD_NAME);
Serial.print(" using "); Serial.println(SHIELD_TYPE);
Serial.println(MDNS_GENERIC_VERSION);

Serial.print("Using mac index = ");
Serial.println(index);
initEthernet();

Serial.print("Connected! IP address: ");
Serial.println(Ethernet.localIP());

// Initialize the mDNS library. You can now reach or ping this
// Arduino via the host name "arduino.local", provided that your operating
// system is mDNS/Bonjour-enabled (such as MacOS X).
// Always call this before any other method!
String hostname = String(BOARD_NAME) + "_" + String(index);
String hostname = String(BOARD_NAME) + "_" + String(macIndex);

//hostname.toUpperCase();
hostname.toLowerCase();
hostname.replace(" ", "-");
hostname.replace(".", "-");
hostname.replace("_", "-");

Serial.print("Registering mDNS hostname: "); Serial.println(hostname);
Expand Down
Loading

0 comments on commit 754935e

Please sign in to comment.