Advertisement
pleasedontcode

WiFi Management rev_94

Oct 1st, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: WiFi Management
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-01 21:43:49
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Configure WiFi and timezone settings with web page */
  21.     /* available via both AP and STA */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Wire.h>
  26. #include <WiFi.h> // Include WiFi library for network connectivity
  27. #include <EasyButton.h> //https://github.com/evert-arias/EasyButton
  28. #include <Adafruit_SSD1306.h>   //https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
  29. #include <U8g2_for_Adafruit_GFX.h>  //https://github.com/olikraus/U8g2_for_Adafruit_GFX
  30. #include "DisplayHandler.h" // Include the display handler header
  31. #include "EasyButtonHandler.h" // Include the EasyButton handler header
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36. void updateOutputs();
  37. void configureWiFi(); // Function to configure WiFi settings
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t test_PushButton_PIN_D4        = 4;
  41.  
  42. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  43. const uint8_t relay_RelayModule_Signal_PIN_D13      = 13;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. bool    relay_RelayModule_Signal_PIN_D13_rawData        = 0;
  47.  
  48. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  49. float   relay_RelayModule_Signal_PIN_D13_phyData        = 0.0;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  52. // The EasyButton object is now instantiated in EasyButtonHandler.h
  53. // The Adafruit_SSD1306 object is now instantiated in DisplayHandler.h
  54. // The U8G2_FOR_ADAFRUIT_GFX object is also instantiated in DisplayHandler.h
  55.  
  56. void setup(void)
  57. {
  58.     // put your setup code here, to run once:
  59.     Serial.begin(115200); // Initialize serial communication for debugging
  60.  
  61.     pinMode(test_PushButton_PIN_D4, INPUT_PULLUP);
  62.     pinMode(relay_RelayModule_Signal_PIN_D13, OUTPUT);
  63.  
  64.     // Initialize the button
  65.     button1.begin();
  66.     button1.onPressed(onButton1Pressed); // Set the callback for button press
  67.  
  68.     // Initialize the OLED display
  69.     initializeDisplay(); // Call the display initialization function
  70.  
  71.     // Configure WiFi settings
  72.     configureWiFi(); // Call the function to configure WiFi
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.     updateOutputs(); // Refresh output data
  79.     button1.read(); // Read the button state
  80. }
  81.  
  82. void updateOutputs()
  83. {
  84.     digitalWrite(relay_RelayModule_Signal_PIN_D13, relay_RelayModule_Signal_PIN_D13_rawData);
  85. }
  86.  
  87. // Function to configure WiFi settings
  88. void configureWiFi() {
  89.     const char* ssid = "Your_SSID"; // Replace with your WiFi SSID
  90.     const char* password = "Your_PASSWORD"; // Replace with your WiFi password
  91.  
  92.     // Start WiFi in AP mode
  93.     WiFi.softAP(ssid, password);
  94.     Serial.println("Access Point started");
  95.  
  96.     // Start WiFi in STA mode
  97.     WiFi.begin(ssid, password);
  98.     while (WiFi.status() != WL_CONNECTED) {
  99.         delay(1000);
  100.         Serial.println("Connecting to WiFi...");
  101.     }
  102.     Serial.println("Connected to WiFi");
  103.    
  104.     // Set timezone (example: GMT+0)
  105.     configTime(0, 0, "pool.ntp.org", "time.nist.gov"); // Configure NTP server for time synchronization
  106. }
  107.  
  108. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement