Hallo zusammen,
nachdem ich es endlich geschafft habe meine Funksteckdosen zu schalten, habe ich einen weiteren Schritt draufgesattelt und mir mittels Ethernet-Shield einen Webserver gebastelt, so dass ich über einen Link die Dosen ein und ausschalten kann.
Das funktioniert auch prima.
Leider gibt's aber Nebenwirkungen:
Solange der Arduino Saft hat, funktioniert meine Fernbedienung der Dosen nicht mehr und auch unsere Funktürklingel kriegt das Klingeln nicht mehr mit. Die Frequenz scheint komplett blockiert zu sein und ich versteh nicht, warum.
Hier mein Sketch:
#include <Ethernet.h>
#include <RCSwitch.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
};
IPAddress ip(10, 250, 250, 114);
// 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;
RCSwitch mySwitch24 = RCSwitch();
RCSwitch mySwitch28 = RCSwitch();
void setup() {
// Open serial communications and wait for port to open:
// Transmitter is connected to Arduino Pin #10
mySwitch24.enableTransmit(10);
mySwitch28.enableTransmit(10);
// Optional set protocol (default is 1, will work for most outlets)
mySwitch24.setProtocol(1);
mySwitch28.setProtocol(2);
// Optional set pulse length.
mySwitch24.setPulseLength(314);
mySwitch28.setPulseLength(475);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
}
void loop() {
readString = "";
// 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();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString += 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
if(readString.indexOf("1-on") >0)//checks for on
{
mySwitch24.send(4276501, 24);
mySwitch28.send(40124578, 28);
} else if (readString.indexOf("1-off") >0)
{
mySwitch28.send(40672262, 28);
mySwitch24.send(4276500, 24);
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html><body style=\"font-size:5em;\">");
client.print( "<a href=\"http://10.250.250.114?x=1-on\">Switch #1 on</a>
");
client.print( "<a href=\"http://10.250.250.114?x=1-off\">Switch #1 off</a>");
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();
Ethernet.maintain();
}
}
Jemand eine Idee?
Das Ganze läuft auf einem Uno mit einem W5100-Ethernet-Shield.