Tips for extracting information from an HTML input and saving it to a local file for later use

Currently, I am in the process of learning about ESP32 and have set myself a project with various objectives:

  • Successfully setting up ESP32 as a softAP - COMPLETED
  • Establishing access to ESP32 via WiFi - COMPLETED
  • Serving an HTML authentication form (index1.html) stored within the flash memory of the ESP32 to request nearby Wireless Network's SSID and Password - COMPLETED
  • Entering the credentials mentioned above, clicking on a Log-In button, and connecting the ESP32 to the specified Wireless Network
  • Navigating to a different webpage (index2.html) also located inside the flash memory of the ESP32

Below are the hardware specifications being used for this project:

Board: ESP32 DEVKIT1

Core Installation version: 1.0.1-git link here

IDE name: Arduino IDE

Flash Frequency: 80Mhz

PSRAM enabled: no

Upload Speed: 115200

Computer OS: Linux Mint 19.1 Mate

Although I have conducted thorough research, I have been unable to find applicable information related to my project, hence the creation of this post.

Due to unfamiliarity with posting code correctly (following guidelines found here), I have created gists for reference. Hopefully, they prove useful.

index.html

Link to index.html gist

login.css

Link to login.css gist

Arduino IDE Sketch

Link to Arduino IDE Sketch gist

My next objective is to input SSID and Password into their respective fields, click on the "Sign in" button, store these details in a read-only file within the Flash Memory of the ESP32, establish connection to the specified Wireless Network, and serve another webpage from the Flash Memory.

I have not mentioned the use of JavaScript or PhP as I am unsure which one would be suitable or if they can function in this manner.

Alternatively, instead of a read-only file, could there be a small database storing limited Wireless Networks?

Thank you! Apologies for the lengthy post.

Answer №1

While I don't have experience with the ESP32 or web services on microcontrollers, my primary work involves writing web services and applications.

If you want to store username and password values by submitting an HTTP request to a separate endpoint, JavaScript can help you achieve this. However, it's worth noting that HTML already has built-in support for forms.

Your current input tags are suitable for working with forms. All you need to do is wrap them in a form element that specifies how to encode and transfer the form values, as well as where to send them. The browser will handle the rest when the submit button is clicked:

<body>
    <div class="login-box">
        <form method="post" action="/login">
            <div class = "box-head">
                <div class = "logo"><img url="logo.png"></div>
                <div class = "network-title"><h1>Network Login</h1></div>
            </div>
            <div class ="textbox">            
                <input type="text" placeholder="Network Name" name="networkName" value="">
            </div>        
            <div class="textbox">            
                <input type="password" placeholder="Password" name="networkPassword" value="">
            </div>        
            <input class="button" type="submit" value="Sign in">
            <input class="button" type="reset" value="Restart">        
        </form>
    </div>    
</body>

This setup would trigger an HTTP POST request to the /login endpoint, containing the form values encoded as

application/x-www-form-urlencoded
.

In this scenario, PHP isn't necessary to handle the request since your logic resides within the AsyncWebServer object in your sketch which acts as the HTTP server.

AsyncWebServerRequest can easily extract form values, simplifying the process of handling form submissions on your server:

