Hallo zusammen,
ich bin Arduinobastler in jungen Tagen und versuche mich gerade an einem Webserver, welcher im Netzwerk ansteuerbar ist und "Hallo Welt" per Klick ausgeben soll.
Sende hier mal mein bisheriges Programm.
Bitte schaue es sich mal jemand an und gebe mir Rückmeldung dazu.
(Ich erwarte nicht unbedingt eine Musterlösung. Es würde mir auch schon ein hilfreicher Denkanstoß oder Link zu einem Tutorial helfen)
Vielen Dank im Vorraus.
Magic
#include <SPI.h> //Anbindung microcontroller an Ethernet-Shield
#include <Ethernet.h>
int x;
// 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, 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);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
pinMode(5, OUTPUT);
}
void loop()
{
if (x==1){
analogWrite(5, 200);
}
// 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 (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:
client.println("");
client.println("");
client.println("Sörens Testpage");
client.println(" <input type='submit' name='buttoncolorchange' id='button' value='Farbwechsel' method='post' onclick=' alert('Hallo Welt') '/> ");
client.println("");
client.println("");
client.println("");
client.println("");
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();
}
}[/table]