Browse Source

toggle button

feature/basic_test
Brian Stubbs 2 years ago
parent
commit
90c8d9b1d6
  1. 10
      .vscode/extensions.json
  2. 39
      src/main.cpp

10
.vscode/extensions.json vendored

@ -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"
]
}

39
src/main.cpp

@ -9,6 +9,8 @@
#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,7 +23,8 @@ 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;
@ -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();
} }

Loading…
Cancel
Save