Advertisement
pleasedontcode

Charli_Speaker

Mar 31st, 2024
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 3.14 KB | Source Code | 0 0
  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: Charli_Speaker
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-04-01 00:12:17
  15.     - Source Code generated by:
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.     /* Configure WiFi and timezone settings with web page */
  22.     /* available via both AP and STA */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SPI.h>
  27. #include <WiFi.h>
  28. #include <AsyncTCP.h>
  29. #include <ESPAsyncWebServer.h>
  30. #include <NTPClient.h>
  31. #include <WiFiUdp.h>
  32. #include <SPIFFS.h>
  33.  
  34. /***** DEFINITION OF SPI PINS *****/
  35. const uint8_t sdcard_SDCardModule_SPI_PIN_MOSI_D23 = 23;
  36. const uint8_t sdcard_SDCardModule_SPI_PIN_MISO_D19 = 19;
  37. const uint8_t sdcard_SDCardModule_SPI_PIN_SCLK_D18 = 18;
  38. const uint8_t sdcard_SDCardModule_SPI_PIN_CS_D5 = 5;
  39.  
  40. /****** WiFi and Timezone Configuration *****/
  41. // WiFi credentials
  42. const char* ssid = "YourWiFiNetwork";
  43. const char* password = "YourWiFiPassword";
  44.  
  45. // NTP server settings
  46. const char* ntpServer = "pool.ntp.org";
  47. const long gmtOffset_sec = 3600;
  48. const int daylightOffset_sec = 3600;
  49.  
  50. // Declare objects for NTP client and WiFi
  51. WiFiUDP ntpUDP;
  52. NTPClient timeClient(ntpUDP, ntpServer, gmtOffset_sec, daylightOffset_sec);
  53.  
  54. // Create access point and web server objects
  55. const char* apSSID = "ESP32-AP";
  56. const char* apPassword = "password";
  57. AsyncWebServer server(80);
  58.  
  59. void setup() {
  60.   // put your setup code here, to run once:
  61.   pinMode(sdcard_SDCardModule_SPI_PIN_CS_D5, OUTPUT);
  62.   // start the SPI library:
  63.   SPI.begin();
  64.  
  65.   // Initialize Serial communication
  66.   Serial.begin(115200);
  67.  
  68.   // Connect to WiFi network
  69.   WiFi.mode(WIFI_AP_STA);
  70.   WiFi.begin(ssid, password);
  71.  
  72.   while (WiFi.status() != WL_CONNECTED) {
  73.     delay(1000);
  74.     Serial.println("Connecting to WiFi...");
  75.   }
  76.  
  77.   // Print IP address
  78.   Serial.println("");
  79.   Serial.print("Connected to WiFi. IP Address: ");
  80.   Serial.println(WiFi.localIP());
  81.  
  82.   // Initialize NTP client
  83.   timeClient.begin();
  84.  
  85.   // Configure access point
  86.   WiFi.softAP(apSSID, apPassword);
  87.  
  88.   // Set up web server routes
  89.   server.on("/", HTTP_GET, [](AsyncWebServerRequest* request){
  90.     request->send(SPIFFS, "/index.html", "text/html");
  91.   });
  92.  
  93.   server.on("/submit", HTTP_POST, [](AsyncWebServerRequest* request){
  94.     // Handle form submission here
  95.   });
  96.  
  97.   // Start web server
  98.   server.begin();
  99. }
  100.  
  101. void loop() {
  102.   // put your main code here, to run repeatedly:
  103.   timeClient.update();
  104.  
  105.   // Rest of your code goes here
  106.  
  107.   // Example usage of NTP client
  108.   Serial.print("Current time: ");
  109.   Serial.println(timeClient.getFormattedTime());
  110.  
  111.   delay(1000);
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement