B4R Question HTML from ESP Web Server

JMB

Active Member
Licensed User
Longtime User
Hi

I am playing around with the Tutorial for the ESP board - ESP8266 - WiFi Remote Configuration


I've been trying to get it to actually output HTML so that it presents a web page of sorts when you go to the IP, without success.

I am VERY new to all this, so please be patient!

My Code looks like this:

If Main.WiFi.IsConnected Then
Astream.Write("Connected to network.").Write(CRLF)
Astream.Write("ESP8266 IP address: ").Write(Main.WiFi.LocalIp)
Astream.Write("<HTML>").Write(CRLF)
Astream.Write("<HEAD>").Write(CRLF)
Astream.Write("<TITLE> title of page</TITLE >").Write(CRLF)
Astream.Write("</HEAD>").Write(CRLF)
Astream.Write("<BODY>").Write(CRLF)
Astream.Write("<p>HELLO</p>").Write(CRLF)
Astream.Write("write what you like here:").Write(CRLF)
Astream.Write("</BODY >").Write(CRLF)
Astream.Write("</HTML >").Write(CRLF)

But the HTML doesn't work - it just shows all of that text with all the tags.

I obviously don't quite understand what the Astream is doing...

I just want the ESP board to act as a web server and to present a page to the user.

Thanks

JMB the Noob
 

mrred128

Active Member
Licensed User
Longtime User
I have no ESP experience, but as an old fart at web developing, your first two writes should not be there. Replace them with......

Astream.Write("Content-Type: text/html").Write(CRLF).Write(CRLF)

That tells the browser at the other end how it is to treat the following data. What you sent makes it default to thinking it's text.
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
H there Mr Red,

I tried that but with no success - it still shows up as pure text.

Thanks for your suggestion though.

JMB
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
Is this something to do with the way that Astreams works?

Should I be creating a page and then sending it back in a different way?

I've seen samples using C++ using the ESP as a webserver and I am trying to do the same here.

All very new to me!

JMB
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top