You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is a modified TCPClient example from the LwIP_w5500 library:
/* This sketch establishes a TCP connection to a "quote of the day" service. It sends a "hello" message, and then prints received data.*/
#include<SPI.h>//#include <W5500lwIP.h>//or #include <W5100lwIP.h>
#include<ENC28J60lwIP.h>
#include<WiFiClient.h>// WiFiClient (-> TCPClient)constchar* host = "djxmmx.net";
constuint16_t port = 17;
using TCPClient = WiFiClient;
#defineCSPIN D1 // wemos/lolin/nodemcu D0
ENC28J60lwIP eth(CSPIN);
voidsetup() {
Serial.begin(115200);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz?
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
eth.setDefault(); // use ethernet for default route
IPAddress ip(192, 168, 1, 118);
IPAddress gw(192, 168, 1, 1);
IPAddress nm(255, 255, 255, 0);
eth.config(ip, gw, nm, gw);
if (!eth.begin()) {
Serial.println("ethernet hardware not found ... sleeping");
while (1) {
delay(1000);
}
} else {
Serial.print("connecting ethernet");
while (!eth.connected()) {
Serial.print(".");
delay(1000);
}
}
Serial.println();
Serial.print("ethernet IP address: ");
Serial.println(eth.localIP());
}
voidloop() {
staticboolwait = false;
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
TCPClient 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 availableunsignedlong 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");
// not testing 'client.connected()' since we do not need to send data herewhile (client.available()) {
char ch = static_cast<char>(client.read());
Serial.print(ch);
}
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
if (wait) {
delay(300000); // execute once every 5 minutes, don't flood remote service
}
wait = true;
}
Debug Messages
SDK:2.2.2-dev(38a443e)/Core:3.0.0=30000000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-48-g7421258/BearSSL:c0b69df
connecting ethernet
ethernet IP address: 192.168.1.118
connecting to djxmmx.net:17
[hostByName] request IP for: djxmmx.net
[hostByName] Host: djxmmx.net lookup error: -5!
connection failed
connecting to djxmmx.net:17
[hostByName] request IP for: djxmmx.net
[hostByName] Host: djxmmx.net IP: 104.9.242.101
connection failed
connecting to djxmmx.net:17
[hostByName] request IP for: djxmmx.net
[hostByName] Host: djxmmx.net IP: 104.9.242.101
connection failed
with setDefault after config
SDK:2.2.2-dev(38a443e)/Core:3.0.0=30000000/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-48-g7421258/BearSSL:c0b69df
connecting ethernet
ethernet IP address: 192.168.1.118
connecting to djxmmx.net:17
[hostByName] request IP for: djxmmx.net
[hostByName] Host: djxmmx.net lookup error: -5!
connection failed
connecting to djxmmx.net:17
[hostByName] request IP for: djxmmx.net
[hostByName] Host: djxmmx.net IP: 23.28.179.206
sending data to server
receiving from remote server
"Here's the rule for bargains: "Do other men, for they would do you."
That's the true business precept." Charles Dickens (1812-70)
closing connection
connecting to djxmmx.net:17
[hostByName] request IP for: djxmmx.net
[hostByName] Host: djxmmx.net IP: 23.28.179.206
sending data to server
receiving from remote server
"A wonderful fact to reflect upon, that every human creature is constituted
to be that profound secret and mystery to every other."
Charles Dickens (1812-70)
closing connection
The text was updated successfully, but these errors were encountered:
Basic Infos
Platform
Settings in IDE
Problem Description
Ethernet LwIP interfaces static IP configuration only works if eth.config is followed by eth.setDefault().
MCVE Sketch
It is a modified TCPClient example from the LwIP_w5500 library:
Debug Messages
with
setDefault
afterconfig
The text was updated successfully, but these errors were encountered: