Problems using esp8266 web server

Hello all,
I have been having trouble when I start the web server on an esp8266 NodeMCU board. I uploaded the sketch to the board and that worked fine. However, when I tried pressing the “RST” (reset) button on the board, I got a line of complete nonsense in the serial port monitor window. So I tried re-uploading the sketch with the same problem. I tried experimenting with the baud rate, and uploading it using different “programming” methods in Arduino IDE (AVRISP mkii, ArduinoISP, BusPirate as ISP, etc.) and still got the same results. When I attempted to connect to the board’s wireless network using my phone, I was able to see the ssid in the list of networks, but I was not able to connect to it using the provided password that came with the sketch (123456789).

Below I have posted both the output I get in the serial port monitor as well as a copy of the sketch I used (unchanged) for the esp8266 board attached in an .ino file.

Here is the output from the serial port monitor (I pressed the reset button on the esp8266 multiple times);

{l�d⸮⸮⸮⸮#⸮n ⸮ d⸮ B|⸮⸮⸮⸮⸮r⸮#⸮ c⸮⸮oN⸮�$no⸮⸮⸮bp⸮⸮cl {$p⸮o⸮ ⸮⸮l⸮⸮ B o⸮|$⸮⸮⸮p ⸮⸮oN⸮$⸮⸮�$⸮eoN $n{⸮⸮⸮o ⸮⸮{lr⸮⸮o ⸮⸮rl⸮⸮o⸮Connecting to
12:47:03.952 → NodeMCU
12:47:04.955 → …rl�$ܞ⸮⸮#⸮n ⸮l⸮b|⸮⸮⸮⸮r⸮c⸮b⸮⸮no⸮loN⸮⸮⸮bp⸮cl s$p⸮o⸮ ⸮ $ ⸮⸮ b N⸮⸮o$⸮⸮⸮p ⸮⸮oN⸮l⸮⸮�l ⸮eoN d n{⸮⸮⸮o ⸮⸮l {⸮⸮o ⸮⸮s$⸮⸮n⸮Connecting to
12:47:10.748 → NodeMCU
12:47:11.743 → …s$�lܞ⸮⸮c⸮N ⸮ l⸮b|⸮⸮⸮2⸮⸮|B⸮b⸮⸮nn⸮�$nn⸮⸮⸮ cp⸮blrlp⸮N⸮⸮ d⸮⸮ cN⸮⸮od⸮⸮⸮⸮"⸮|⸮N⸮l⸮⸮l⸮eNn $Nr⸮ےN ⸮⸮lr⸮⸮N ⸮⸮rd⸮⸮n⸮Connecting to
12:47:14.014 → NodeMCU
12:47:15.028 → …{$�l⸮⸮|�⸮$⸮| ⸮l⸮"|⸮⸮⸮⸮p⸮⸮|B⸮ c⸮⸮no⸮loo⸮⸮⸮ Bp⸮⸮#${$p⸮o⸮ ⸮ l⸮⸮ cN⸮|$⸮⸮⸮b⸮⸮no⸮�$⸮⸮�d ⸮e2Nn d Nr⸮ےN ⸮⸮lsےN ⸮⸮{$⸮⸮o⸮Connecting to
12:47:29.654 → NodeMCU
12:47:30.655 → …rl�d⸮⸮⸮⸮l⸮| ⸮ l⸮ c|⸮⸮⸮⸮{⸮⸮⸮ B⸮p⸮N⸮loN⸮⸮⸮bp⸮⸮ls$rlp⸮N⸮ ⸮$ ⸮⸮ " o⸮|l⸮⸮⸮⸮ B⸮|⸮N⸮l⸮⸮�l ⸮eoN l or⸮ےN ⸮⸮{lr⸮⸮o⸮⸮$⸮⸮n⸮Connecting to 12:47:37.314 -> NodeMCU 12:47:38.339 -> ........{$�l⸮⸮|�⸮$⸮| ⸮l⸮b|⸮⸮⸮⸮{⸮⸮⸮ B⸮p⸮n⸮�dNn⸮⸮⸮ cp⸮#${lp⸮o⸮ ⸮ $ ⸮⸮ " o⸮|l⸮⸮⸮⸮b⸮⸮No⸮�$⸮⸮�$⸮oolor⸮⸮⸮o ⸮⸮l {⸮⸮⸮ ⸮⸮d ⸮⸮N⸮Connecting to
12:47:46.423 → NodeMCU
12:47:47.437 → …rl�l⸮⸮|�⸮$⸮| ⸮⸮d⸮ c|⸮⸮⸮⸮{⸮"⸮ c⸮⸮no⸮$no⸮⸮b cp⸮⸮cl rlp⸮N⸮ ⸮ l⸮⸮ b o⸮|l⸮⸮⸮⸮p ⸮⸮Nn⸮d⸮⸮�l ⸮2Nn `Nr⸮۲N ⸮⸮rdr⸮⸮o ⸮⸮`⸮⸮N⸮Connecting to
12:48:19.262 → NodeMCU
12:48:20.281 → …

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

/*Put your SSID & Password*/
const char* ssid = "NodeMCU";  // Enter SSID here
const char* password = "123456789";  //Enter Password here

ESP8266WebServer server(80);

uint8_t LED1pin = D7;
bool LED1status = LOW;

uint8_t LED2pin = D6;
bool LED2status = LOW;

void setup() {
  Serial.begin(115200);
  delay(100);
  pinMode(LED1pin, OUTPUT);
  pinMode(LED2pin, OUTPUT);

  Serial.println("Connecting to ");
  Serial.println(ssid);

  //connect to your local wi-fi network
  WiFi.begin(ssid, password);

  //check wi-fi is connected to wi-fi network
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected..!");
  Serial.print("Got IP: ");  Serial.println(WiFi.localIP());

  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/led2on", handle_led2on);
  server.on("/led2off", handle_led2off);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");
}
void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, HIGH);}
  else
  {digitalWrite(LED1pin, LOW);}
  
  if(LED2status)
  {digitalWrite(LED2pin, HIGH);}
  else
  {digitalWrite(LED2pin, LOW);}
}

void handle_OnConnect() {
  LED1status = LOW;
  LED2status = LOW;
  Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,LED2status)); 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO7 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED2status)); 
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO7 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED2status)); 
}

void handle_led2on() {
  LED2status = HIGH;
  Serial.println("GPIO6 Status: ON");
  server.send(200, "text/html", SendHTML(LED1status,true)); 
}

void handle_led2off() {
  LED2status = LOW;
  Serial.println("GPIO6 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,false)); 
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t led1stat,uint8_t led2stat){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #1abc9c;}\n";
  ptr +=".button-on:active {background-color: #16a085;}\n";
  ptr +=".button-off {background-color: #34495e;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>ESP8266 Web Server</h1>\n";
    ptr +="<h3>Using Station(STA) Mode</h3>\n";
  
   if(led1stat)
  {ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
  else
  {ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}

  if(led2stat)
  {ptr +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";}
  else
  {ptr +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

A copy of the copy of the sketch I used also is attached in a .ino file

ArduinoSimpleWebServer.ino (3.72 KB)

The gibberish is some output the bootloader prints at 74880 baud on startup. You can switch the Serial Monitor's baud rate menu to 74880 to see what it says. When you do that, the stuff your sketch prints at 115200 will now be the gibberish.

Your sketch is repeatedly resetting. I just ran it on my ESP8266 board and that doesn't happen. That makes me suspect the problem is caused by the circuitry you have connected to your ESP8266. Try removing all the external wiring, LEDs, modules, shields, etc. from the ESP8266 and running the sketch on the ESP8266 alone. Does the problem still occur?

“A copy of the copy of the sketch I used is attached in a .ino file”

To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.

To go back and put your code in a code box, in the bottom right of your post, select “more” and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.

pert:
The gibberish is some output the bootloader prints at 74880 baud on startup. You can switch the Serial Monitor's baud rate menu to 74880 to see what it says. When you do that, the stuff your sketch prints at 115200 will now be the gibberish.

Your sketch is repeatedly resetting. I just ran it on my ESP8266 board and that doesn't happen. That makes me suspect the problem is caused by the circuitry you have connected to your ESP8266. Try removing all the external wiring, LEDs, modules, shields, etc. from the ESP8266 and running the sketch on the ESP8266 alone. Does the problem still occur?

Thank you for your reply, but there are a few issues with what you are saying.
First, the reseting is my doing. I said in my original post that I pressed the reset button on my esp8266 multiple times to see if that would make any difference (which it did not), and I do not have anything attached to the esp8266 board other than the usb cable.
Second, what do you mean when you say "The gibberish is some output the bootloader prints at 74880 baud on startup."? I have tried switching between all of the options in the baud rate menu, and when I switch to 74880 and press the reset button on my esp8266 this is what it returns;

11:34:43.398 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
11:34:43.398 ->
11:34:43.398 -> load 0x4010f000, len 1264, room 16
11:34:43.398 -> tail 0
11:34:43.398 -> chksum 0x42
11:34:43.398 -> csum 0x42
11:34:43.398 -> ~ld
11:34:43.720 -> Q⸮⸮⸮Z⸮Vi+EuT⸮⸮⸮T⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮

And third, I am following a tutorial from the Last Minute Engineering website (In-depth: Create A Simple ESP8266 NodeMCU Web Server In Arduino IDE) to make the server, and it is telling me I sould see an output from the serial port monitor using baudrate 115200 that looks like this: Http server started.

Thank you again for your help

PhauxFenix:
First, the reseting is my doing. I said in my original post that I pressed the reset button on my esp8266 multiple times

Sorry, I missed that.

PhauxFenix:
what do you mean when you say "The gibberish is some output the bootloader prints at 74880 baud on startup."?

This is the 74880 baud output from the bootloader:

PhauxFenix:
11:34:43.398 -> ets Jan 8 2013,rst cause:2, boot mode:(3,6)
11:34:43.398 ->
11:34:43.398 -> load 0x4010f000, len 1264, room 16
11:34:43.398 -> tail 0
11:34:43.398 -> chksum 0x42
11:34:43.398 -> csum 0x42
11:34:43.398 -> ~ld

This is the 115200 baud output from your sketch, which looks like gibberish because the Serial Monitor is set to 74880:

PhauxFenix:
11:34:43.720 -> Q⸮⸮⸮Z⸮Vi+EuT⸮⸮⸮T⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮

PhauxFenix:
I am following a tutorial from the Last Minute Engineering website (In-depth: Create A Simple ESP8266 NodeMCU Web Server In Arduino IDE) to make the server, and it is telling me I sould see an output from the serial port monitor using baudrate 115200 that looks like this: Http server started.

Works for me. Make sure you have your sketch configured for the SSID and password of your router:

/*Put your SSID & Password*/

const char* ssid = "NodeMCU";  // Enter SSID here
const char* password = "123456789";  //Enter Password here

So I tried re-uploading the sketch with the same problem. I tried experimenting with the baud rate

As long as the Arduino IDE says the upload was successful, you know there is no problem there. So it's a waste of time to keep uploading the same sketch over and over again with different upload settings.

and uploading it using different "programming" methods in Arduino IDE (AVRISP mkii, ArduinoISP, BusPirate as ISP, etc.)

The Tools > Programmer menu selection is only used when you are doing Tools > Burn Bootloader or Sketch > Upload Using Programmer. When you are doing a standard Upload, the Tools > Programmer menu selection is completely ignored, so it doesn't matter what you have it set to.

When I attempted to connect to the board's wireless network using my phone, I was able to see the ssid in the list of networks, but I was not able to connect to it using the provided password that came with the sketch (123456789).

You misunderstood the tutorial. As it explains, there are two different operating modes of the ESP8266: STA (station) and AP (access point). The sketch you posted is the one for using the ESP8266 in STA mode, where it connects to your WiFi router. With this sketch running, you would need to also connect your phone to the WiFi router, not the ESP8266. There is another sketch on that tutorial for AP mode.

The code works. I changed the router name, the password, and the port my wemos is setup to operate, and the board connected to the router and supplied the web page. Below is the serial monitor output minus the boot gibberish (could not copy that from the serial monitor due to one of the characters in it).

Connecting to 
ARRIS-D1FA
....
WiFi connected..!
Got IP: 192.168.0.6
HTTP server started
GPIO7 Status: OFF | GPIO6 Status: OFF
GPIO7 Status: ON
GPIO6 Status: ON
GPIO7 Status: OFF