Hi all,
I downloaded this sketch by Claudio Vella - Malta the other day. I uploaded it into my Mega.
When I try to use the sketch/app, I get the menu once in awhile and it will control the ports. Then it goes to a screen full of garbage or buttons all over the screen that do not work. If I try to log back in to the page, it doesn't connect at all. I tried with firefox, IE, and safari. All the same problems.
If anyone can help me get this working, that would be great.
Thanks.
Everywhere it shows something like client.print("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins");it should be client.print(F("<td><INPUT TYPE=\"button\" VALUE=\"Switch OFF All Pins"));
You said "something like". Do you mean all the client.print statements or just the "all on or all off"?
I don't have a memory problem with the mega. Is that F() thing causing the pages not to load or only load once?
Inserted 3 F()'s. Ran it and it loaded the page once. Buttons never worked then displayed html code and buttons on the left side of the screen. Thanks for helping so far. I know almost nothing about html coding.
I think your code is too large to run on my arduino so I can't see how your page looks. If the page reloads on each action, it will probably be slow. I suggest you start simple and then start adding frills. Below is simple web server control test code that controls the arduino pins.
//zoomkat 5-30-15
//simple button GET with iframe code
//open serial monitor to see what the arduino receives
//use the ' instead of " in html ilnes
//address will look like http://192.168.1.102:84/ when submited
//for use with W5100 based ethernet shields
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //ethernet shield mac address
byte ip[] = {192, 168, 1, 102 }; // arduino IP in lan
byte gateway[] = {192, 168, 1, 1 }; // internet access via router
byte subnet[] = {255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString;
//////////////////////
void setup(){
pinMode(4, OUTPUT); //pin selected to control
pinMode(5, OUTPUT); //pin selected to control
pinMode(6, OUTPUT); //pin selected to control
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("multibutton server test 5-30-15"); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
//now output HTML data header
if(readString.indexOf('?') >=0) { //don't send new page
client.println("HTTP/1.1 204 Zoomkat\r\n\r\n");
}
else {
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("<TITLE>Arduino GET test page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Zoomkat's simple Arduino button</H1>");
client.println("<a href='/?on4' target='inlineframe'>ON 4</a>");
client.println("<a href='/?off4' target='inlineframe'>OFF 4</a>");
client.println("<a href='/?on5' target='inlineframe'>ON 5</a>");
client.println("<a href='/?off5' target='inlineframe'>OFF 5</a>");
client.println("<a href='/?on6' target='inlineframe'>ON 6</a>");
client.println("<a href='/?off6' target='inlineframe'>OFF 6</a>");
client.println("<IFRAME name=inlineframe style='display:none'>");
client.println("</IFRAME>");
client.println("</BODY>");
client.println("</HTML>");
}
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("on4") >0)//checks for on4
{
digitalWrite(4, HIGH); // set pin 4 high
Serial.println("Led 4 On");
}
if(readString.indexOf("off4") >0)//checks for off4
{
digitalWrite(4, LOW); // set pin 4 low
Serial.println("Led 4 Off");
}
if(readString.indexOf("on5") >0)//checks for on5
{
digitalWrite(5, HIGH); // set pin 5 high
Serial.println("Led 5 On");
}
if(readString.indexOf("off5") >0)//checks for off5
{
digitalWrite(5, LOW); // set pin 5 low
Serial.println("Led 5 Off");
}
if(readString.indexOf("on6") >0)//checks for on6
{
digitalWrite(6, HIGH); // set pin 6 high
Serial.println("Led 6 On");
}
if(readString.indexOf("off6") >0)//checks for off6
{
digitalWrite(6, LOW); // set pin 6 low
Serial.println("Led 6 Off");
}
//clearing string for next read
readString="";
}
}
}
}
}
You would add the html line break
code like below. A google search for "html tutorial" will bring up sites that explain basic things like buttons, frames, and similar which are useful. You probably should keep the serial print to the serial monitor in your code for debugging purposes. Also, please read #7 below on how to post code in the discussion: