Display DHCP information on Arduino

HI Everyone

I am trying to build an arduino project that displays “Dhcp information” on a 4 line lcd.
There is a video I have seen on youtube that is exactly what I want,i copied the code and libraries but unsucessfull.The guy who made this project doesn’t reply to me and I would like assistance from you Arduino crew please.On the
His link :

The compiler stops at “Socket was not declared”

PLEASE HELP ME

His Code I copied:

#include <SPI.h>
#include <Ethernet.h>
#include <ICMPPing.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);

byte mac = {
0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};
String ip = “”;
String subnetmask = “”;
String gateway = “”;
String dhcpserver = “”;
String dnsserver = “”;
SOCKET pingSocket = 0;
char buffer [255];

void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
}

void loop() {

lcd.init();
lcd.backlight();
while(1==1) {
EthernetClient client;
lcd.setCursor ( 0, 0 );
lcd.print(" ------------------ “);
lcd.setCursor ( 0, 1 );
lcd.print(”| DER GROSSE |");
lcd.setCursor ( 0, 2 );
lcd.print("| MUTATO |");
lcd.setCursor ( 0, 3 );
lcd.print(" ------------------ “);
delay(500);
lcd.setCursor ( 0, 0 );
lcd.print(“±-----------------+”);
lcd.setCursor ( 0, 1 );
lcd.print(”| DER GROSSE |");
lcd.setCursor ( 0, 2 ); //
lcd.print("| MUTATO |");
lcd.setCursor ( 0, 3 );
lcd.print(“±-----------------+”);

if(Ethernet.begin(mac,2000,2000) == 1)
{
lcd.clear();
break;
}

client.stop();
}
printIPAddress();
printsubnetmask();
printgateway();
printdnsserver();
while(1 == 1) {
if(ping()==1){
lcd.clear();
break;
}
delay(2000);
}
}

int ping()
{
ICMPPing ping(pingSocket);
byte pingAddr = { Ethernet.gatewayIP()[0],Ethernet.gatewayIP()[1],Ethernet.gatewayIP()[2],Ethernet.gatewayIP()[3]};
ping(1, pingAddr, buffer);
char *p = buffer;
char str;
char
buffer[20];
int x=0;
while((str = strtok_r(p,"[",&p))!=NULL){
buffer=str;
x++;
}

String checkping= buffer[0];

if(checkping!=“Reply”)
{
return 1;
}
else
{
return 0;
}

}

void printIPAddress()
{
for (byte thisByte = 0; thisByte < 4; thisByte++) {
ip+=Ethernet.localIP()[thisByte], DEC;
if (thisByte < 3)
{
ip+= “.”;
}
}

lcd.setCursor ( 0, 0 );
lcd.print( “IP | " + ip );
ip=”";
}

void printsubnetmask()
{

for (byte thisByte = 0; thisByte < 4; thisByte++) {
subnetmask+=Ethernet.subnetMask()[thisByte], DEC;
if (thisByte < 3)
{
subnetmask+= “.”;
}
}

lcd.setCursor ( 0, 1 );
lcd.print( “SN | " + subnetmask );
subnetmask=”";

}

void printgateway()
{

for (byte thisByte = 0; thisByte < 4; thisByte++) {
gateway+=Ethernet.gatewayIP()[thisByte], DEC;

if (thisByte < 3)
{
gateway+= “.”;
}
}

lcd.setCursor ( 0, 2 );
lcd.print( “GW | " + gateway );
gateway=”";

}

void printdnsserver()
{

for (byte thisByte = 0; thisByte < 4; thisByte++) {
dnsserver+=Ethernet.dnsServerIP()[thisByte], DEC;
if (thisByte < 3)
{
dnsserver+= “.”;
}
}
lcd.setCursor ( 0, 3 );
lcd.print( “DNS| " + dnsserver );
dnsserver=”";

}

Put code tags around your code. This is a good example of how the forum system mangles the code otherwise.

#include <SPI.h>
#include <Ethernet.h>
#include <Dns.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(115200);
  // this check is only needed on the Leonardo:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // print your local IP address:
  Serial.print("IP: ");
  Serial.println(Ethernet.localIP());
  Serial.print("Gateway: ");
  Serial.println(Ethernet.gatewayIP());
  Serial.print("Subnet: ");
  Serial.println(Ethernet.subnetMask());
  Serial.print("DNS: ");
  Serial.println(Ethernet.dnsServerIP());
  Serial.println();
}

void loop() {
}

HI Surfer Tim and Pylon

Thank you kindly for both your responses.

@ Surfer Tim
Your code is genius looks so much more organised and professional,its just that i want to display it on a 20 x 4 lcd .As you have it showing on serial monitor is perfect,just want that on an LCD pleased.

i really don't mean to be annoying.

:confused: :confused:

Hey guys

Me again.

After copying codes from other projects,i get this.
I would still like a clean display,and a home screen “Zahed Hoosen” when no IP address detected.

Post the code that generated that display and use code tags! (that’s the </> button in the editor)

Thank you so much Guys.
Everything is working as it should be.

Appreciate all the assistance received

My project is working how i want it to.