NodeMCU code not working.

Hello
This code does not work.

 #include <ESP8266WiFi.h>
 
const char* ssid = "BTBHub6-35J9";
const char* password = "J9YhNXiTLYJG";

int ledPin0 = 2;   
int ledPin1 = 4;
int ledPin2 = 6;
int ledPin3 = 8;
int ledPin4 = 10;
int ledPin5 = 12;
int ledPin6 = 14;
int ledPin7 = 16; 
int ledPin8 = 18;
int ledPin9 = 20;
WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  pinMode(ledPin1, OUTPUT);
  digitalWrite(ledPin1, LOW);
 pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin2, LOW);
  pinMode(ledPin3, OUTPUT);
  digitalWrite(ledPin3, LOW);
 pinMode(ledPin4, OUTPUT);
  digitalWrite(ledPin4, LOW);
  pinMode(ledPin5, OUTPUT);
  digitalWrite(ledPin5, LOW);
 pinMode(ledPin6, OUTPUT);
  digitalWrite(ledPin6, LOW);
  pinMode(ledPin7, OUTPUT);
  digitalWrite(ledPin7, LOW);
 pinMode(ledPin8, OUTPUT);
  digitalWrite(ledPin8, LOW);
  pinMode(ledPin9, OUTPUT);
  digitalWrite(ledPin9, LOW);
  
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("/LED1=ON") != -1)  {
    digitalWrite(ledPin1, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED1=OFF") != -1)  {
    digitalWrite(ledPin1, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED2=ON") != -1)  {
    digitalWrite(ledPin2, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED2=OFF") != -1)  {
    digitalWrite(ledPin2, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED3=ON") != -1)  {
    digitalWrite(ledPin3, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED3=OFF") != -1)  {
    digitalWrite(ledPin3, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED4=ON") != -1)  {
    digitalWrite(ledPin4, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED4=OFF") != -1)  {
    digitalWrite(ledPin4, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED5=ON") != -1)  {
    digitalWrite(ledPin5, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED5=OFF") != -1)  {
    digitalWrite(ledPin5, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED6=ON") != -1)  {
    digitalWrite(ledPin6, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED6=OFF") != -1)  {
    digitalWrite(ledPin6, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED7=ON") != -1)  {
    digitalWrite(ledPin7, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED7=OFF") != -1)  {
    digitalWrite(ledPin7, LOW);
    value = LOW;
  }

  if (request.indexOf("/LED8=ON") != -1)  {
    digitalWrite(ledPin8, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED8=OFF") != -1)  {
    digitalWrite(ledPin8, LOW);
    value = LOW;
  }

    if (request.indexOf("/LED9=ON") != -1)  {
    digitalWrite(ledPin9, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED9=OFF") != -1)  {
    digitalWrite(ledPin9, LOW);
    value = LOW;
  }
// Set ledPin according to the request
//digitalWrite(ledPin, value);
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Led1 is now: ");
  
  if(value == HIGH) {
    client.print("On1");
  } else {
    client.print("OFF1");
    
  client.print("Led2 is now: ");

  if(value == LOW) {
    client.print("ON2");
  } else {
    client.print("OFF2");
  }

  client.print("Led3 is now: ");
  
  if(value == HIGH) {
    client.print("On3");
  } else {
    client.print("OFF3");
    
  client.print("Led4 is now: ");

  if(value == LOW) {
    client.print("ON4");
  } else {
    client.print("OFF4");
  }

    client.print("Led5 is now: ");
  
  if(value == HIGH) {
    client.print("On5");
  } else {
    client.print("OFF5");
    
  client.print("Led6 is now: ");

  if(value == LOW) {
    client.print("ON6");
  } else {
    client.print("OFF6");
  }

  client.print("Led7 is now: ");
  
  if(value == HIGH) {
    client.print("On7");
  } else {
    client.print("OFF7");
    
  client.print("Led8 is now: ");

  if(value == LOW) {
    client.print("ON8");
  } else {
    client.print("OFF8");
  }

  client.print("Led9 is now: ");

  if(value == LOW) {
    client.print("ON9");
  } else {
    client.print("OFF9");
  }
   client.println("

");
   client.println("<a href=\"/LED1=OFF\"\"><button>Off1</button></a>
");
   client.println("<a href=\"/LED1=ON\"\"><button>On1</button></a>");
   client.println("</html>");
   
   client.println("

");
   client.println("<a href=\"/LED2=OFF\"\"><button>Off2</button></a>
");
   client.println("<a href=\"/LED2=ON\"\"><button>On2</button></a>");
   client.println("</html>");
   
   client.println("

");
   client.println("<a href=\"/LED3=OFF\"\"><button>Off3</button></a>
");
   client.println("<a href=\"/LED3=ON\"\"><button>On3</button></a>");
   client.println("</html>");
   
   client.println("

");
   client.println("<a href=\"/LED4=OFF\"\"><button>Off4</button></a>
");
   client.println("<a href=\"/LED4=ON\"\"><button>On4</button></a>");
   client.println("</html>"); 
    
   client.println("

");
   client.println("<a href=\"/LED5=OFF\"\"><button>Off5</button></a>
");
   client.println("<a href=\"/LED5=ON\"\"><button>On5</button></a>");
   client.println("</html>");
   
   client.println("

");
   client.println("<a href=\"/LED6=OFF\"\"><button>Off6</button></a>
");
   client.println("<a href=\"/LED6=ON\"\"><button>On6</button></a>");
   client.println("</html>");
   
   client.println("

");
   client.println("<a href=\"/LED7=OFF\"\"><button>Off7</button></a>
");
   client.println("<a href=\"/LED7=ON\"\"><button>On7</button></a>");
   client.println("</html>");
   
   client.println("

");
   client.println("<a href=\"/LED8=OFF\"\"><button>Off8</button></a>
");
   client.println("<a href=\"/LED8=ON\"\"><button>On8</button></a>");
   client.println("</html>");
     
   client.println("

");
   client.println("<a href=\"/LED9=OFF\"\"><button>Off9</button></a>
");
   client.println("<a href=\"/LED9=ON\"\"><button>On9</button></a>");
   client.println("</html>");      
  
  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");
}
}
}

Can you help me?

Thank You,

Natha

(deleted)

Hello

This is the EROR Message.

Arduino: 1.8.9 , Board: "Generic ESP8266 Module, 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), ck, 26 MHz, 40MHz, DOUT (compatible), 512K (no SPIFFS), 2, nonos-sdk 2.2.1 (legacy), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

wifi_led9:296:1: error: expected '}' at end of input
exit status 1
expected '}' at end of input

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Thank You

Natha

Use the auto format tool of the IDE (ctrl-t or Tools, Auto Format) on your code. That will help you find the error.

It took me just a few seconds to find your compile errors- so tell us precisely how "it doesn't work", and also what you are trying to do. You might want to flowchart this logic because there were four embedded if-else-if-else-if-else loops (which the CTRL-T formatting highlighted very quickly), and I can't figure out what you want the code to do.

Also i think you have not selected the proper board Generic ESP8266 is for an ESP-01 you should either select nodeMCU 1.0 (ESP 12E module) probably or maybe the older 0.9 If anyway you have a NodeMCU as the topic title suggests

Hi
I have got it working now.

Thank You

Natha

And you aren't going to say how?

It is really frustrating when I google a question and find that someone else had my exact issue. Only to read the thread and find the solution was "I have got it working now."

So, for anyone in the future who may have the same issue, tell the future user what was the fix.

It compiled for me after I added the two missing '}' at the end of the file. Maybe that was the only problem.

johnwasser:
It compiled for me after I added the two missing '}' at the end of the file. Maybe that was the only problem.

Same here, but I wanted the OP to learn how to find his problem.