Advertisement
pleasedontcode

**Async Server** rev_01

Oct 14th, 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: **Async Server**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-14 20:55:22
  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. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <ESPAsyncWebSrv.h>  // Asynchronous WebServer library
  30. #include <SPIFFS.h>          // SPIFFS library for file system
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  37. AsyncWebServer server(80); // Create an instance of the AsyncWebServer
  38.  
  39. void setup(void)
  40. {
  41.     // Initialize serial communication
  42.     Serial.begin(115200);
  43.    
  44.     // Initialize SPIFFS
  45.     if (!SPIFFS.begin(true)) {
  46.         Serial.println("SPIFFS Mount Failed");
  47.         return;
  48.     }
  49.  
  50.     // Serve static files from SPIFFS
  51.     server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
  52.  
  53.     // Handle not found requests
  54.     server.onNotFound([](AsyncWebServerRequest *request) {
  55.         request->send(404, "text/plain", "Not found");
  56.     });
  57.  
  58.     // Start the server
  59.     server.begin();
  60.     Serial.println("Server started");
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // Main loop can be empty as the server handles requests asynchronously
  66. }
  67.  
  68. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement