cover photo

BLOG · 13/4/2023

Common Task Report Part-2

Puneeth Jayaram, Batch-3, AI & ML 2nd year.

Puneeth
Puneeth
OP
 Common Task Report Part-2
This Article is yet to be approved by a Coordinator.

Common Tasks Final Report Part-2\n---\n## ESP32\n\nAim : Creating a standalone web server with an ESP32 that\ncontrols the LED connected with ESP32 GPIOs.\n\nComponents Required :\n\n1. ESP32 development board\n2. 2x 5mm LED\n3. 2x 330 Ohm Resistor\n4. Breadboard\n5. Jumper Wires\n\nProcedure :\n\n1.Connect two LEDs to the ESP32 one LED connected to GPIO 26, and the other to GPIO 27.\n2.To make the ESP32 webserver the following code is put in the Arduino IDE.\nJava\n// Load Wi-Fi library\n#include \n\n// Replace with your network credentials\nconst char* ssid = \vvvvvvxxxxxx\";\nconst char* password = vvvvvvxxxxxx\";\n\n// Set web server port number to 80\nWiFiServer server(80);\n\n// Variable to store the HTTP request\nString header;\n\n// Auxiliar variables to store the current output state\nString output26State = \"off\";\nString output27State = \"off\";\n\n// Assign output variables to GPIO pins\nconst int output26 = 26;\nconst int output27 = 27;\n\n// Current time\nunsigned long currentTime = millis();\n// Previous time\nunsigned long previousTime = 0; \n// Define timeout time in milliseconds (example: 2000ms = 2s)\nconst long timeoutTime = 2000;\n\nvoid setup() {\n Serial.begin(115200);\n // Initialize the output variables as outputs\n pinMode(output26, OUTPUT);\n pinMode(output27, OUTPUT);\n // Set outputs to LOW\n digitalWrite(output26, LOW);\n digitalWrite(output27, LOW);\n\n // Connect to Wi-Fi network with SSID and password\n Serial.print(\"Connecting to \");\n Serial.println(ssid);\n WiFi.begin(ssid, password);\n while (WiFi.status() != WL_CONNECTED) {\n delay(500);\n Serial.print(\".\");\n }\n // Print local IP address and start web server\n Serial.println(\"\");\n Serial.println(\"WiFi connected.\");\n Serial.println(\"IP address: \");\n Serial.println(WiFi.localIP());\n server.begin();\n}\n\nvoid loop(){\n WiFiClient client = server.available(); // Listen for incoming clients\n\n if (client) { // If a new client connect \n currentTime = millis();\n previousTime = currentTime;\n Serial.println(\"New Client.\"); // print a message out in the serial port\n String currentLine = \"\"; // make a String to hold incoming data from the client\n while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client\'s connected\n currentTime = millis();\n if (client.available()) { // if there\'s bytes to read from the clien \n char c = client.read(); // read a byte, then\n Serial.write(c); // print it out the serial monitor\n header += c;\n if (c == \'\\n\') { // if the byte is a newline character\n // if the current line is blank, you got two newline characters in a row.\n // that\'s the end of the client HTTP request, so send a response:\n if (currentLine.length() == 0) {\n // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)\n // and a content-type so the client knows what\'s coming, then a blank line:\n client.println(\"HTTP/1.1 200 OK\");\n client.println(\"Content-type:text/html\");\n client.println(\"Connection: close\");\n client.println();\n \n // turns the GPIOs on and off\n if (header.indexOf(\"GET /26/on\") >= 0) {\n Serial.println(\"GPIO 26 on\");\n output26State = \"on\";\n digitalWrite(output26, HIGH);\n } else if (header.indexOf(\"GET /26/off\") >= 0) {\n Serial.println(\"GPIO 26 off\");\n output26State = \"off\";\n digitalWrite(output26, LOW);\n } else if (header.indexOf(\"GET /27/on\") >= 0) {\n Serial.println(\"GPIO 27 on\");\n output27State = \"on\";\n digitalWrite(output27, HIGH);\n } else if (header.indexOf(\"GET /27/off\") >= 0) {\n Serial.println(\"GPIO 27 off\");\n output27State = \"off\";\n digitalWrite(output27, LOW);\n }\n \n // Display the HTML web page\n client.println(\"\");\n client.println(\"\");\n client.println(\"\");\n // CSS to style the on/off buttons \n // Feel free to change the background-color and font-size attributes to fit your preferences\n client.println(\"\");\n \n // Web Page Heading\n client.println(\"ESP32 Web Server\");\n \n // Display current state, and ON/OFF buttons for GPIO 26 \n client.println(\"GPIO 26 - State \" + output26State + \"\");\n // If the output26State is off, it displays the ON button \n if (output26State==\"off\") {\n client.println(\"ON\");\n } else {\n client.println(\"OFF\");\n } \n \n // Display current state, and ON/OFF buttons for GPIO 27 \n client.println(\"GPIO 27 - State \" + output27State + \"\");\n // If the output27State is off, it displays the ON button \n if (output27State==\"off\") {\n client.println(\"ON\");\n } else {\n client.println(\"OFF\");\n }\n client.println(\"\");\n \n // The HTTP response ends with another blank line\n client.println();\n // Break out of the while loop\n break;\n } else { // if you got a newline, then clear currentLine\n currentLine = \"\";\n }\n } else if (c != \'\\r\') { // if you got anything else but a carriage return characte \n currentLine += c; // add it to the end of the currentLine\n }\n }\n }\n // Clear the header variable\n header = \"\";\n // Close the connection\n client.stop();\n Serial.println(\"Client disconnected.\");\n Serial.println(\"\");\n }\n}\n\n\n3.ESP IP address is found in the serial monitor in the IDE.\n\n4.This IP address is pasted on the web browser to access the web server. Now we can control the LED.\n\n\n\n\n\n---\n\n## Github\n\n GitHub is a tool that allows you to automate your workflow by creating custom workflows that can be triggered by events such as push, pull request, issue creation, etc. Issues are used to track bugs, feature requests, and other tasks related to your project. Pull requests are used to propose changes to a repository.\n\n In this task, I opened a pull request in the repository and fixed the code.\n\n\n\n\n\n---\n\n## 3D Printing\n\n3D printing is a process of creating three-dimensional objects from a digital file using a printer that lays down successive layers of material until the object is created.\n\nAn STL file stores information about the 3D model and represents the raw surface of a model with small triangles. More complex the strcuture, the more triangles.\n\nSlicing an STL file involves breaking it down into layers and generating a toolpath for each layer. This toolpath is then used by the 3D printer to create the object layer by layer. Software such as ultimaker or creality slicer is used for slicing.\n\n 3D Model \n\n \n\n This is my 3D model. I downloaded a stl file, sliced it, and printed it.\n\n ---\n\n\n ## Active Participation\n\nI took part in events such as Escape The Crash and AR Wizards which was recently organised by IEEE UVCE.\n\n\n\n---\n\n## API\n\n1.API stands for Application Programming Interface. It is a set of protocols, routines, and tools for building software applications.\n\n2.I made a user web interface using weather API.\n\n\n\n---\n \n"

UVCE,
K. R Circle,
Bengaluru 01