Advertisement
pleasedontcode

**Web Server** rev_01

Nov 27th, 2024
73
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: ESP8266 NodeMCU V1.0
  14.     - Source Code created on: 2024-11-27 20:12:10
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create a robust esp8266 project that leverages */
  21.     /* connected components for efficient data */
  22.     /* acquisition and processing. The system should */
  23.     /* prioritize user-friendly interfaces and modular */
  24.     /* design for easy upgrades. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <ESP8266WiFi.h>
  31. #include <WiFiClient.h>
  32. #include <ESP8266WebServer.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /****** GLOBAL VARIABLES *****/
  39. const char* ssid = "your_SSID";     // Replace with your network SSID
  40. const char* password = "your_PASSWORD"; // Replace with your network password
  41.  
  42. ESP8266WebServer server(80); // Create a web server on port 80
  43.  
  44. void handleRoot() {
  45.     server.send(200, "text/plain", "Hello, this is your ESP8266 server!");
  46. }
  47.  
  48. void setup(void)
  49. {
  50.     // Initialize Serial for debugging
  51.     Serial.begin(115200);
  52.    
  53.     // Connect to Wi-Fi
  54.     WiFi.begin(ssid, password);
  55.     while (WiFi.status() != WL_CONNECTED) {
  56.         delay(500);
  57.         Serial.print(".");
  58.     }
  59.     Serial.println("Connected to Wi-Fi");
  60.  
  61.     // Define the root URL handler
  62.     server.on("/", handleRoot);
  63.  
  64.     // Start the server
  65.     server.begin();
  66.     Serial.println("HTTP server started");
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // Handle client requests
  72.     server.handleClient();
  73. }
  74.  
  75. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement