Skip to content

Instantly share code, notes, and snippets.

@danilopinotti
Last active April 26, 2021 02:00
Show Gist options
  • Save danilopinotti/17422febfaef2fd58854e191b6faad9d to your computer and use it in GitHub Desktop.
Save danilopinotti/17422febfaef2fd58854e191b6faad9d to your computer and use it in GitHub Desktop.
Código para treinamento sobre bibliotecas e utilização delas
#include <Led.h>
#include <WebServer.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
Led led(2);
WebServer webServer(80);
void setupWifi() {
WiFi.mode(WIFI_STA);
WiFiManager wifiManager;
// Apaga os dados salvos da última rede wifi conectada
// wifiManager.resetSettings();
bool successConnection;
successConnection = wifiManager.autoConnect("Treinamento", "password");
if (successConnection == false) {
Serial.println("Failed to connect. Restarting ESP");
ESP.restart();
return;
}
Serial.print("WiFi Connected. IP address: ");
Serial.println(WiFi.localIP());
}
void handleToogle() {
led.toggle();
webServer.send(200, "text/plain", "Led toggle OK!");
}
void setup() {
Serial.begin(19200);
setupWifi();
webServer.on("/toggle", handleToogle);
webServer.begin();
}
void loop() {
webServer.handleClient();
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment