global.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef GLOBAL_H
  2. #define GLOBAL_H
  3. /* DEFAULT ACCESS POINT CONFIGURATION */
  4. #define ACCESS_POINT_NAME "ESP"
  5. #define ACCESS_POINT_PASSWORD "12345678"
  6. boolean AdminEnabled = false; // Enable Admin Mode for a given Time
  7. int AdminTimeOutCounter = 0; // Counter for Disabling the AdminMode
  8. #define AdminTimeOut 60 // Defines the Time in Seconds, when the Admin-Mode will be disabled
  9. /* UDP CONFIGURATION */
  10. int UKI_UDP_In_Port = 9000; //udp port input for ESP
  11. IPAddress UKI_UDP_Master_IP(192, 168, 0, 41); //default udp address to send to. Will automatically change to the ip sending something to udp in
  12. int GSR_sensor;
  13. int loop_counter;
  14. int counter;
  15. void setupWifi() {
  16. //if no config in eeprom, start as default access point
  17. if (!ReadConfig()) {
  18. WiFi.mode(WIFI_AP);
  19. WiFi.softAP( ACCESS_POINT_NAME , ACCESS_POINT_PASSWORD);
  20. Serial.println("Starting default access point (SSID:ESP, pwd:12345678)");
  21. Serial.println(WiFi.softAPIP());
  22. }
  23. //if config in eeprom, try and connect to wifi, if fail after timeout start access point with config.name SSID
  24. else {
  25. WiFi.mode(WIFI_STA);
  26. // ConfigureWifi();
  27. Serial.println("Connecting to configured wifi network");
  28. while (WiFi.status() != 3) {
  29. counter++;
  30. Serial.print(".");
  31. Serial.println(WiFi.status());
  32. if (counter > 50) {
  33. Serial.println("failed");
  34. Serial.println("Starting as access point, SSID:"+ (String)config.DeviceName.c_str()+" pwd:" + (String)ACCESS_POINT_PASSWORD);
  35. WiFi.mode(WIFI_AP);
  36. //WiFi.softAP( ACCESS_POINT_NAME , ACCESS_POINT_PASSWORD);
  37. WiFi.softAP( config.DeviceName.c_str() , ACCESS_POINT_PASSWORD);
  38. Serial.println(WiFi.softAPIP());
  39. break;
  40. }
  41. }
  42. }
  43. }
  44. #endif