html/js interface with arduino

code below is an html/js interface with arduino.I am able to connect with uno through enc28j60 but not able to display my webpage and pass values.

#include <SPI.h>
#include <UIPEthernet.h>//ran success eith UIPEthernet but not eith Ethernet
#include <SD.h>
#define BAUD 115200
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 14, 10 }; // ip in lan
byte gateway[] = {
192, 168, 14, 9 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(84);//server port
File webfile;
//byte Ethernet::buffer[700];

String readString;

//////////////////////

void setup(){

//pinMode(9, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(BAUD);
Serial.println("server text box test1"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
String wifissid;
String sta_pwd;
String ap_ip;
String ap_ssid;
String ap_pwd;
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {//Serial.print("inside client connected");
if (client.available()) {//Serial.println("inside client available");
char c = client.read();

//read char by char HTTP request
if (readString.length() < 1000) {

//store characters to string
readString += c;
//Serial.print(c);
}

//if HTTP request has ended
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
//Serial.println("in 1st if");
///////////////
Serial.println(readString); //see what was captured

//now output HTML data header
//client.send()

client.println("HTTP/1.1 200 OK");
//client.println("Content-Type: text/html");
//client.println();

/*running client.println("");
client.println("");
client.println("Arduino GET test page");
client.println("");
client.println("");
//client.println("

HTML form GET example

");
client.println(""); //uses IP/port of web page
//client.println("Pin 9 'on9' or 'off9':
");

client.println("

Enter the configuration.


");
client.println("WiFiSettings:

");
client.println("WiFiSSID ");
client.println("WiFiPASSWORD .

");
client.println("AP Settings:

");
client.println("AP IP ");
client.println("AP SSID");
client.println("AP PASSWORD ");
client.println("

");

client.println("");

client.println("
");

//check for mypassword
if(readString.indexOf("mypassword") >0) {
//link to a second control page
client.println("<a href='/ctrl' '>secret click link");
}running*/
/client.println("document.getElementByName('sta_ssid'))[0].value");
client.println("document.getElementByName('sta_password'))[0].value");
client.println("document.getElementByName('ap_ip'))[0].value");
client.println("document.getElementByName('ap_ssid'))[0].value");
client.println("document.getElementByName('ap_password'))[0].value");
/
/runningclient.println("");
client.println("");running
/

//GetTextFromHtmltextboxes()
if(readString.substring(0)=="ajax_inputs")
{
/////////////////////
if(readString.indexOf("sta_ssid") >0)//checks for on
{
//digitalWrite(9, HIGH); // set pin 9 high
wifissid=readString.substring(strlen("sta_ssid")+1,readString.indexOf(":"));
Serial.println(wifissid);
}
if(readString.indexOf("sta_pwd") >0)//checks for off
{
//digitalWrite(9, LOW); // set pin 9 low
sta_pwd=readString.substring(strlen("sta_pwd")+1,readString.indexOf(":"));
Serial.println(readString.indexOf(sta_pwd));
}
if(readString.indexOf("ap_ip") >0)//checks for off
{
//digitalWrite(9, LOW); // set pin 9 low
ap_ip=readString.substring(strlen("ap_ip")+1,readString.indexOf(":"));
Serial.println(readString.indexOf(ap_ip));
}
if(readString.indexOf("ap_ssid") >0)//checks for off
{
//digitalWrite(9, LOW); // set pin 9 low
ap_ssid=readString.substring(strlen("ap_ssid")+1,readString.indexOf(":"));
Serial.println(readString.indexOf(ap_ssid));
}
if(readString.indexOf("ap_pwd") >0)//checks for off
{
//digitalWrite(9, LOW); // set pin 9 low
ap_pwd=readString.substring(strlen("ap_pwd")+1,readString.indexOf(":"));
Serial.println(readString.indexOf(ap_pwd));
}
//clearing string for next read
readString="";

}
else // web page request
{
//
webfile = SD.open("arduinohtml.html"); // open web page file
if (webfile) {
while(webfile.available()) {
client.write(webfile.read()); // send web page to client
}
webfile.close();
}
/
/
}
break;
}
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;//Serial.println("currentLineIsBlank = true");
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false; //Serial.println("currentLineIsBlank = false");
}

}// end if (client.available())
}// end while (client.connected())
delay(1);
//stopping client
client.stop();
}// end if (client)
}

/*output:

  • GET/HTTP/1.1 Host:192.168.14.10:84 User Agent:Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0

Accept: text/html,application/xhtml#AE application/xml;q 0.9,*;q 0.8 Accept Language: en US,en;q 0.5 Accept
Encoding: gzip, deflate
Connection: keep alive

Upgrade Insecure Requests: 1
G*/

Start building something small and and Check the HTML you send is a well formed (including header). Using String class will lead to disappointment

Please read how to post here & forum rules. Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

You are setting up your server in the loop() function. It will be constantly reloaded. Set it up in setup(). I didn't bother to look into the code any further than that atm.

ee_es_pe:
You are setting up your server in the loop() function. It will be constantly reloaded. Set it up in setup(). I didn't bother to look into the code any further than that atm.

Not sure what you are saying... OP’s server’s begin() is in the setup and port declared in the global instanciation...

J-M-L:
Not sure what you are saying... OP’s server’s begin() is in the setup and port declared in the global instanciation...

Yeah my bad. Read it wrong.

In that case (hard too read but) I think the problem may be processing the entire page each time a single character is read. I'm not seeing the read loops closed early enough. And then since readString is cleared near the end it will never have a length greater than 1 will it?

That’s not the case either because of the if/while probably. Code poorly formatted so hard to see and I won’t put more effort into this as OP is MIA.. (but I think the http answer is most likely not correct)

hey people,
kindly pathe this code in IDE you will find that client.println() has been commented out due to mmory issues.I am sending an html file as a response.some how not able to display the html although am able to connect on LAN.

Why don’t you kindly fix your post and get rid if all the commented out part rather than expecting the forum members to do that... it’s your project, the level of effort you put in asking for help usually matches the level of efforts members will put in...

Hi,

First follow the first post here: Auto Format Code in IDE

Then check number 7 on the following post before even expecting a proper answer:
How to use this forum - please read.

(With this way of posting code, its way easier to find problems)

You can’t follow simple rules for posting here, I’m out

Go read the rules. Apply them. I showed you in post #1 what code posting should look like.

If you can’t follow simple instructions, programming is probably not for you... sorry - nothing personal, just sharing an opinion on what's required on a path to self sufficiency.

bye