Hallo ich versuche verzweifelt folgends Sketch zum laufen zu bringen.
Ich möchte drei Ausgänge mittels einer Webseite ein oder ausschalten.
Mit 2 Ausgängen klappt dies auch Problemlos aber sobald ich den 3. hinzufüge ist der Webserver nicht mehr erreichbar.
Ich hoffe Ihr könnt mir helfen.
#include <SPI.h> #include <Ethernet.h> // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192,168,178, 177 }; // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); boolean Pin3ON = false; // Status flag boolean Pin5ON = false; boolean Pin6ON = false; int Pin3 = 3; int Pin5 = 5; int Pin6 = 6; String readString = String(20); void setup() { // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); // Serial.begin(9600); readString=(""); pinMode(6, OUTPUT); digitalWrite(6, LOW); pinMode(5, OUTPUT); digitalWrite(5, LOW); pinMode(3, OUTPUT); digitalWrite(3, LOW); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); // 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 (readString.length() < 20) { //Serial.println("Hallo"); //Serial.println(c); //store characters to string // readString.append(c); removed by Katsu readString = readString + c; // insert by Katsu // very simple but it works... } if (c == '\n' && currentLineIsBlank) { // Serial.println(readString); // send a html code if(readString.indexOf("?5=einschalten") > -1) {//Serial.print("\n 5 HIGH \n"); digitalWrite(Pin5, HIGH); Pin5ON=true; } if(readString.indexOf("?5=ausschalten") > -1) {//Serial.print("\n 5 LOW \n"); digitalWrite(Pin5, LOW); Pin5ON=false; } if(readString.indexOf("?3=einschalten") > -1) {//Serial.print("\n 3 HIGH \n"); digitalWrite(Pin3, HIGH); Pin3ON=true; } if(readString.indexOf("?3=ausschalten") > -1) {//Serial.print("\n 3 LOW \n"); digitalWrite(Pin3, LOW); Pin3ON=false; } if(readString.indexOf("?6=einschalten") > -1) {//Serial.print("\n 6 HIGH \n"); digitalWrite(Pin6, HIGH); Pin6ON=true; } if(readString.indexOf("?6=ausschalten") > -1) {//Serial.print("\n 6 LOW \n"); digitalWrite(Pin6, LOW); Pin6ON=false; } if(readString.indexOf("?all=Alles+aus") > -1) {//Serial.print("\n 3 LOW \n"); //Serial.print("\n 5 LOW \n"); digitalWrite(Pin3, LOW); digitalWrite(Pin5, LOW); digitalWrite(Pin6, LOW); Pin3ON=false; Pin5ON=false; Pin6ON=false; } client.print("<html><head>"); client.print("<title>Arduino Webserver</title>"); client.println("</head>"); client.print("<body bgcolor='#444444'>"); //---Überschrift--- client.println("<br><hr />"); client.println("<h1><div align='center'><font color='#2076CD'>Arduino Webserver</font color></div></h1>"); client.println("<hr /><br>"); //---Überschrift--- //---Ausgänge schalten--- client.println("<div align='left'><font face='Verdana' color='#FFFFFF'>Ausgänge schalten:</font></div>"); client.println("<br>"); client.println("<table border='1' width='500' cellpadding='5'>"); client.println("<tr bgColor='#222222'>"); client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Ausgang 3<br></font></td>"); client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=3 value='einschalten'></form></td>"); client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=3 value='ausschalten'></form></td>"); if (Pin3ON) client.println("<td align='center'><font color='green' size='5'>ON</td>"); else client.println("<td align='center'><font color='#CFCFCF' size='5'>OFF</td>"); client.println("</tr>"); client.println("<tr bgColor='#222222'>"); client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Ausgang 5<br></font></td>"); client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=5 value='einschalten'></form></td>"); client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=5 value='ausschalten'></form></td>"); if (Pin5ON) client.println("<td align='center'><font color='green' size='5'>ON</td>"); else client.println("<td align='center'><font color='#CFCFCF' size='5'>OFF</td>"); client.println("</tr>"); //3. Ausgang client.println("<tr bgColor='#222222'>"); client.println("<td bgcolor='#222222'><font face='Verdana' color='#CFCFCF' size='2'>Ausgang 6<br></font></td>"); client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='einschalten'></form></td>"); client.println("<td align='center' bgcolor='#222222'><form method=get><input type=submit name=6 value='ausschalten'></form></td>"); if (Pin6ON) client.println("<td align='center'><font color='green' size='5'>ON</td>"); else client.println("<td align='center'><font color='#CFCFCF' size='5'>OFF</td>"); client.println("</tr>"); // ende des 3. Ausgangs client.println("</tr>"); client.println("</table>"); client.println("<br>"); client.println("<form method=get><input type=submit name=all value='Alles aus'></form>"); client.println("</body></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 delay(1); // close the connection: client.stop(); readString=""; } } [code]
vor 1 year 6 days
... Verwendet dein Ethernet shield zufällig deinen dritten Pin? Schonmal versucht einen anderen zu nehmen?
Login or register to post comments