diff --git a/Arduino Code/DasSchmalter/DasSchmalter.ino b/Arduino Code/DasSchmalter/DasSchmalter.ino new file mode 100644 index 0000000..c734701 --- /dev/null +++ b/Arduino Code/DasSchmalter/DasSchmalter.ino @@ -0,0 +1,151 @@ +const byte led = D1; +const byte button = D5; +bool LEDstate = false; + +#include + +#define WIFI_MODE_CLIENT //can be WIFI_MODE_MASTER + +// Replace with your network credentials +char* ssid = "DPWL";//"WIV"; //"DasSchmalter"; +char* password = "3p7iX/2gV";//"DF~12qa.40"; //"12345678"; + + +// Set web server port number to 80 +WiFiServer server(80); + +String header; +// the code for the whole ebinterface +String webInterface = "\n\n\n\n\n\n\nDas Schmalter\n\n\n\n\n\n\n\n\n\n

Das Schmalter

\n\n
\n\n\n\n
\n\n\n\n"; + +// Configure the static ip adress +#ifdef WIFI_MODE_CLIENT +IPAddress local_IP(192, 168, 4, 10); +#endif +#ifdef WIFI_MODE_MASTER +IPAddress local_IP(192, 168, 4, 1); +#endif +IPAddress gateway(192, 168, 4, 1); +IPAddress subnet(255, 255, 255, 0); + +volatile unsigned long oldTime = 0, debounceTime = 200; +void toggleLED() { + if ((millis() - oldTime) > debounceTime) { + + if (digitalRead(button) == LOW) { + LEDstate = ! LEDstate; + digitalWrite(led, LEDstate); + } + } + oldTime = millis(); +} + +void setup() { + // put your setup code here, to run once: + pinMode(led, OUTPUT); + pinMode(button, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(button), toggleLED, FALLING); + Serial.begin(9600); + + /*if (!WiFi.config(local_IP, gateway, subnet)) { + //Serial.println("STA Failed to configure"); + } */ +#ifdef WIFI_MODE_MASTER + //Serial.print("Configuring access point..."); + //WiFi.softAPConfig(local_IP, gateway, subnet); + WiFi.softAP(ssid, password); + + IPAddress myIP = WiFi.softAPIP(); + //Serial.print("AP IP address: "); + //Serial.println(myIP); +#endif + +#ifdef WIFI_MODE_CLIENT + WiFi.begin(ssid, password); + Serial.print("Connecting to WiFi.."); + while (WiFi.status() != WL_CONNECTED) { + delay(1000); + Serial.print("."); + } + + Serial.println(""); + Serial.println("Connected to the WiFi network"); + Serial.println(WiFi.localIP()); +#endif + + server.begin(); +} + + +void loop() { + // put your main code here, to run repeatedly: + WiFiClient client = server.available(); // Listen for incoming clients + + if (client) { // If a new client connects, + //Serial.println("New Client."); // print a message out in the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + //Serial.write(c); // print it out the serial monitor + header += c; + if (c == '\n') { // if the byte is a newline character + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println("Access-Control-Allow-Origin: *"); + client.println("Connection: close"); + client.println(); + + // turns the GPIOs on and off + if (header.indexOf("GET /api/on") >= 0) { + //Serial.println("LAMP on"); + LEDstate = true; + digitalWrite(led, HIGH); + client.println("{\"command\":\"on\",\"response\":\"OK\"}"); + } else if (header.indexOf("GET /api/off") >= 0) { + //Serial.println("LAMP off"); + LEDstate = false; + digitalWrite(led, LOW); + client.println("{\"command\":\"off\",\"response\":\"OK\"}"); + } else if (header.indexOf("GET /api/state") >= 0) { + if(LEDstate) { + client.println("{\"command\":\"state\",\"response\":\"ON\"}"); + } + else { + client.println("{\"command\":\"state\",\"response\":\"OFF\"}"); + } + //Serial.println("LAMP status"); + } + else { + // Display the HTML web page + client.println(webInterface); + + } + + + + // The HTTP response ends with another blank line + client.println(); + // Break out of the while loop + break; + } else { // if you got a newline, then clear currentLine + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + } + } + // Clear the header variable + header = ""; + // Close the connection + client.stop(); + //Serial.println("Client disconnected."); + //Serial.println(""); + } +} diff --git a/DasSchmalter.pro b/Das Schmalter App/Qt-Code/DasSchmalter.pro similarity index 100% rename from DasSchmalter.pro rename to Das Schmalter App/Qt-Code/DasSchmalter.pro diff --git a/appsettings.cpp b/Das Schmalter App/Qt-Code/appsettings.cpp similarity index 100% rename from appsettings.cpp rename to Das Schmalter App/Qt-Code/appsettings.cpp diff --git a/appsettings.h b/Das Schmalter App/Qt-Code/appsettings.h similarity index 100% rename from appsettings.h rename to Das Schmalter App/Qt-Code/appsettings.h diff --git a/main.cpp b/Das Schmalter App/Qt-Code/main.cpp similarity index 100% rename from main.cpp rename to Das Schmalter App/Qt-Code/main.cpp diff --git a/main.qml b/Das Schmalter App/Qt-Code/main.qml similarity index 100% rename from main.qml rename to Das Schmalter App/Qt-Code/main.qml diff --git a/off.png b/Das Schmalter App/Qt-Code/off.png similarity index 100% rename from off.png rename to Das Schmalter App/Qt-Code/off.png diff --git a/on0.png b/Das Schmalter App/Qt-Code/on0.png similarity index 100% rename from on0.png rename to Das Schmalter App/Qt-Code/on0.png diff --git a/on1.png b/Das Schmalter App/Qt-Code/on1.png similarity index 100% rename from on1.png rename to Das Schmalter App/Qt-Code/on1.png diff --git a/on2.png b/Das Schmalter App/Qt-Code/on2.png similarity index 100% rename from on2.png rename to Das Schmalter App/Qt-Code/on2.png diff --git a/on3.png b/Das Schmalter App/Qt-Code/on3.png similarity index 100% rename from on3.png rename to Das Schmalter App/Qt-Code/on3.png diff --git a/on4.png b/Das Schmalter App/Qt-Code/on4.png similarity index 100% rename from on4.png rename to Das Schmalter App/Qt-Code/on4.png diff --git a/on5.png b/Das Schmalter App/Qt-Code/on5.png similarity index 100% rename from on5.png rename to Das Schmalter App/Qt-Code/on5.png diff --git a/qml.qrc b/Das Schmalter App/Qt-Code/qml.qrc similarity index 100% rename from qml.qrc rename to Das Schmalter App/Qt-Code/qml.qrc diff --git a/shared.qrc b/Das Schmalter App/Qt-Code/shared.qrc similarity index 100% rename from shared.qrc rename to Das Schmalter App/Qt-Code/shared.qrc