Basic.ino 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
  2. void setup() {
  3. WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  4. // put your setup code here, to run once:
  5. Serial.begin(115200);
  6. // WiFi.mode(WiFi_STA); // it is a good practice to make sure your code sets wifi mode how you want it.
  7. //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
  8. WiFiManager wm;
  9. //reset settings - wipe credentials for testing
  10. //wm.resetSettings();
  11. // Automatically connect using saved credentials,
  12. // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
  13. // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
  14. // then goes into a blocking loop awaiting configuration and will return success result
  15. bool res;
  16. // res = wm.autoConnect(); // auto generated AP name from chipid
  17. // res = wm.autoConnect("AutoConnectAP"); // anonymous ap
  18. res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
  19. if(!res) {
  20. Serial.println("Failed to connect");
  21. // ESP.restart();
  22. }
  23. else {
  24. //if you get here you have connected to the WiFi
  25. Serial.println("connected...yeey :)");
  26. }
  27. }
  28. void loop() {
  29. // put your main code here, to run repeatedly:
  30. }