|
|
@ -6,9 +6,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef APSSID |
|
|
|
#ifndef APSSID |
|
|
|
#define APSSID "ESPap" |
|
|
|
#define APSSID "ESPap" |
|
|
|
#define APPSK "thereisnospoon" |
|
|
|
#define APPSK "thereisnospoon" |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BUTTON D2 |
|
|
|
|
|
|
|
|
|
|
|
/* Set these to your desired credentials. */ |
|
|
|
/* Set these to your desired credentials. */ |
|
|
|
const char *APssid = APSSID; |
|
|
|
const char *APssid = APSSID; |
|
|
|
const char *APpassword = APPSK; |
|
|
|
const char *APpassword = APPSK; |
|
|
@ -21,14 +23,15 @@ WiFiClient wifiClient; |
|
|
|
|
|
|
|
|
|
|
|
String HOST_ADDRESS = "192.168.0.47"; |
|
|
|
String HOST_ADDRESS = "192.168.0.47"; |
|
|
|
|
|
|
|
|
|
|
|
String make_toggle_request(){ |
|
|
|
String make_toggle_request() |
|
|
|
|
|
|
|
{ |
|
|
|
HTTPClient http; |
|
|
|
HTTPClient http; |
|
|
|
String ADCData, station, getData, request; |
|
|
|
String ADCData, station, getData, request; |
|
|
|
|
|
|
|
|
|
|
|
request = "http://" + HOST_ADDRESS + "/cm?cmnd=Power24%20Toggle"; |
|
|
|
request = "http://" + HOST_ADDRESS + "/cm?cmnd=Power24%20Toggle"; |
|
|
|
Serial.println("Sent request to:" + request); |
|
|
|
Serial.println("Sent request to:" + request); |
|
|
|
http.begin(wifiClient, request);
|
|
|
|
http.begin(wifiClient, request); |
|
|
|
|
|
|
|
|
|
|
|
auto httpCode = http.GET(); |
|
|
|
auto httpCode = http.GET(); |
|
|
|
String response = http.getString(); |
|
|
|
String response = http.getString(); |
|
|
|
http.end(); |
|
|
|
http.end(); |
|
|
@ -36,18 +39,22 @@ String make_toggle_request(){ |
|
|
|
return response; |
|
|
|
return response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void handleRoot() { |
|
|
|
void handleRoot() |
|
|
|
make_toggle_request(); |
|
|
|
{ |
|
|
|
web_server.send(200, "text/html", "<h1>Deu bom!</h1>"); |
|
|
|
String response = make_toggle_request(); |
|
|
|
|
|
|
|
web_server.send(200, "text/html", response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void handleSetHost() { |
|
|
|
void handleSetHost() |
|
|
|
|
|
|
|
{ |
|
|
|
String host = web_server.arg("host"); |
|
|
|
String host = web_server.arg("host"); |
|
|
|
Serial.println("Setting host to: " + host); |
|
|
|
Serial.println("Setting host to: " + host); |
|
|
|
HOST_ADDRESS = host; |
|
|
|
HOST_ADDRESS = host; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
void setup() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
pinMode(BUTTON, INPUT_PULLUP); |
|
|
|
delay(1000); |
|
|
|
delay(1000); |
|
|
|
Serial.begin(9600); |
|
|
|
Serial.begin(9600); |
|
|
|
Serial.println("Init"); |
|
|
|
Serial.println("Init"); |
|
|
@ -57,7 +64,8 @@ void setup() { |
|
|
|
// WiFi.mode(WIFI_AP_STA);
|
|
|
|
// WiFi.mode(WIFI_AP_STA);
|
|
|
|
// WiFi.softAP(APssid, APpassword);
|
|
|
|
// WiFi.softAP(APssid, APpassword);
|
|
|
|
WiFi.begin(ssid, password); |
|
|
|
WiFi.begin(ssid, password); |
|
|
|
while (WiFi.status() != WL_CONNECTED) { |
|
|
|
while (WiFi.status() != WL_CONNECTED) |
|
|
|
|
|
|
|
{ |
|
|
|
Serial.print('.'); |
|
|
|
Serial.print('.'); |
|
|
|
delay(1000); |
|
|
|
delay(1000); |
|
|
|
} |
|
|
|
} |
|
|
@ -71,7 +79,22 @@ void setup() { |
|
|
|
Serial.println("HTTP server started"); |
|
|
|
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(); |
|
|
|
web_server.handleClient(); |
|
|
|
} |
|
|
|
} |
|
|
|