Hello everyone,
I am facing problems while reading IP address of my Ethernet module using EthernetENC.h library. I am using this ethernet module and ESP32. I have used the example code given in arduino's Ethernet.h library and simply replaced #include<Ethernet.h> with #include<EthernetENC.h>. The example code is named DhcpAddressPrinter.
The code works perfectly fine and I can see the IP address as an output on the serial monitor.
But, when I use a different code (took reference from the code given here) I get the output as "Ethernet cable not detected". Even the blinking LEDs near ethernet cable go OFF
Here is my code:
#include <EthernetENC.h>
#include <SPI.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED // here I put the mac of ESP32
};
IPAddress ip(116,75,59,24); // This is the IP address I got in the output of DhcpAddressPrinter code
IPAddress serv(192, 168, 0, 10); // This is my PC's IPv4 address
String tagID = "123ABC";
String RTCtime2 = "2020-11-28%2011:58:30";
String GateNO = "gate4";
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
//EthernetServer server(80);
EthernetClient cliente;
void setup() {
// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
Ethernet.init(5); // ESP32 with Adafruit Featherwing Ethernet
// Open serial communications and wait for port to open:
Serial.begin(115200);
// while (!Serial) {
// ; // wait for serial port to connect. Needed for native USB port only
// }
Serial.println("Ethernet WebServer Example");
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
// start the server
// server.begin();
// Serial.print("server is at ");
// Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
// EthernetClient client = server.available();
if (cliente.connect(serv, 80)) {
Serial.println("new client");
// send a standard http response header
cliente.print(String("GET http://192.168.0.10/connect4.php?") +
("tagID=") + tagID + ("&RTCtimestamp=") + RTCtime2 + ("&GateNO=") + GateNO +
("&i=1") +
" HTTP/1.1\r\n" +
"Host: " + serv + "\r\n" +
"Connection: Keep-Alive\r\n\r\n");
// output the value of each analog input pin
Serial.println(String("GET http://192.168.0.10/connect4.php?") +
("tagID=") + tagID + ("&RTCtimestamp=") + RTCtime2 + ("&GateNO=") + GateNO +
" HTTP/1.1\r\n" +
"Host: " + serv + "\r\n" +
"Connection: Keep-Alive\r\n\r\n");
}
// give the web browser time to receive the data
delay(1);
// close the connection:
cliente.stop();
Serial.println("client disconnected");
}
And this is the output:
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
Ethernet WebServer Example
Ethernet cable is not connected.
My connections are as follows:
MOSI = 23;
MISO = 19;
SCK = 18;
CS = 5;
3.3V=3.3V
GND=GND
I'm probably doing something wrong in the code but I can't see it. Please help me find the mistake here.