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: **Web Server**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-11-16 14:40:10
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* The system shall utilize the Sim800L module for */
- /* GSM communication, ensuring reliable data */
- /* transmission and reception via SoftwareSerial on */
- /* specified pins. It must handle reset and DTR */
- /* signals effectively for optimal performance. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SoftwareSerial.h> //https://github.com/plerup/espsoftwareserial
- #include <Sim800L.h> //https://github.com/vittorioexp/Sim800L-Arduino-Library-revised
- #include <forcedBMX280.h> //https://github.com/soylentOrange/Forced-BMX280
- #include <WiFi.h> // Include WiFi library for ESP32
- #include <WebServer.h> // Include WebServer library for handling HTTP requests
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void handleRoot(); // Function to handle root URL
- void handleLogin(); // Function to handle login
- void handleSignup(); // Function to handle signup
- void handleProfile(); // Function to handle profile page
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Ny_SIM800L_RING_PIN_RX2 = RX2;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Ny_SIM800L_RST_PIN_D14 = 14;
- const uint8_t Ny_SIM800L_DTR_PIN_TX2 = TX2;
- /***** DEFINITION OF Software Serial *****/
- const uint8_t Ny_SIM800L_Serial_PIN_SERIAL_TX_D4 = 4;
- const uint8_t Ny_SIM800L_Serial_PIN_SERIAL_RX_D13 = 13;
- SoftwareSerial Ny_SIM800L_Serial(Ny_SIM800L_Serial_PIN_SERIAL_RX_D13, Ny_SIM800L_Serial_PIN_SERIAL_TX_D4);
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool Ny_SIM800L_RST_PIN_D14_rawData = 0;
- bool Ny_SIM800L_DTR_PIN_TX2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float Ny_SIM800L_RST_PIN_D14_phyData = 0.0;
- float Ny_SIM800L_DTR_PIN_TX2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Initialize the web server on port 80
- WebServer server(80);
- Sim800L sim800l(Ny_SIM800L_Serial_PIN_SERIAL_RX_D13, Ny_SIM800L_Serial_PIN_SERIAL_TX_D4, Ny_SIM800L_RST_PIN_D14); // Instantiate Sim800L object
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(Ny_SIM800L_RING_PIN_RX2, INPUT_PULLUP);
- pinMode(Ny_SIM800L_RST_PIN_D14, OUTPUT);
- pinMode(Ny_SIM800L_DTR_PIN_TX2, OUTPUT);
- // Initialize Software Serial for SIM800L
- Ny_SIM800L_Serial.begin(9600);
- // Initialize SIM800L
- sim800l.begin(9600); // Set baud rate for SIM800L
- // Start WiFi connection
- WiFi.begin("YOUR_SSID", "YOUR_PASSWORD"); // Replace with your WiFi credentials
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- }
- // Define routes
- server.on("/", handleRoot);
- server.on("/login", handleLogin);
- server.on("/signup", handleSignup);
- server.on("/profile", handleProfile);
- // Start server
- server.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- server.handleClient(); // Handle incoming client requests
- }
- void updateOutputs()
- {
- digitalWrite(Ny_SIM800L_RST_PIN_D14, Ny_SIM800L_RST_PIN_D14_rawData);
- digitalWrite(Ny_SIM800L_DTR_PIN_TX2, Ny_SIM800L_DTR_PIN_TX2_rawData);
- }
- void handleRoot() {
- // Serve the login page
- server.send(200, "text/html", R"rawliteral(
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>WeEarnZA - Get Started</title>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <div class="logo"></div>
- <div class="container">
- <div class="partText">Participate and Earn</div>
- <div class="loginText">Login</div>
- <div class="fields">
- <div class="username"><input type="text" class="user-input" placeholder="Username:"></div>
- <div class="password"><input type="password" class="pass-input" placeholder="Password:"></div>
- </div>
- <button class="signin-button" onclick="location.href='/login'">Sign IN</button>
- <div class="link"><a href="/signup">Sign Up</a></div>
- </div>
- <div class="bottom"></div>
- </body>
- </html>
- )rawliteral");
- }
- void handleLogin() {
- // Here you would implement the login logic
- // For now, just redirect to the profile page
- server.sendHeader("Location", "/profile");
- server.send(303); // 303 See Other
- }
- void handleSignup() {
- // Serve the signup page (similar to login)
- server.send(200, "text/html", R"rawliteral(
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Sign Up</title>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <div class="container">
- <div class="signupText">Sign Up</div>
- <div class="fields">
- <div class="username"><input type="text" class="user-input" placeholder="Username:"></div>
- <div class="password"><input type="password" class="pass-input" placeholder="Password:"></div>
- </div>
- <button class="signup-button">Sign Up</button>
- <div class="link"><a href="/">Back to Login</a></div>
- </div>
- </body>
- </html>
- )rawliteral");
- }
- void handleProfile() {
- // Serve the profile page
- server.send(200, "text/html", R"rawliteral(
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Profile</title>
- <link rel="stylesheet" href="styles.css">
- </head>
- <body>
- <div class="container">
- <div class="profileText">User Profile</div>
- <div class="fields">
- <div class="username">Username: [Username]</div>
- <div class="balance">Balance: R88.00</div>
- </div>
- <div class="link"><a href="/">Logout</a></div>
- </div>
- </body>
- </html>
- )rawliteral");
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement