-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
introduce yieldUntil(untilFunction, timeoutMs)
#8317
Closed
Closed
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
632260d
introduce `yieldUntil(untilFonction, timeoutMs)` which is a delay int…
d-a-v 7acc813
Merge branch 'master' into ethdelay
d-a-v fad4d17
simplification
d-a-v 6b8eeff
Ethernet: add examples (dhcp, static, mdns, ssl)
d-a-v 98aac7d
style
d-a-v 7ae8d0b
use scalar for gpio
d-a-v a69d4d6
further simplification
d-a-v 8a07ca8
per review
d-a-v 1fac913
fix comments and add debug messages
d-a-v 4ba8b31
Merge branch 'master' into ethdelay
d-a-v 639ec45
fix example
d-a-v 18dc923
default interface set from userland
d-a-v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
This sketch establishes a TCP connection to a "quote of the day" service. | ||
It sends a "hello" message, and then prints received data. | ||
|
||
This is Ethernet version of: | ||
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino | ||
*/ | ||
|
||
#include <LwipEthernet.h> | ||
|
||
Wiznet5500lwIP eth(/*SS*/16); // <== adapt to your hardware | ||
|
||
const char* host = "djxmmx.net"; | ||
const uint16_t port = 17; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
Serial.println("\nEthernet\n"); | ||
|
||
if (!ethInitDHCP(eth)) { | ||
Serial.printf("no hardware found\n"); | ||
while (1) { | ||
delay(1000); | ||
} | ||
} | ||
|
||
while (!eth.connected()) { | ||
Serial.printf("."); | ||
delay(1000); | ||
} | ||
|
||
Serial.printf("Ethernet: IP Address: %s\n", | ||
eth.localIP().toString().c_str()); | ||
} | ||
|
||
void loop() { | ||
|
||
Serial.print("connecting to "); | ||
Serial.print(host); | ||
Serial.print(':'); | ||
Serial.println(port); | ||
|
||
// Use WiFiClient class to create TCP connections | ||
// (this class could have been named TCPClient) | ||
WiFiClient client; | ||
if (!client.connect(host, port)) { | ||
Serial.println("connection failed"); | ||
delay(5000); | ||
return; | ||
} | ||
|
||
// This will send a string to the server | ||
Serial.println("sending data to server"); | ||
if (client.connected()) { | ||
client.println("hello from ESP8266"); | ||
} | ||
|
||
// wait for data to be available | ||
unsigned long timeout = millis(); | ||
while (client.available() == 0) { | ||
if (millis() - timeout > 5000) { | ||
Serial.println(">>> Client Timeout !"); | ||
client.stop(); | ||
delay(60000); | ||
return; | ||
} | ||
} | ||
|
||
// Read all the lines of the reply from server and print them to Serial | ||
Serial.println("receiving from remote server"); | ||
client.sendAll(Serial); // this peer closes once all data are sent | ||
|
||
// Close the connection | ||
Serial.println(); | ||
Serial.println("closing connection"); | ||
client.stop(); | ||
|
||
delay(600000); // execute once every 10 minutes, don't flood remote service | ||
} |
80 changes: 80 additions & 0 deletions
80
libraries/lwIP_Ethernet/examples/EthClientStatic/EthClientStatic.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
This sketch establishes a TCP connection to a "quote of the day" service. | ||
It sends a "hello" message, and then prints received data. | ||
|
||
This is Ethernet version of: | ||
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino | ||
*/ | ||
|
||
#include <LwipEthernet.h> | ||
|
||
#define LOCAL_IP 192,168,0,233 | ||
#define LOCAL_GW 192,168,0,254 // <== adapt to your network | ||
#define LOCAL_MASK 255,255,255,0 | ||
#define DNS 8,8,8,8 | ||
|
||
Wiznet5500lwIP eth(/*SS*/16); // <== adapt to your hardware | ||
|
||
const char* host = "djxmmx.net"; | ||
const uint16_t port = 17; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
Serial.println("\nEthernet\n"); | ||
|
||
if (!ethInitStatic(eth, IPAddress(LOCAL_IP), IPAddress(LOCAL_GW), IPAddress(LOCAL_MASK), IPAddress(DNS))) { | ||
Serial.printf("no hardware found\n"); | ||
while (1) { | ||
delay(1000); | ||
} | ||
} | ||
|
||
Serial.printf("Ethernet: IP Address: %s\n", | ||
eth.localIP().toString().c_str()); | ||
} | ||
|
||
void loop() { | ||
|
||
Serial.print("connecting to "); | ||
Serial.print(host); | ||
Serial.print(':'); | ||
Serial.println(port); | ||
|
||
// Use WiFiClient class to create TCP connections | ||
// (this class could have been named TCPClient) | ||
WiFiClient client; | ||
if (!client.connect(host, port)) { | ||
Serial.println("connection failed"); | ||
delay(5000); | ||
return; | ||
} | ||
|
||
// This will send a string to the server | ||
Serial.println("sending data to server"); | ||
if (client.connected()) { | ||
client.println("hello from ESP8266"); | ||
} | ||
|
||
// wait for data to be available | ||
unsigned long timeout = millis(); | ||
while (client.available() == 0) { | ||
if (millis() - timeout > 5000) { | ||
Serial.println(">>> Client Timeout !"); | ||
client.stop(); | ||
delay(60000); | ||
return; | ||
} | ||
} | ||
|
||
// Read all the lines of the reply from server and print them to Serial | ||
Serial.println("receiving from remote server"); | ||
client.sendAll(Serial); // this peer closes once all data are sent | ||
|
||
// Close the connection | ||
Serial.println(); | ||
Serial.println("closing connection"); | ||
client.stop(); | ||
|
||
delay(600000); // execute once every 10 minutes, don't flood remote service | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Changing it to
true
allows to avoid calling manuallyeth.setDefault()
, which is necessary for valid routing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense for one instance, true. ok if not a problem
(but, I wonder if default=false would be safer when there are more)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are more than one interface, only the last "defaulted" one becomes the default route.
I will investigate further on why this is necessary, but last time I checked packets are not routed without it.
I could have delegated the directive to "userland" but I think it is better to let the library deal with defaults so we don't need to change the API or the guidelines / examples when something changes or is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see also WiFi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the instance variable does not make sense and it should be a static (and shared between the wifi and the lwipintf class), if every interface wants to become the default on callback?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
I have moved the default value back to
false
and updated examples to explicitly use the new interface as default route.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the lwip part also be made aware of default modifications? (with another issue / pr, I gather, not to pollute the changes too too much)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modification for "default" is reverted to what it was before the PR no ?
If the question is about "lwip2 - the driver adapter", it is very delicate to update the WiFi interface management code per possible hidden side effect. Maybe a new gh-issue describing the API question might be indeed opened for that purpose.