Hier mein aktueller Code
#include <SPI.h> //Anbindung microcontroller an Ethernet-Shield
#include <Ethernet.h>
#include <WString.h>
#include <Client.h>
#include <Server.h>
int LED =4;
boolean testdiode=false;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte ip[] = { 192,168,1, 190 };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
String readString = String(100); // string for fetching data from address
void setup(){
Ethernet.begin(mac, ip); //Start der Ethernet-Verbindung und des Servers
server.begin();
pinMode(4, OUTPUT);
Serial.begin(9600);
}
void loop(){
// listen for incoming clients
EthernetClient client = server.available(); //Client Verbindung herstellen
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length()< 100){
readString = readString + c;
}
Serial.print(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// print something, in HTML format:
}
else if (c == '\n') {
if(readString.indexOf("diode=AN") > -1) {
togglediode; // verändert den status von testdiode
}
if(readString.indexOf("diode=AUS") > -1) {
togglediode; // verändert den status von testdiode
}
client.println("<html>");
client.println("<head>");
client.println("<TITLE>Sörens Testpage</TITLE>");
client.println("</head>");
client.println("<body>");
/*
if (testdiode==true) {
client.println("<input type=submit value=AN name=3 style=width:200;height:100;background-color:lightgreen;/>");
client.println("<input type=\'hidden\' name='anderung' value='AUS'> ");
}else if (testdiode==false) {
client.println("<input type=submit value=AUS name=3 style=width:200;height:100;background-color:red;/>");
client.println("<input type=\'hidden\' name='anderung' value='AN'> ");
}
*/
if (testdiode==false) {
client.println(" <form action='/' method='get'><input type=submit name=3 value='einschalten'> ");
client.println(" <input type='hidden' name='diode' value='AN'> ");
client.println(" </form> ");
}
else if (testdiode==true) {
client.println(" <form action='/' method=get><input type=submit name=3 value='ausschalten'> ");
client.println(" <input type='hidden' name='diode' value='AUS'> ");
client.println(" </form> ");
}
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
readString=" ";
delay(1);
// close the connection:
client.stop();
}
}
void togglediode (){
if (testdiode == false){
testdiode=true;
digitalWrite(LED, HIGH);
}
else {
testdiode=false;
digitalWrite(LED, LOW);
}
}
Wenn ich den Button "einschalten" drücke steht Folgendes in der Adressleiste
" http://192.168.1.190/?3=einschalten&diode=AN "
Jedoch bleibt der LED status unverändert.
Wenn ich auf der Seite "http://192.168.1.190/ " den Befehl "diode=AN" anhänge, passiert das selbe.
Seriell wird ausgegeben:
GET /?3=einschalten&diode=AN HTTP/1.1
GET /?3=einschalten&diode=AN HTTP/1.1
Ich vermute an dieser Stelle, das das Suchen von diode=AN im String nicht funktioniert.
Kann mir allerdings nicht erklären warum nicht.