Orphic
August 20, 2021, 10:58am
15
Juraj:
#include <SPI.h>
#include <ENC28J60lwIP.h>
#include <ESP8266WiFi.h>
const char* host = "djxmmx.net";
const uint16_t port = 17;
#define CSPIN D1
ENC28J60lwIP eth(CSPIN);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(23, 28, 179, 206);
void setup() {
Serial.begin(115200);
delay(500);
WiFi.mode(WIFI_OFF);
SPI.begin();
// if (!eth.config(ip, gw, nm, gw, IPADDR_NONE)) {
// Serial.println("wrong config");
// }
eth.setDefault(); // use ethernet for default route
if (!eth.begin(mac)) {
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());
Serial.println(eth.gatewayIP());
Serial.println(eth.subnetMask());
Serial.println(WiFi.dnsIP());
}
void loop() {
static bool wait = true;
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
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");
// not testing 'client.connected()' since we do not need to send data here
while (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;
}
Thank you for your immediate response
connecting ethernet...
ethernet IP address: 192.168.1.105
192.168.1.1
255.255.255.0
192.168.1.1
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
connection failed
connecting to djxmmx.net:17
sending data to server
receiving from remote server
"Oh the nerves, the nerves; the mysteries of this machine called man!
Oh the little that unhinges it, poor creatures that we are!"
Charles Dickens (1812-70)