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

make WiFi/Ethernet interface compatible with Arduino Ethernet API #8645

Merged
merged 5 commits into from
Jul 27, 2022

Conversation

d-a-v
Copy link
Collaborator

@d-a-v d-a-v commented Jul 20, 2022

While helping a colleague with ethernet on a portenta H7,
I noticed that it was poorly implemented with respect to Official Ethernet Arduino API,
and it does not help foreigners to understand official examples.
Before trying to fix there, looking at esp8266's own backyard first.

Some basic legacy examples are also imported with minimal changes.
They are ethernet examples but they could also run on WiFi.

provide some minimaly adapted examples from legacy
@JAndrassy
Copy link
Contributor

using EthernetServer = ArduinoWiFiServer; I like that

everywhere I recommend to use SDK NTP functions on esp8266. so maybe don't add the NTP example. even it is a good example for UDP same arguments against it apply as for WebClient example.

@d-a-v
Copy link
Collaborator Author

d-a-v commented Jul 20, 2022

using EthernetServer = ArduinoWiFiServer; I like that

And thank you for that :)

everywhere I recommend to use SDK NTP functions on esp8266. so maybe don't add the NTP example. even it is a good example for UDP same arguments against it apply as for WebClient example.

You are totally right. I'll replace it with another UDP example. Suggestions are welcome (even for TCP examples).

@mcspr
Copy link
Collaborator

mcspr commented Jul 22, 2022

Shouldn't ethernet thing go to the ethernet class? I have noticed using Ethernet = WiFi;, but now we have yet another set of enum tokens in a global namespace.

@d-a-v
Copy link
Collaborator Author

d-a-v commented Jul 24, 2022

Shouldn't ethernet thing go to the ethernet class? I have noticed using Ethernet = WiFi;, but now we have yet another set of enum tokens in a global namespace.

Global enums are now moved to the Ethernet class.
These arduino definitions were allowing maximum compatibility with legacy sketch when using WiFi as network.
But I get it ;)

NTP example is removed and replaced by UDP server example.

Copy link
Collaborator

@mcspr mcspr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm then :)
do we care about code in these legacy examples? like, Ethernet.begin(...) == 0 where it is bool, or switch-case on integers instead of DHCP_CHECK..., or the pre-connection link checks that are slightly different between .ino setups

Serial.println(Ethernet.localIP());
break;

default:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need


// start the Ethernet
// Ethernet.begin(mac, ip);
if (Ethernet.begin(mac) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Ethernet.begin(mac) == 0) {
if (!Ethernet.begin(mac)) {

@d-a-v
Copy link
Collaborator Author

d-a-v commented Jul 25, 2022

do we care

The goal is to keep them the closest possible to the original ethernet examples.

--- ../../../Ethernet/examples/ChatServer/ChatServer.ino	2022-07-18 22:17:20.550672427 +0200
+++ LegacyChatServer.ino	2022-07-20 03:12:30.293107744 +0200
@@ -7,7 +7,7 @@
  Using an Arduino Wiznet Ethernet shield.
 
  Circuit:
- * Ethernet shield attached to pins 10, 11, 12, 13
+ * Ethernet Wiznet5500/Wiznet5100/ENC28J60 on esp8266
 
  created 18 Dec 2009
  by David A. Mellis
@@ -16,14 +16,22 @@
 
  */
 
-#include <SPI.h>
-#include <Ethernet.h>
+
+// specific to esp8266 w/lwIP
+#include <EthernetCompat.h>
+ArduinoWiznet5500lwIP Ethernet(/*SS*/ 16);  // <== adapt to your hardware
+// ArduinoWiznet5100lwIP Ethernet(/*SS*/ 16);  // <== adapt to your hardware
+// ArduinoENC28J60lwIP Ethernet(/*SS*/ 16);  // <== adapt to your hardware
 
 // Enter a MAC address and 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 };
+byte notNeededButAllowed_mac[] = {
+  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
+};
+byte* mac = nullptr;  // automatic mac
 IPAddress ip(192, 168, 1, 177);
 IPAddress myDns(192, 168, 1, 1);
 IPAddress gateway(192, 168, 1, 1);
@@ -36,12 +44,13 @@
 
   // Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
+  //                     // esp8266 w/lwIP: SS set in Ethernet constructor
 
   // initialize the ethernet device
   Ethernet.begin(mac, ip, myDns, gateway, subnet);

@d-a-v d-a-v merged commit ee7ac2f into esp8266:master Jul 27, 2022
@d-a-v d-a-v deleted the ArduinoEthernetCompat branch July 27, 2022 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants