Hallo zusammen!
Habe hier mal ein ganzes Programm. Könnte es mir mal jemand durchchecken?
Vielleicht sind ja Fehler drin! Es soll die Webseite an den Client gesendet werden,
wenn es an der Tür klingelt.
Vielen Dank schonmal. Freue mich auf jede Hilfe!
#include <SPI.h>
#include <Ethernet.h>
#include <Flash.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x40, 0xF2 }; // MAC-Adresse
byte ip[] = { 192, 168, 178, 22 }; // IP-Adresse
byte gateway[] = { 192, 168, 178, 1 }; // Gateway
byte subnet[] = { 255, 255, 255, 0 }; // Subnetz
byte xbmc_ip[] = { 192, 168, 178, 43 }; // XBMC IP
Server server(80);
Client xbmc(xbmc_ip, 80);
int Pin8 = 8; // Digital Input
int Pin3 = 3; // Digital Output
int Pin5 = 5; // Analog Output
int Pin6 = 6; // Analog Output
int state;
int helligkeit = 0;
String readString = String(100); // String for data from address
boolean Pin8ON = false; // Status flag
boolean Pin3ON = false; // Status flag
boolean Pin5ON = false; // Status flag
boolean Pin6ON = false; // Status flag
void setup() {
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
pinMode(Pin8, INPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin5, OUTPUT);
pinMode(Pin6, OUTPUT);
digitalWrite(Pin3, state);
analogWrite(Pin5, helligkeit);
analogWrite(Pin6, helligkeit);
Serial.begin(9600);
}
void loop() {
//Create a client connection
Client 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 = readString + c;
}
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
if (c == '\n') {
// indexOf locates a character or String within another String
// returns the index of val within the String, or -1 if not found
if(readString.indexOf("3=einschalten") > -1) {
//Setting Pin3 to HIGH
digitalWrite(Pin3, HIGH);
//printing to line that door is open
Serial.println("Tür ist offen!");
//setting local variable to true
Pin3ON = true;
//sleeping for 2.5 seconds
delay(2500);
//setting Pin3 again to LOW
digitalWrite(Pin3, LOW);
//printing to line that door is now closed again
Serial.println("Tür ist geschlossen!");
//setting local variable to false again
Pin3ON = false;
}
if(readString.indexOf("5=heller") > -1) {
if(helligkeit<255) {
helligkeit++;
analogWrite(Pin5, helligkeit);
delay(10);
Serial.println("Dimmen +");
Pin5ON = true;
}
}
//else { Pin5ON = false;
//}
if(readString.indexOf("6=dunkler") > -1){
if(helligkeit!=0) {
helligkeit--;
analogWrite(Pin6, helligkeit);
delay(10);
Serial.println("Dimmen-");
Pin6ON = true;
}
}
else {
Pin6ON = false;
}
if(readString.indexOf("all=Alles+aus") > -1){
digitalWrite(Pin3, LOW);
analogWrite(Pin5, LOW);
analogWrite(Pin6, LOW);
Serial.println("Alles ausgeschaltet");
Pin3ON = false;
Pin5ON = false;
Pin6ON = false;
}
if(readString.indexOf("klingel=Klingel") > -1){ // (sphere start)
if (xbmc.connect())
{
Serial.println("xbmc connected");
// Make a HTTP request:
xbmc.println("GET /xbmcCmds/xbmcHttp?command=ExecBuiltIn(RunScript(special://home/addons/script.playcam/default.py)) HTTP/1.0");
Serial.println("xbmc command sent");
xbmc.stop();
}
else
{
// could not contact xbmc
Serial.println("xbmc connection failed");
}
} // (...end)
}
}