AutoConnectNonBlockingwParams.ino 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
  2. WiFiManager wm;
  3. WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40);
  4. void setup() {
  5. WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
  6. // put your setup code here, to run once:
  7. Serial.begin(115200);
  8. //reset settings - wipe credentials for testing
  9. //wm.resetSettings();
  10. wm.addParameter(&custom_mqtt_server);
  11. wm.setConfigPortalBlocking(false);
  12. wm.setSaveParamsCallback(saveParamsCallback);
  13. //automatically connect using saved credentials if they exist
  14. //If connection fails it starts an access point with the specified name
  15. if(wm.autoConnect("AutoConnectAP")){
  16. Serial.println("connected...yeey :)");
  17. }
  18. else {
  19. Serial.println("Configportal running");
  20. }
  21. }
  22. void loop() {
  23. wm.process();
  24. // put your main code here, to run repeatedly:
  25. }
  26. void saveParamsCallback () {
  27. Serial.println("Get Params:");
  28. Serial.print(custom_mqtt_server.getID());
  29. Serial.print(" : ");
  30. Serial.println(custom_mqtt_server.getValue());
  31. }