diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/src/main.cpp b/src/main.cpp index ad50d5a..170fc1a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,9 +6,11 @@ #ifndef APSSID #define APSSID "ESPap" -#define APPSK "thereisnospoon" +#define APPSK "thereisnospoon" #endif +#define BUTTON D2 + /* Set these to your desired credentials. */ const char *APssid = APSSID; const char *APpassword = APPSK; @@ -21,14 +23,15 @@ WiFiClient wifiClient; String HOST_ADDRESS = "192.168.0.47"; -String make_toggle_request(){ +String make_toggle_request() +{ HTTPClient http; String ADCData, station, getData, request; request = "http://" + HOST_ADDRESS + "/cm?cmnd=Power24%20Toggle"; Serial.println("Sent request to:" + request); - http.begin(wifiClient, request); - + http.begin(wifiClient, request); + auto httpCode = http.GET(); String response = http.getString(); http.end(); @@ -36,18 +39,22 @@ String make_toggle_request(){ return response; } -void handleRoot() { - make_toggle_request(); - web_server.send(200, "text/html", "

Deu bom!

"); +void handleRoot() +{ + String response = make_toggle_request(); + web_server.send(200, "text/html", response); } -void handleSetHost() { +void handleSetHost() +{ String host = web_server.arg("host"); Serial.println("Setting host to: " + host); HOST_ADDRESS = host; } -void setup() { +void setup() +{ + pinMode(BUTTON, INPUT_PULLUP); delay(1000); Serial.begin(9600); Serial.println("Init"); @@ -57,7 +64,8 @@ void setup() { // WiFi.mode(WIFI_AP_STA); // WiFi.softAP(APssid, APpassword); WiFi.begin(ssid, password); - while (WiFi.status() != WL_CONNECTED) { + while (WiFi.status() != WL_CONNECTED) + { Serial.print('.'); delay(1000); } @@ -71,7 +79,22 @@ void setup() { Serial.println("HTTP server started"); } +void loop() +{ + if(digitalRead(BUTTON) == LOW) { + //digitalWrite(LED_BUILTIN, HIGH); + //int v = digitalRead(BUTTON); + //Serial.print("READ: "); + //Serial.println(v); + // Wait for the button to be released + //while(digitalRead(BUTTON) == LOW) { + // delay(100); + //} + //digitalWrite(LED_BUILTIN, LOW); + //Serial.println("BOO"); + make_toggle_request(); + delay(500); + } -void loop() { web_server.handleClient(); }