I have the following sketch, working fine but whenever a button is clicked the page take long time to load since sketch has many button.
I need action immediately without referesh by using sd card webserver, or splitting the sketch into to groups
please help me.
#include <SPI.h>
#include <Ethernet.h>
EthernetServer server(80);// Server port
const byte BIT0Pin = 2;// Select pin for 2^0 BIT
const byte BIT1Pin = 3;// Select pin for 2^1 BIT
const byte BIT2Pin = 4;// Select pin for 2^2 BIT
const byte BIT3Pin = 5;// Select pin for 2^3 BIT
const byte BIT4Pin = 6;// Select pin for 2^4 BIT
const byte BIT5Pin = 7;// Select pin for 2^5 BIT
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 200 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
String readString;
//////////////////////
void setup()
{
delay(10);// Delay for Ethernet shield initialization (Arduino has 65mS Power Up delay and W5100 reset logic has 280mS)
pinMode(BIT0Pin, OUTPUT);// Define pin for BIT0 as Output
pinMode(BIT1Pin, OUTPUT);// Define pin for BIT1 as Output
pinMode(BIT2Pin, OUTPUT);// Define pin for BIT2 as Output
pinMode(BIT3Pin, OUTPUT);// Define pin for BIT3 as Output
pinMode(BIT4Pin, OUTPUT);// Define pin for BIT4 as Output
pinMode(BIT5Pin, OUTPUT);// Define pin for BIT5 as Output
Serial.begin(9600);// Initialize serial communications at 9600 bps
Serial.println(F("TEST"));// Display Arduino title
Ethernet.begin(mac, ip, gateway, subnet);// Start Ethernet
server.begin();
Serial.print(F("Ethernet Shield initialized. Local IP address is:"));
Serial.println(Ethernet.localIP());// Print Server IP address
}
void loop()
{
EthernetClient client = server.available();// Create a client connection
if (client == true)
{
while (client.connected())
{
if (client.available())
{
char c = client.read();// Read char by char HTTP request
if (readString.length() < 100)
{
readString = readString + c;// Store characters to string
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<BODY>");
client.println(F("<body bgcolor='Turquoise'>"));
client.println(F("<h1><b><center>GAS TURBINE E CONTROL PANEL</b></h2><font size=5>"));
//client.println(F("<hr/><p> Click the Buttons to turn On and OFF <p/><hr/>
"));
client.print(F("<input type=button value=OPERATION style=position:absolute;left:976px;top:110px;width:150px;height:30px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?off3579'> "));
client.print(F("<input type=button value=OFF style=position:relative;left:840px;top:85px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?OFF'>"));
client.print(F("<input type=button value='CRANK' style=position:relative;left:850px;top:85px;width:85px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?CRK'>"));
client.print(F("<input type=button value=FIRE style=position:relative;left:860px;top:85px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?FIR'>"));
client.print(F("<input type=button value=AUTO style=position:relative;left:870px;top:85px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?AUT'>"));
client.print(F("<input type=button value=REM style=position:relative;left:880px;top:85px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?REM'>"));
client.print(F("<input type=button value=LOAD style=position:absolute;left:975px;top:230px;width:150px;height:30px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?off3579'> "));
client.print(F("<input type=button value=PRESEL style=position:relative;left:540px;top:205px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?PRS'>"));
client.print(F("<input type=button value=BASE style=position:relative;left:560px;top:205px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?BAS'>"));
client.print(F("<input type=button value=PEAK style=position:relative;left:580px;top:205px;width:70px;height:50px;color:blue;font-size:16px;border-width:5px;border-style:ridge;border-color:blue; onmousedown=location.href='/?PEK'>
"));
client.println("
");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if (readString.indexOf("/?OFF") > 0)
{
digitalWrite(BIT0Pin, HIGH); // set the LED on
digitalWrite(BIT2Pin, HIGH); // set the LED on
digitalWrite(BIT3Pin, HIGH); // set the LED on
digitalWrite(BIT5Pin, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(BIT0Pin, LOW); // set the LED on
digitalWrite(BIT2Pin, LOW); // set the LED on
digitalWrite(BIT3Pin, LOW); // set the LED on
digitalWrite(BIT5Pin, LOW); // set the LED on
delay(0); // wait for a second
}
readString = "";// Clearing string for next read
}// End of line reached
}// End of client available
}// End of client connected
}// End of client connection
}// End of loop
Moderator edit: [code] ... [/code] tags added. (Nick Gammon)