Wemos D1R2 Web Server suggestions.

Hi
Here is a Web Server for a Wemos D1R2.
This program does seem to work.
I would like it if others would look it over and tell me what is good or bad.
I don't want to keep doing something that is considered a bad programming practice.
I did try to thank everybody who helped me along the way.

#include <ESP8266WiFi.h>
#include <user_interface.h>

String req;
String OnOffString;
const char* ssid = "****";
const char* password = "********";
unsigned int xPageHits = 0;
unsigned int led4 = D6;
IPAddress staticIP(192, 168, 1, 102);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns1(192, 168, 1, 1);
WiFiServer server(80);
WiFiClient client;

void setup()
{
  pinMode(led4, OUTPUT);
  digitalWrite(led4, 0);
  OnOffString = "Off ";
  Serial.begin(115200);
  Serial.println();
  Serial.print("Connecting to: ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  WiFi.config(staticIP, gateway, subnet, dns1);
  WiFi.hostname("Wemos102");
  while (WiFi.status() != WL_CONNECTED)  // Connecting to Network
  {
    delay(500);
    Serial.print(".");                  // Print Dots while NOT Connected
  }  // End of While Connected Loop
  PrintElCrapo();                       // Print Network Information
  server.begin();                       // Start Server
}  // End of Setup Loop


void loop()
{ // * * * * * * * Main Loop * * * * * * * *
  client = server.available();   // Check if a client has connected
  if (!client)
  {
    return;
  }  // End of If Client Connect  Once a Client has Connected it will pass through here

  while (!client.available())  // Wait until the client sends some data
  {
    delay(1);
  } // End of While Client

  req = client.readStringUntil('\r'); // Read the first line of the request
  Serial.println("* *");
  Serial.println(req);                // req is what is sent back from the client browser
  client.flush();

  // * * Match the request * *
  int val;
  if (req.indexOf("GET /1") != -1)   // indexof returns -1 if not found
  {
    val = 1;
  }
  else if (req.indexOf("GET /0") != -1)
  {
    val = 2;
  }
  else if (req.indexOf("favicon") != -1)
    val = 9;
  else if (req.indexOf("GET") != -1)
    val = 3;
  else
  { // This is for -not- 1,2,3,9
    client.stop();
    return;
  }  // End of Match Else

  if (val == 9) return;
  if (val == 2)
  {
    val = 3;
    digitalWrite(led4, 0);
    OnOffString = "Off ";
  }
  if (val == 1)
  {
    val = 3;
    digitalWrite(led4, 1);
    OnOffString = "On  ";
  }

  if (val == 3)
  {
    PrintToWeb();
  }

}  // End of Main Loop

//  * * * * * * * * * * SubRoutines * * * * * * * * * * *

void PrintToWeb()
{
  xPageHits = xPageHits + 1;
  client.println("<!DOCTYPE HTML><html lang=\"en\">");
  client.println("<head><meta charset=\"UTF-8\"><title>RobWemos102</title></head>");
  client.println("<body>");
  client.println("<font face=\"Arial\"><font size=\"5\"><font color=\"blue\"><h1>
");
  client.println("<center>--- Control Robs Lights ---</center>");
  client.println("


");
  client.print("<center><font size=\"7\"><a href=1>Turn On</a>




<a href=0>Turn Off</a></center>");
  client.println("</h1></font>");
  client.println("


");
  client.println("<center><font size=\"4\"><font color=\"Navy\"><h1>");
  client.print("The Lights Are ");
  client.println(OnOffString);
  client.println("


");
  client.print("      Number of Page Hits = ");
  client.println(xPageHits);
  client.println("</h1></font></center>");
  client.println("</body></html>");
}  // End of Print To Web


void PrintElCrapo()
{
  delay(2000);
  Serial.println();
  Serial.println("     Wifi Connected");
  Serial.print(" IP Address: ");
  Serial.println(WiFi.localIP());
  Serial.print("Subnet Mask: ");
  Serial.println(WiFi.subnetMask());
  Serial.print(" Gateway IP: ");
  Serial.println(WiFi.gatewayIP());
  Serial.print(" Dns IP 0-1: ");
  Serial.print(WiFi.dnsIP(0));
  Serial.print(" , ");
  Serial.println(WiFi.dnsIP(1));
  Serial.print("Mac Address: ");
  Serial.println(WiFi.macAddress());
  Serial.print("  Host Name: ");
  Serial.println(WiFi.hostname());
  if (WiFi.isConnected())
  {
    Serial.print(ssid);
    Serial.println(" Is still Connected");
  }  // End of If Connected
  else
  {
    Serial.print(ssid);
    Serial.println(" Is NOT Connected");
  }  // End of Else Connected
  Serial.print("Sleep Mode: ");
  Serial.println(WiFi.getSleepMode ());
  Serial.print("Mode:" );
  Serial.println(WiFi.getMode ());
}  // End of PrintElCrapo
  PrintElCrapo();                       // Print Network Information

If your function had a decent // The comments should
name, there would be no // Not be needed; the
reason for the useless // code should be self
comments // documenting.

  PrintNetworkIdentification(); // Isn't it obvious what this function does?
void loop()
{ // * * * * * * * Main Loop * * * * * * * *

Really? Are you sure?

Comments that insult the reader's intelligence will quickly stop people from reading your code.

I really hate comments at the end of a line of code. Decent comments go BEFORE the code that needs some explanation.

// This block of code will wait for a client to connect
   while(!client.connected())
   {
      Whatever needs doing to get a client to connect happens here...
  if (req.indexOf("GET /1") != -1)   // indexof returns -1 if not found
  {
    val = 1;
  }
  else if (req.indexOf("GET /0") != -1)
  {
    val = 2;
  }
  else if (req.indexOf("favicon") != -1)
    val = 9;
  else if (req.indexOf("GET") != -1)
    val = 3;

Consistent use of curly braces is a good thing. Inconsistency sucks.

val is a meaningless name. I'm sure you could do better than that. I think it makes more sense to arrange the if/else if statements so that val's values follow a logical sequence. 1, 2, 9, 3 is NOT a logical sequence. It looks like case 3 is an afterthought.

  if (val == 2)
  {
    val = 3;

Now, THAT needs an explanation/comment.

void PrintElCrapo()
{
  delay(2000);

I can not imagine a single reason, no matter how far fetched, where printing the network information should not be done as fast as possible.

  Serial.println("     Wifi Connected");

  if (WiFi.isConnected())
  {
    Serial.print(ssid);
    Serial.println(" Is still Connected");
  }  // End of If Connected

You print "connected" even if you aren't. Doesn't make sense to me.

Of course, this function is only called after connecting to the network, so it is pointless to test whether you are connected, or not. It is unlikely that the connection failed in the few nanoseconds between connection and getting to this test. If your network is that flaky, I can't imagine actually trying to use it for anything but a paperweight.

Well, you DID ask... 8)

Thanks Paul, that's what I was looking for. Ways to make my programming better.
I try to comment on things that I think I will need later.
Req and Val came from the example program that I copied and you are right, they don't convey what they should.
I agree that the Val 1,2,3,9, is not a very elegant solution. I didn't know what to do with the browser asking for a favicon and I had to get it out of the way some how.
Testing to see if WiFi is still connected was to see if it stayed connected even in a function. When I would try to print to the client it would say it was not defined in the printtoweb function and that was because I had defined Wifi client in the main loop. Once I moved the WiFi client above the setup loop it solved that problem.

Thanks again Paul for taking the time to review my program.