Advertisement
pleasedontcode

**Async Server** rev_03

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:59:13
  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> //https://github.com/dvarrel/ESPAsyncWebSrv
  30. #include <FS.h>               // Include the FS library for SPIFFS
  31. #include <SPIFFS.h>          // Include the SPIFFS library
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. AsyncWebServer server(80); // Create an instance of the server
  39.  
  40. void setup(void)
  41. {
  42.     // Initialize Serial for debugging
  43.     Serial.begin(115200);
  44.    
  45.     // Initialize SPIFFS
  46.     if (!SPIFFS.begin(true)) {
  47.         Serial.println("SPIFFS Mount Failed");
  48.         return;
  49.     }
  50.  
  51.     // Serve static files from SPIFFS
  52.     server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.htm");
  53.  
  54.     // Handle not found requests
  55.     server.onNotFound([](AsyncWebServerRequest *request){
  56.         request->send(404, "text/plain", "Not found");
  57.     });
  58.  
  59.     // Start the server
  60.     server.begin();
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // Main code to run repeatedly
  66. }
  67.  
  68. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement