Advertisement
pleasedontcode

**Web Server** rev_02

Oct 14th, 2024
72
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: **Web Server**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-14 20:56:48
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* adjust baseline code to convert code using */
  21.     /* espasyncwebserver and SPIFFS. Let's consider that */
  22.     /* javascript code is already integrated in html */
  23.     /* file. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - code is incomplete. you loose entire baseline code.
  30. ********* User code review feedback **********/
  31.  
  32. /* START CODE */
  33.  
  34. /****** DEFINITION OF LIBRARIES *****/
  35. #include <ESPAsyncWebSrv.h>  // Asynchronous WebServer library
  36. #include <SPIFFS.h>          // SPIFFS library for file system
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. AsyncWebServer server(80); // Create an instance of the AsyncWebServer
  44.  
  45. const char* ssid = "YOUR_SSID"; // Replace with your WiFi SSID
  46. const char* password = "YOUR_PASSWORD"; // Replace with your WiFi Password
  47.  
  48. void setup(void)
  49. {
  50.     // Initialize serial communication
  51.     Serial.begin(115200);
  52.    
  53.     // Initialize SPIFFS
  54.     if (!SPIFFS.begin(true)) {
  55.         Serial.println("SPIFFS Mount Failed");
  56.         return;
  57.     }
  58.  
  59.     // Serve static files from SPIFFS
  60.     server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
  61.  
  62.     // Handle not found requests
  63.     server.onNotFound([](AsyncWebServerRequest *request) {
  64.         request->send(404, "text/plain", "Not found");
  65.     });
  66.  
  67.     // Start the server
  68.     server.begin();
  69.     Serial.println("Server started");
  70. }
  71.  
  72. void loop(void)
  73. {
  74.     // Main loop can be empty as the server handles requests asynchronously
  75. }
  76.  
  77. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement