Hi guys, I got a Esp8266 WiFi board which I am trying to use with Arduino IDE to connect to a WiFi Network and then use an HTTP Post HTML PAGE to send an information and display On a LCD.
Currently I am stuck on the use of ESP8266 WIFI Board , I can’t get it connected to my WiFi Such that it shows me through the arduino IDE serial monitor the IP address of the server so I can access the HTML page.
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* WifiName="Super Network";
const char* WifiPass="Fesa77796";
ESP8266WebServer server(80);
const char htmlPage[]PROGMEM=R"=====(
<HTML>
<HEAD>
<TITLE>Post Request</TITLE>
</HEAD>
<BODY>
<CENTER>
<B>
LED
Status =@@LEDstate@@</B>
</CENTER>
<FORM METHOD="POST" action="/">
<BUTTON name="LED" value="1"> ON </BUTTON>
<BUTTON name="LED" value="0"> OFF </BUTTON>
</FORM>
<marquee Behavior="alternate"> NodeMCU ESP8266 </marquee>
</BODY>
</HTML>
)=====";
void handleRoot()
{
String LEDstate, webPage;
webPage=htmlPage;
LEDstate=server.arg("LED");
Serial.print("Argument Received");
Serial.println(LEDstate);
if (LEDstate=="1")
{
digitalWrite(D2,0);
webPage.replace
("@@LEDState@@","ON");
}
if(LEDstate=="0")
{
digitalWrite(D2,1);
webPage.replace
("@@LEDState@@","OFF");
}
server.send(200,"text/html",webPage);
}
void setup()
{
Serial.begin(115200);
delay(10);
pinMode(D2,OUTPUT);
Serial.println();
Serial.print("Connecting");
WiFi.begin(WifiName,WifiPass);
while(WiFi.status()!= WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Wi-Fi Connected");
Serial.println("IP Address is:");
Serial.println(WiFi.localIP());
server.on("/",handleRoot);
server.begin();
Serial.println("HTTP Server Started");
// put your setup code here, to run once:
}
void loop() {
server.handleClient();
// put your main code here, to run repeatedly:
}
The problem is that the serial monitor doesnt pop up to display the IP Address of the HTTP server at which the HTML page is, once I uploaded this sketch onto the Esp8266 WifiBoard using my WIFI credentials .
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags: [code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.
You still haven't properly explained what the problem is.
Thanks Pert, I have modified the post , please check and let me know if you understand .
If you still dont understand the forget about that code, What
I Want is to create a Server to host a simple Html page with a button and a text box to send whatever I type in the text box to the Esp8266 ,process it and eventually display it on a LCD.
CiscoFrancis:
The problem is that the serial monitor doesnt pop up to display the IP Address of the HTTP server at which the HTML page is, once I uploaded this sketch onto the Esp8266 WifiBoard using my WIFI credentials .
You need to open the Serial Monitor. It won't pop up. You can open it via Tools > Serial Monitor or by clicking the magnifying glass icon at the top right of the Arduino IDE.
When I open it shows funny characters , it doesn’t Show what it was supposed to, like connecting to” Network”, “IP Address” , “connection successful, in other words it doesn’t print the message in my code .
Ah! Your ESP is crashing. That is the trace dump. Check out the ESP Exception Decoder. It should point you at the bit of your code causing the trouble.
I just fired up your sketch, and needed to define D2 before it would compile for me. Once I put in correct WiFi details it successfully launched a webpage and it changes the LED. Although the text on the webpage does not update. Sounds like something you can tinker with (I don't think you can edit the const char array) so long as you can find the source of your crashing. Im using an ESP Huzzah module btw.
You'll want to stick a resistor in series with that LED! Somewhere around 100+ ohms should do for starters. This might well be the cause of your troubles here. It's certainly not doing your ESP any good without one.