server.on("/login", HTTP_POST, [](AsyncWebServerRequest *request) {
  if (!request->hasParam("networkName", true) || !request->hasParam("networkPassword", true)) {
    request->send(400, "Missing fields");
    return;
  }
  const char *networkName = request->getParam("networkName")->value().c_str();
  const char *networkPassword = request->getParam("networkPassword")->value().c_str();
  // Process networkName and networkPassword
  // ...
  // Redirect to another page
  request->redirect("/whatever");
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: 'require is not defined' pops up while trying to import into App.js for a React App built with CDN links

My latest project involves a React App that showcases an h1 tag saying "Hello World" on the browser. Rather than utilizing npm, I have opted for CDN links to set up the application. The structure of the App consists of three key files: An index.html file ...

Tips for ensuring HTML5 <video> compatibility with CSP in Google Chrome

When I implement an HTML5 video element on my website with a strict Content-Security-Policy directive (default-src 'self'), I encounter an error in the Google Chrome console upon loading a page for the first time. The error message states: [Repo ...

Extracting particular data from various XML documents and displaying it on an HTML webpage

Imagine a scenario where there is an HTML page displaying TV listings in a table format, populated by XML data. The goal is to allow users to click on any program title and view its description, which also comes from the same XML file. Past attempts using ...

Refresh your textarea content using the replace method in jQuery

My goal is to extract and manipulate specific values within a user-entered code using jQuery. The code includes custom tags called setting, which I want to extract and display in input fields for easy editing. I have successfully retrieved and displayed th ...

What could be the reason my dropdown menu is not appearing on hover?

Currently, I am in the process of developing a menu using angularJS and google app script within a dialog box. I have been referring to this sample code for guidance. Instead of pasting all my code here, I can summarize what I have come up with: var a ...

Issues arise with HTML and CSS when users begin to scroll the page

Could really use some assistance here! I created this website for a friend, but the color of the menu bar mysteriously disappears when I scroll to the right. Any suggestions or ideas on how to fix this issue would be greatly appreciated. The site in quest ...

Unexpected issue encountered for identifiers beginning with a numerical digit

Is it possible to select an element from a page with an id that begins with a number? $('#3|assets_main|ast_module|start-iso-date') Upon attempting to do so, the following error occurs: Uncaught Error: Syntax error, unrecognized expression: ...

``There seems to be an issue with disapplying a CSS class using JavaScript

I've designed a website that appears to have multiple pages, but in reality, all the content is contained within one HTML file: index.html. Using javascript and CSS, I have divided the site into a "home" position and an "inside" position similar to a ...

The HTML link is not functioning properly. I included the code "<a href="fileName"></a>" but the link is not working

My hyperlink isn't functioning properly in my HTML code, and I can't determine the reason why. <div class="banner-text"> <ul> <li><h3><a href="chawla.html">HOME</a></h ...

Using jQuery to choose options and change the background color

Hey there, I have a select box below: <select id="events"> <option value="1" style="background-color:green;">Event 1</option> <option value="2" style="background-color:yellow;">Event 2</option> <option value="3 ...

Update: "Mui V5 - Eliminate collapse/expand icons in TreeView and reduce TreeItem indentation"

My current project involves Mui V5 and I am looking to customize the TreeView component. Specifically, I need to remove the collapse/expand icons as I want them to be integrated into the TreeItem label component on the left side instead of the right. Add ...

Ways to activate side-to-side scrolling?

Here on this specific page, I am looking to showcase the SPECIAL and RECOMMENDED sections together in a single line with horizontal scrolling. This is my current CSS: .box-product { width: 100%; overflow: auto; } I have attempted implementing it like th ...

Assigning attributes to each letter in a pangram

I am attempting to assign the appropriate class to a group of elements, representing each letter in the alphabet. The elements have IDs ranging from #alpha_0 to #alpha_25. If a letter appears just once in the input, it should be displayed in green. If a le ...

Leverage the calc() function within the makeStyles method

const useStyles = makeStyles((theme) => ({ dialog: { '& .MuiTextField-root': { margin: theme.spacing(1), } }, address: { width:"calc(24vw + 8px)" }, })); <div> <TextField id="contact ...

The react boolean attribute is malfunctioning and the video is not playing automatically

I have a React component with a <video> element that includes the autoplay attribute. <video autoplay muted src="/vids/vid.mp4"> However, it does not work as expected. Interestingly, when I set autoplay="true", it starts wo ...

Moving the element from the right side

Is there a way to change the direction of this element's transition from left to right, so that it transitions from right to left smoothly without any gaps between the element and the edge of the page? @keyframes slideInFromRight { 0% { trans ...

Creating a website with a seamless image background that fills the entire page

! Is it possible to achieve the same effect using AngularJS? Below is the CSS code: .bg { background: url(holiday-car-rental.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-s ...

The index.html file seems to be missing from the website's current files

I recently bought a Wordpress web template and hired a designer to work on it before uploading it to the site. Now, I want to make some modifications to the site myself. However, despite downloading all the files, I can't seem to locate any folders w ...

Suggestion for a script that graphs in PHP

Searching for a user-friendly PHP-based graphing script that can generate image-based charts for e-mailing or printing purposes. Looking into PHPGraphLib, but open to other recommendations, whether commercial or GNU. Flash-based solutions are not suitabl ...

Having an issue where the Jquery clone function is only duplicating the content once. Looking to

I'm currently working on existing HTML table code. My goal is to copy the text from the 'th' header rows and paste them inside the corresponding td cells for each subsequent row. While I have successfully managed to copy the header row, it o ...