Created
June 9, 2015 15:13
-
-
Save michaelsarduino/65d58cfb486f964335f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
import processing.net.*; | |
String HTTP_GET_REQUEST = "GET /"; | |
String HTTP_HEADER = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"; //speichern des Headers. | |
Serial arduino; //erstellen von arduino als Objekt vom Typ Serial | |
String datenpuffer; //Variable zum Abspeichern der Daten der seriellen Verbindung | |
String website; //aktueller Wortlaut der Website | |
String neu; //Speicherort fuer neue Bewegungsmeldung mit Uhrzeit | |
Server s; //Server | |
Client c; //Client | |
String input; //Variable fuer Verbindungsanfragen | |
long akt; //Speichervariable | |
long last; //Speichervariable | |
void setup() | |
{ | |
String port = Serial.list()[0]; | |
arduino = new Serial(this, port, 9600); //starten der seriellen Verbindung mit Arduino | |
s = new Server(this, 8080); //server starten auf port 8080 | |
website = "<html> Hallo hier ist der Arduino <br>"; //Anfangsinhalt der Website | |
} | |
void draw() | |
{ | |
if(arduino.available() > 0) | |
{ | |
datenpuffer = arduino.readStringUntil('\n'); | |
akt = millis(); | |
if((akt - last) > 5000) | |
{ | |
neu = hour() + ":" + minute() + ":" + second() + ": " + "Bewegung erkannt" + "<br />"; | |
website = website + neu; | |
last = millis(); | |
} | |
} //Wenn der Arduino etwas gesandt hat, wird die aktuelle Uhrzeit samt der Meldung Bewegung erkannt zum Websitentext hinzugefuegt | |
c = s.available(); //ueberpruefen, ob Client vorhanden | |
if (c != null) { //wenn Client vorhanden | |
input = c.readString(); //abspeichern der Verbindungsanfragen | |
input = input.substring(0, input.indexOf("\n")); //abspeichern der ersten Zeile | |
if (input.indexOf(HTTP_GET_REQUEST) == 0) //ueberpruefen ob empfangene Anfrage korrekt ist | |
{ | |
c.write(HTTP_HEADER); //Header senden (Verbindung starten) | |
c.write(website); //HTML Code senden | |
c.stop(); //schließen der Verbindung | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment