global.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef GLOBAL_H
  2. #define GLOBAL_H
  3. /* 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. void ConfigureWifi()
  15. {
  16. Serial.println("Configuring Wifi");
  17. WiFi.begin (config.ssid.c_str(), config.password.c_str());
  18. if (!config.dhcp)
  19. {
  20. WiFi.config(IPAddress(config.IP[0],config.IP[1],config.IP[2],config.IP[3] ), IPAddress(config.Gateway[0],config.Gateway[1],config.Gateway[2],config.Gateway[3] ) , IPAddress(config.Netmask[0],config.Netmask[1],config.Netmask[2],config.Netmask[3] ));
  21. }
  22. }
  23. void setupWifi(){
  24. if (!ReadConfig()) {
  25. // DEFAULT CONFIG
  26. config.ssid = "Freebox-6F7B3C";
  27. config.password = "accessorem6-gignendi7-insultare!";
  28. config.dhcp = true;
  29. config.IP[0] = 192; config.IP[1] = 168; config.IP[2] = 0; config.IP[3] = 100;
  30. config.Netmask[0] = 255; config.Netmask[1] = 255; config.Netmask[2] = 255; config.Netmask[3] = 0;
  31. config.Gateway[0] = 192; config.Gateway[1] = 168; config.Gateway[2] = 0; config.Gateway[3] = 254;
  32. config.ntpServerName = "0.de.pool.ntp.org";
  33. config.Update_Time_Via_NTP_Every = 0;
  34. config.timezone = -10;
  35. config.daylight = true;
  36. config.DeviceName = "UKI_ESP_default";
  37. config.AutoTurnOff = false;
  38. config.AutoTurnOn = false;
  39. config.TurnOffHour = 0;
  40. config.TurnOffMinute = 0;
  41. config.TurnOnHour = 0;
  42. config.TurnOnMinute = 0;
  43. WriteConfig();
  44. Serial.println("General config applied");
  45. }
  46. if (AdminEnabled) {
  47. WiFi.mode(WIFI_AP_STA);
  48. //WiFi.softAP( ACCESS_POINT_NAME , ACCESS_POINT_PASSWORD);
  49. WiFi.softAP( config.DeviceName.c_str() , ACCESS_POINT_PASSWORD);
  50. }
  51. else { WiFi.mode(WIFI_STA); }
  52. ConfigureWifi();
  53. while (WiFi.status() != 3) {
  54. Serial.println(WiFi.status());
  55. }
  56. // Serial.print(".");
  57. // digitalWrite(Blue_Led, Blue_Led_State);
  58. // Blue_Led_State = !Blue_Led_State;
  59. // yield();
  60. // }
  61. Serial.println(WiFi.status());
  62. /* A MODIFIER : pour le moment si AdminEnabled, lance pendant AdminTimeOut un AP en parallèle de la connection configurée
  63. * devrait être remplacé par - tente de se connecter au wifi configuré, si ok on continue normalement
  64. * - si n'arrive pas à se connecter au wifi configuré, passe en mode AP avec webserver pour reconfigurer le wifi / ou demarrer en mode AP si bouton utilisateur appuyé pendant démarragae
  65. * - normalement redémarre après reconfiguration, donc ok
  66. * - eventuellement ajouter dans loop un redemarrage en cas de perte de connection
  67. */
  68. }
  69. #endif