Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: Charli_Speaker
- - Source Code compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-04-01 00:12:17
- - Source Code generated by:
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Configure WiFi and timezone settings with web page */
- /* available via both AP and STA */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <WiFi.h>
- #include <AsyncTCP.h>
- #include <ESPAsyncWebServer.h>
- #include <NTPClient.h>
- #include <WiFiUdp.h>
- #include <SPIFFS.h>
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t sdcard_SDCardModule_SPI_PIN_MOSI_D23 = 23;
- const uint8_t sdcard_SDCardModule_SPI_PIN_MISO_D19 = 19;
- const uint8_t sdcard_SDCardModule_SPI_PIN_SCLK_D18 = 18;
- const uint8_t sdcard_SDCardModule_SPI_PIN_CS_D5 = 5;
- /****** WiFi and Timezone Configuration *****/
- // WiFi credentials
- const char* ssid = "YourWiFiNetwork";
- const char* password = "YourWiFiPassword";
- // NTP server settings
- const char* ntpServer = "pool.ntp.org";
- const long gmtOffset_sec = 3600;
- const int daylightOffset_sec = 3600;
- // Declare objects for NTP client and WiFi
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, ntpServer, gmtOffset_sec, daylightOffset_sec);
- // Create access point and web server objects
- const char* apSSID = "ESP32-AP";
- const char* apPassword = "password";
- AsyncWebServer server(80);
- void setup() {
- // put your setup code here, to run once:
- pinMode(sdcard_SDCardModule_SPI_PIN_CS_D5, OUTPUT);
- // start the SPI library:
- SPI.begin();
- // Initialize Serial communication
- Serial.begin(115200);
- // Connect to WiFi network
- WiFi.mode(WIFI_AP_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting to WiFi...");
- }
- // Print IP address
- Serial.println("");
- Serial.print("Connected to WiFi. IP Address: ");
- Serial.println(WiFi.localIP());
- // Initialize NTP client
- timeClient.begin();
- // Configure access point
- WiFi.softAP(apSSID, apPassword);
- // Set up web server routes
- server.on("/", HTTP_GET, [](AsyncWebServerRequest* request){
- request->send(SPIFFS, "/index.html", "text/html");
- });
- server.on("/submit", HTTP_POST, [](AsyncWebServerRequest* request){
- // Handle form submission here
- });
- // Start web server
- server.begin();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- timeClient.update();
- // Rest of your code goes here
- // Example usage of NTP client
- Serial.print("Current time: ");
- Serial.println(timeClient.getFormattedTime());
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement