Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d6b2eb

Browse files
committed
Merge lwIP_Ethernet library from PResp8266#8317
1 parenta736a95 commit8d6b2eb

File tree

10 files changed

+870
-5
lines changed

10 files changed

+870
-5
lines changed

‎cores/esp8266/LwipIntfDev.h‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
5959
returnIPAddress(ip4_addr_get_u32(ip_2_ip4(&_netif.gw)));
6060
}
6161

62-
voidsetDefault();
62+
voidsetDefault(bool deflt =true);
6363

6464
// true if interface has a valid IPv4 address
6565
boolconnected()
@@ -184,10 +184,10 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
184184
returnfalse;
185185
}
186186

187-
_netif.flags |= NETIF_FLAG_UP;
188-
189187
if (localIP().v4() ==0)
190188
{
189+
// IP not set, starting DHCP
190+
_netif.flags |= NETIF_FLAG_UP;
191191
switch (dhcp_start(&_netif))
192192
{
193193
case ERR_OK:
@@ -201,6 +201,12 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
201201
returnfalse;
202202
}
203203
}
204+
else
205+
{
206+
// IP is set, static config
207+
netif_set_link_up(&_netif);
208+
netif_set_up(&_netif);
209+
}
204210

205211
_started =true;
206212

@@ -386,9 +392,9 @@ err_t LwipIntfDev<RawDev>::handlePackets()
386392
}
387393

388394
template<classRawDev>
389-
void LwipIntfDev<RawDev>::setDefault()
395+
void LwipIntfDev<RawDev>::setDefault(bool deflt)
390396
{
391-
_default =true;
397+
_default =deflt;
392398
if (connected())
393399
{
394400
netif_set_default(&_netif);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
This sketch establishes a TCP connection to a "quote of the day" service.
3+
It sends a "hello" message, and then prints received data.
4+
5+
This is Ethernet version of:
6+
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino
7+
*/
8+
9+
#include<LwipEthernet.h>
10+
11+
Wiznet5500lwIPeth(/*SS*/16);// <== adapt to your hardware
12+
13+
constchar* host ="djxmmx.net";
14+
constuint16_t port =17;
15+
16+
voidsetup() {
17+
Serial.begin(115200);
18+
19+
Serial.println("\nEthernet\n");
20+
21+
eth.setDefault(true);// default route set through this interface
22+
if (!ethInitDHCP(eth)) {
23+
Serial.printf("no hardware found\n");
24+
while (1) {
25+
delay(1000);
26+
}
27+
}
28+
29+
while (!eth.connected()) {
30+
Serial.printf(".");
31+
delay(1000);
32+
}
33+
34+
Serial.printf("Ethernet: IP Address: %s\n",
35+
eth.localIP().toString().c_str());
36+
}
37+
38+
voidloop() {
39+
40+
Serial.print("connecting to");
41+
Serial.print(host);
42+
Serial.print(':');
43+
Serial.println(port);
44+
45+
// Use WiFiClient class to create TCP connections
46+
// (this class could have been named TCPClient)
47+
WiFiClient client;
48+
if (!client.connect(host, port)) {
49+
Serial.println("connection failed");
50+
delay(5000);
51+
return;
52+
}
53+
54+
// This will send a string to the server
55+
Serial.println("sending data to server");
56+
if (client.connected()) {
57+
client.println("hello from ESP8266");
58+
}
59+
60+
// wait for data to be available
61+
unsignedlong timeout =millis();
62+
while (client.available() ==0) {
63+
if (millis() - timeout >5000) {
64+
Serial.println(">>> Client Timeout !");
65+
client.stop();
66+
delay(60000);
67+
return;
68+
}
69+
}
70+
71+
// Read all the lines of the reply from server and print them to Serial
72+
Serial.println("receiving from remote server");
73+
client.sendAll(Serial);// this peer closes once all data are sent
74+
75+
// Close the connection
76+
Serial.println();
77+
Serial.println("closing connection");
78+
client.stop();
79+
80+
delay(600000);// execute once every 10 minutes, don't flood remote service
81+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
This sketch establishes a TCP connection to a "quote of the day" service.
3+
It sends a "hello" message, and then prints received data.
4+
5+
This is Ethernet version of:
6+
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino
7+
*/
8+
9+
#include<LwipEthernet.h>
10+
11+
#defineLOCAL_IPIPAddress(192,168,0,233)
12+
#defineLOCAL_GWIPAddress(192,168,0,254)// <== adapt to your network
13+
#defineLOCAL_MASKIPAddress(255,255,255,0)
14+
#defineDNSIPAddress(8,8,8,8)
15+
16+
Wiznet5500lwIP eth(/*SS*/16);// <== adapt to your hardware
17+
18+
constchar* host ="djxmmx.net";
19+
constuint16_t port =17;
20+
21+
voidsetup() {
22+
Serial.begin(115200);
23+
24+
Serial.println("\nEthernet\n");
25+
26+
eth.setDefault(true);// default route set through this interface
27+
if (!ethInitStatic(eth, LOCAL_IP, LOCAL_GW, LOCAL_MASK, DNS)) {
28+
// enabling debug message will show the real cause
29+
Serial.printf("no hardware found or bad network configuration\n");
30+
while (1) {
31+
delay(1000);
32+
}
33+
}
34+
35+
Serial.printf("Ethernet: IP Address: %s\n",
36+
eth.localIP().toString().c_str());
37+
}
38+
39+
voidloop() {
40+
41+
Serial.print("connecting to");
42+
Serial.print(host);
43+
Serial.print(':');
44+
Serial.println(port);
45+
46+
// Use WiFiClient class to create TCP connections
47+
// (this class could have been named TCPClient)
48+
WiFiClient client;
49+
if (!client.connect(host, port)) {
50+
Serial.println("connection failed");
51+
delay(5000);
52+
return;
53+
}
54+
55+
// This will send a string to the server
56+
Serial.println("sending data to server");
57+
if (client.connected()) {
58+
client.println("hello from ESP8266");
59+
}
60+
61+
// wait for data to be available
62+
unsignedlong timeout =millis();
63+
while (client.available() ==0) {
64+
if (millis() - timeout >5000) {
65+
Serial.println(">>> Client Timeout !");
66+
client.stop();
67+
delay(60000);
68+
return;
69+
}
70+
}
71+
72+
// Read all the lines of the reply from server and print them to Serial
73+
Serial.println("receiving from remote server");
74+
client.sendAll(Serial);// this peer closes once all data are sent
75+
76+
// Close the connection
77+
Serial.println();
78+
Serial.println("closing connection");
79+
client.stop();
80+
81+
delay(600000);// execute once every 10 minutes, don't flood remote service
82+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp