02_wifi.ino 794 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <WiFi.h>
  2. #define NETWORK "Guest WiFi Signal"
  3. #define PASSWORD "something easy"
  4. #define HOSTNAME "outdoor-weather-station"
  5. void connectWifi() {
  6. WiFi.begin(NETWORK, PASSWORD);
  7. debugNoLn("Connecting to wifi ..");
  8. int64_t startTime = millis();
  9. while (WiFi.status() != WL_CONNECTED) {
  10. if(millis() - startTime > WIFI_TIMEOUT_SECONDS * 1000) {
  11. debug("Could not connect to wifi.");
  12. ERR;
  13. }
  14. debugNoLn(".");
  15. showProgress(PROGRESS_BLUE);
  16. delay(500);
  17. }
  18. debug("");
  19. debug("=====");
  20. debug("Connected!");
  21. debugln("IP: ", WiFi.localIP());
  22. debugln("Strength: ", WiFi.RSSI());
  23. debugln("DNS: ", WiFi.dnsIP());
  24. debugln("Gateway: ", WiFi.gatewayIP());
  25. }
  26. void initWifi() {
  27. WiFi.mode(WIFI_STA);
  28. // Set the hostname
  29. WiFi.setHostname(HOSTNAME);
  30. connectWifi();
  31. }