Hello all, I'm stuck on a part of my program again and need some help from some one please. I know there are excellent programmers here how can help.
I have a web site with a PHP script running. On the script is a couple of buttons then when pressed send a GET function to my arduino to turn on an LED.
This all works very well and I can turn on and off an LED from anywhere that I have internet access.
What I am struggling to do it send back to my server that the arduino has turned on the LED so the web page will display LED ON.
i have tried putting in a GET script to return back to my web page. This works but the URL is changed to www.mywebpage.com/file.php?led=1
the ?led=1 stops the rest of my web page displaying.
i think this could be overcome by sending back the information using POST. But I don't know how to do this.
My arduino code is below
#include <SPI.h>
#include <Ethernet.h>
int led = 2;
int led1 = 9;
int led2 = 8;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { ***, ***, *, ** }; // ip in lan (that's what you need to use in your browser. ("***.***.*.***")
byte gateway[] = { ***, **, **, * }; // internet access via router
EthernetServer server(****); //server port
String readString;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip );
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
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
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("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("POST /TempGauges.php HTTP/1.1");
client.println("Host: MyWebPage.com");
client.println("led=1");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=http://www.MyWebPage.com/TempGauges.php\">");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
Serial.println ("LED 0n");
}
if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
}
if (readString.indexOf("?button2on") >0){
digitalWrite(led1, HIGH);
}
if (readString.indexOf("?button2off") >0){
digitalWrite(led1, LOW);
}
if (readString.indexOf("?button3on") >0){
digitalWrite(led2, HIGH);
}
if (readString.indexOf("?button3off") >0){
digitalWrite(led2, LOW);
}
//clearing string for next read
readString="";
}
}
}
}
}
Can anyone help.
thank you:)