Create Webserver with ESP8266 using SPIFFS

Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at How to Create Web Server with ESP8266 using SPIFFS.

We've already seen how to create a web server and how to provide an HTML page on our ESP8266. We use the PROGMEM command to store an HTML code in FLASH memory. For a simple page, this works fine, but what if we have a more complex webpage? With a better style? What if we want to include images?

Today we will learn how to use SPIFFS with ESP8266 to store files (regardless of type) in FLASH memory.

Where To Buy?
No.ComponentsDistributorLink To Buy
1ESP8266AmazonBuy Now

What is SPIFFS?

  • SPIFFS (SPI Flash File System) is a system designed for managing SPI flash memory in embedded devices. Its main goal is to use minimal RAM to access files. It's very useful when using pen drives, memory cards, and the ESP8266's flash memory.
  • SPIFFS allows you to access files (create, read, write, delete) just like on a computer. But with a much simpler folder structure.
  • To show how the tool works, we will create a web server with a styled page and an image. Then when accessing the webserver, the browser will receive the HTML file, the CSS file, and the images.

Create Webserver with ESP8266 using SPIFFS

  • For that, we will need two things:
    • Library to manage SPIFFS.
    • Tool to load the files in FLASH.
  • The upload tool is a plugin called ESP8266fs that integrates python into the Arduino IDE.
  • Download the ESP8266FS-0,5.0.zip file from Github and unzip the files into Arduino's tools folder ( Possibly C:\program files x86\arduino \tools).
  • Restart Arduino IDE and the tool should appear available as shown in the image.
  • Now let's take a look at how it works.
  • Your sketch will always be saved inside a folder. The Arduino IDE cannot open an .INO file if it is not inside a folder with the same name.
  • Our upload tool will look inside that folder and look for another folder called “data”. Everything inside that folder will be transferred to the ESP8266's FLASH memory.

Our page will have 3 main objects:

  • An image that will change depending on the status of the LED.
  • A text with the status of the LED.
  • A button to change the status of the LED.

Files on Webserver

And to build this page we will use 4 files:

  • html, which will contain the page itself.
  • css, containing the styling to make the page more beautiful.
  • Image of the lamp
  • Image of the lamp
  • The two images were chosen from the pixabay repository. You can use another one. But I recommend not using very large files as it takes a little longer to load. I also recommend using some service to resize the image, such as tinypng.
  • In our index.html file, we will have:
  • In our style.css file, we will have:

Understanding ESP8266 Webserver Code

  • Created and saved, we used ESP8266 Sketch Data Upload to load the file into FLASH memory.
  • Before we look at the code, it's important to understand how the browser behaves when accessing a page.
  • When accessing the web server address, the browser sends an HTTP GET command in the path “/” and waits for an index file in response.
  • Inside index file it can be informed that it needs other files. What happens in our code.
  • In line 7 of the index.html file, it is informed that the style.css file will also be needed and that it is of type text/css.
  • Then the browser sends another HTTP GET command with the path “/style.css” and expects to receive a file with that name.
  • In line 13, the <img> tag informs the path to an image, and the browser sends another HTTP GET command to the address “/bulb-off.png”, this time the browser expects an image file.
  • The browser will send GET commands each time we click the Toggle button (“/toggle” path) and every 1 second to receive an updated status (“/state” path).
  • Doing yet another GET to the lit lamp image (path: “/bulb-on.png”).

So we will need to handle it in our .INO code the GET requests in the paths:

  • “/”
  • “/style.css”
  • “/bulb-off.png”
  • “/bulb-on.png”
  • “/toggle”
  • “/state”

Our style.css file sets sizes, alignments, and colors for components. We start our .INO file by importing four libraries:

  • h – That will take care of our WiFi connection.
  • h and ESPAsyncWebServer.h – Which will manage the webserver (including HTTP GET commands).
  • h – File System Library that will take care of our SPIFFS.

We define the pin for our LED. We create variables with SSID and password of the wifi network where we will connect. We created our server on port 80 and a variable to monitor the LED status.

  • The wifiConnect() function will connect the ESP8266 to the chosen wifi network by printing the IP address on the serial monitor.
  • Pay attention to this number. You will need to access the webserver from the browser.
  • The processor() function is responsible for updating the variable with the status of the LED.
  • We will use it in handling our GETs.
  • The toggleLed() function toggles the LED state. We will use it in the GET “/toggle”.
  • And finally, our setup() function. We start by setting our LED to OUTPUT (otherwise, our toggle won't work.
  • Next, we start Serial with a baud rate of 115200 to view the IP address on the Serial Monitor.
  • With SPIFFS.begin(), we initialize our filesystem in flash memory.
  • If an error occurs, our code stops here and reports on Serial Monitor. In that case, upload the files again.
  • And finally, we've included our GETs.

The “server.on” structure is an event manager provided by the ESPAsyncWebServer.h library. In short, we inform a route, a method (HTTP-GET, for our case), and action when receiving the request. But we need to take a closer look at some variations of the function.

  • The server receives a request for the “/” route with the HTTP GET method.
  • In request->send, we inform that the response is a SPIFFS file with the name index.html and that it will be sent in string format.
  • The last two fields (“false” and “processor”) inform that the index.html file is a template that depends on more information. This information will be provided by the processor() function.

It is necessary to send the index file with the updated LED state value.

For style files and images, we use a similar principle, but these files are not being changed before they are uploaded. So we only inform the origin, name, and type (if you want to know a little more about file types in HTTP, I recommend a study on MIME TYPES. Any type of file can be sent, but MIME standardizes what browsers can understand).

Lastly, we have the “/state” returning the stateValue variable on each update and the “/toggle” which changes the state before sending the same variable. The response format has a small change. As we are sending only one variable, we inform the MIME TYPE “text/plain”, the response code 200 (default for success over HTTP), and the variable converted to a string.

Results

  • With the code compiled and recorded, check the IP of the webserver in the Serial Monitor and access it in the browser.
  • Example: for IP: 10.10.10.11 access: http://10.10.10.11.
  • Attention: As we use port 80 on the web server, we use HTTP and not HTTPS. The result on the screen should look like the images below:

So that was all for today. I hope you have enjoyed today's lecture because it will improve the presentation of your project. If you got any queries, ask in the comments. Thanks for reading!!!

Create Web Server with ESP8266

Hello friends, I hope you all are doing great. Today, we will create a web server with ESP8266 microcontroller to control the activation of an LED. The goal is to understand how the ESP8266 connects to a WiFi network, how it sets up a web server, and how it is possible to exchange information between the browser and the esp8266.

Where To Buy?
No.ComponentsDistributorLink To Buy
1ESP8266AmazonBuy Now

Components Required

  • 1x Computer/notebook with Arduino
  • 1x Mini-USB cable.
  • 1x NodeMCU (ESP8266 Breakout Board)
  • Internet Browser (Chrome, Firefox, IE…)

ESP8266 Libraries for Arduino IDE

For this project, we will use two libraries:

  • ESP8266WiFi: This library carries all the functions necessary for the ESP8266 to connect to a wifi network.
  • ESPAsyncWebServer: This library carries the functions needed to create and manage an EB server.

Creating the code

  • We can divide the code into three main functionalities:
    1. Control the LED.
    2. Connect to Wifi
    3. Create the webserver.

And we'll treat this building in blocks.

Importing Libraries

  • The Libraries must be included at the beginning of the sketch so that their functions are already available elsewhere in the code.

LED Control with ESP8266

  • Our first step is to define the pin to be used. For our example, we will use the LED of the NodeMCU module.
  • And set this pin as output in the setup function.
  • We will also create a variable to monitor LED status. This variable is not used to control the LED, but it will be important for the webserver so, we will include it here.
  • So, we'll create a function that, whenever triggered, will change the state of the LED (and the variable).
  • The toggleLed() function makes a function nesting in its first line:
  • The digitalWrite() function receives as a value for writing, the inverse of the reading of the pin itself. So each time the function is called, it reads the current value of the pin and toggles its value.
  • The following conditional is only used to update the stateValue variable. To test the function, you can include it in the loop as follows:
  • With these inclusions, we will have this code:
  • With this code, the NodeMCU module LED, we expect to change state every 3 seconds. Remember to remove the data inside the loop function when you finish the test. We will not use them in the next steps.

Connect ESP8266 to WIFI

  • Now let's connect the ESP8266 to your WIFI network. We'll start by creating a variable to store the network name and another one for the password.
  • The connection could be executed directly in the setup function, but we will create a standalone function to make the code more organized and so that it can be reused if you want to create a reconnect function.

The wifiConnect() function will send a connection request and wait for it to be approved.

With Wifi.begin(), ESP8266 will search the network informed in the ssid variable and send a connection request, informing the password (just like what a cell phone would do).

The WiFi.status() function can return the following values:

  • WL_CONNECTED: assigned when connected to a WiFi network;
  • WL_NO_SHIELD: assigned when no WiFi shield is present;
  • WL_IDLE_STATUS: it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED);
  • WL_NO_SSID_AVAIL: assigned when no SSID are available;
  • WL_SCAN_COMPLETED: assigned when the scan networks is completed;
  • WL_CONNECT_FAILED: assigned when the connection fails for all the attempts;
  • WL_CONNECTION_LOST: assigned when the connection is lost;
  • WL_DISCONNECTED: assigned when disconnected from a network;

In this project, we are not handling connection failures, so we are only interested in the WL_CONNECTED return. The function will wait while this is not the connection status and, when identifying it, it will look for the IP address it received on the network.

Here is a point of attention. The WIFI network must allow the connection and provide an IP by DHCP. If any device can connect to your network just by offering the password, don't worry. This configuration must already exist.

We've added some information to be viewed on the Serial monitor, so the serial needs to be initialized before we call the wifiConnect() function.

  • This should be our code so far:
  • The expected result on the Serial Monitor is as follows:
  • From this point on, the ESP8266 can be found by network tools like the Advanced IP Scanner or a simple PING at the command prompt.

Creating the Webserver with ESP8266

  • Spoiler Alert: At the end of this step, you can view our webserver at the address
  • HTTP://”IP address”, for our case http://192.168.18.76.
  • We will start by creating an instance of AsyncWebServer operating on port 80.
  • In short, a webserver operates as a file manager that delivers on-demand. Then the browser makes a request, the web server responds and continues to wait for new requests.
  • All this happens following communication protocols (HTTP, FTTP, or both), rigorous error handling, and high-security logic.
  • The library takes care of preparing the backstage of the webserver, which saves us a lot of time and lines of code. But we still need to configure what happens on each request.

We will handle two requests:

  • When the page starts or refreshes
  • When we press the LED state change

The first will occur when we send a GET request to the root “/”. What the browser does automatically when we go to http://192.168.18.76.

  • The server will respond with status 200 (default success response), the information on the type of file sent ("text/html"), the HTML file (which we will create next and save in the variable index_html), and the return of the processor( ) (which we will also create now).
  • The processor function simply returns the value of the updated stateValue variable.
  • The HTML file the browser expects tends to be large for a variable, and even with the good SRAM memory space the ESP8266 has, it could cause problems.
  • That's why we'll use the PROGMEM utility so that the variable is written to FLASH memory.
 
  • Don't worry if you don't know HTML or javascript. We won't go into details, but we'll explain the most important ones for now.
  • On line 23, the page displays the value returned by the processor() function.
  • In line 24, the button calls the “toggleLED()” function when activated.
  • The toggleLED() function makes a GET request at address “/state” passing the toggle valceue.
  • After 1 second it refreshes the page to receive the updated value. We need to handle this request:
  • When the server receives the request at the address “/state” it calls the toggleLed() function
  • and just replies to the server that everything went fine. And last but not least: We started the server:
  • This will be our final code:
  • In our browser:

Conclusion

In this project, we saw a very simple application of the power that the ESP8266 WiFi has. In the HTML file, page styling could also be included to make the page prettier.

And with that base, it's possible to expand into several cool projects. A temperature monitor via Wifi? Security systems? Home automation systems? These are just a few examples. The limit is up to your creativity.

How to Become a Licensed Residential Architect?

Designing homes and landscapes is a dream job for many individuals, but the challenges of becoming a licensed architect often stand in the way of this dream. To become a licensed architect, you’ll need to be willing to put in a lot of hard work throughout the education and apprenticeship stages of certification and study extensively for the ARE accreditation exam. Once certified, many individuals choose to work for a residential architectural firm to design custom homes and assist with planning remodeling projects.

There are many education and experience requirements involved with qualifying for the ARE exam and becoming a residential architect. In this article, we’ll go over the details for each of these requirements and answer some of your questions regarding this profession. To successfully complete these requirements and receive accreditation, prospective architects will need dedication, attention to detail, and advanced problem-solving skills.

What Does a Residential Architect Do?

A residential architect plans and designs buildings that will serve as residences. The assistance of a residential architect is a necessity for building new homes, condominiums, and apartment buildings. Individuals interested in custom homes will often consult with a residential architect directly, to discuss how their new space will accommodate their needs and lifestyle.  However, the property owner or construction company will reach out to or directly hire a residential architect for many projects. Most residential architects work with a team in a firm or dedicated office within a construction company.

What Level of Salary is Available as an Architect?

Becoming a licensed architect requires many years of experience and education, which means architects are generally in frequent demand. According to learn.org, the median salary for residential architects is approximately $80,000 a year. This salary varies based on the hiring company and the type of consultation for which the architect is available. Many architects are self-employed therefore will have a fluctuating yearly income.

What Skills Do I Need To Work as an Architect?

Drawing and CADD (Computer-Aided Drawing and Drafting) are essential technical skills for working as an architect. However, a considerable portion of this career lies away from the drafting table. Meeting with clients and project managers is essential throughout the lifespan of a project and so requires strong interpersonal and communication skills. Many architects also spend a great deal of time traveling to project sites and overseeing construction or meeting with vendors.

Education Requirements

Beginning a career in architecture requires completing a bachelor’s or master’s degree in architecture accredited by the NAAB (National Architectural Accrediting Board). There are many degree programs available through liberal arts and design schools that are notably not accredited- it’s important to check in with the university or school to ask about their accreditation beforehand. The educational institution hosting the degree must maintain its NAAB certification throughout the duration of your studies.

Accredited bachelor’s degree programs typically span five years and cover all aspects of project management, environmental planning, and design technology. Throughout these programs, students will assemble portfolios and present projects for professional review to showcase their work. Architecture master’s degree programs cover many of the same topics as the bachelor’s degree and work well for students who picked a different undergraduate major. However, many architecture bachelor’s degree students will choose to take on the master’s degree in addition to their prior education.

Students wishing to proceed with a career in architecture will ultimately need to complete either the accredited bachelor’s degree program or the accredited master’s degree program. Doctorate-level studies are available but focus more on the academic field associated with architecture rather than the licensing process.

Experience Requirements

After completing the educational requirements associated with becoming a licensed architect, you’ll need to gather architectural experience through NCARB (National Council of Architectural Registration Boards). The NCARB organizes a program called the AXP, which stands for Architectural Experience Program.

The AXP targets a number of specific proficiencies (96, to be exact) and requires a total of 3,740 hours across all disciplines. The experience component of earning your architectural license will take, at a minimum, around two years. Previously, this hours requirement was much higher- 5,600 hours were required through the IDP (Intern Development Program), which typically needed an extra year or two of work to complete.

Architects will need to log their hours for the experience component according to specific AXP guidelines. Non-licensed architects can bypass part of this component with a portfolio displaying architectural competencies across the 96 AXP task areas. You can read more about AXP guidelines here. The experience required for an architectural license is essentially an apprenticeship or internship that will give candidates a look into how architectural firms and offices operate.

Exam Requirements

Once a licensed architect candidate has completed an accredited education program and the AXP experience requirements, they will be eligible to take the ARE (Architect Registration Examination). The exam is divided into six parts, each of which focuses on a specific architectural discipline. These exam portions are as follows: Practice Management, Project Management, Programming and Analysis, Project Planning and Design, Project Development and Documentation, and Construction and Evaluation.

Prospective candidates for licensure will need to study extensively for several months before the exam, which typically occurs in the fall. Many architects will need to take the exam several times, though it is important to know that each full exam attempt currently costs around $1500. Examination is the final step in becoming an officially licensed architect. You will need to renew your license every few years, though you won’t need to take the ARE again once you’ve passed.

Conclusion

Becoming a licensed architect requires many years of hard work and determination but can lead to a fulfilling career with many opportunities to build residential and commercial spaces. The residential architecture field is growing steadily as many cities and urban areas expand to accommodate a growing population. To learn more about this field of work, speak with an experienced residential architect today and ask about their journey towards designing homes and commercial spaces.

Do You Need a Dedicated Server? 

If you’re hosting a website, eCommerce business, or even just the latest online game with your friends, you know that performance, reliability, and security matter. To take your web hosting to the next level, consider what a dedicated server could do for you. With full access to your own web server, you’ll have more control and better performance from your hosting service. What’s not to love about that?

But how do you know when you really need a dedicated server? Many smaller websites can perform just fine without one, but for larger sites and businesses, the benefits quickly become apparent. Here, we’re taking a closer look at dedicated servers and what they can offer for your online experience. We provide some key information about dedicated servers to help you determine if you need one for your hosting.

What is a Dedicated Server?

If you’ve just started a website or an eCommerce company, you probably went with a cheaper web hosting option. This just makes sense. For smaller websites and online businesses, you most likely don’t need the power and capabilities of a dedicated server or the more costly hosting options out there. However, as your site grows in terms of traffic, bandwidth, and storage requirements, you may find that your previous hosting methods simply aren’t cutting it anymore for what you need.

This is when you should look into a dedicated server. When you’re hosted from a dedicated server, this essentially means that you have an entire server to yourself, enabling you to take advantage of the server’s full capacities and power. At this point, some might opt for a virtual private server (VPS). A VPS is still an upgrade from a shared server, but it doesn’t give you your own server. Rather, a VPS provides you exclusive space on a server that may still be shared with other web owners. While this option may come at a cheaper cost, it simply can’t match the benefits, security, and full capability of having your own dedicated server.

Benefits of a Dedicated Server

In comparison to traditional hosting options, there are quite a few benefits to hosting your site, eCommerce business, or online gaming experience from a dedicated server. Here’s a look at some of the top benefits that might convince you that you need to make the upgrade to a dedicated server.

  1. Exclusive server usage: when you really break it down, do any of us want to share our server capabilities? Exclusive server access is one of the primary benefits of using a dedicated server for your hosting needs. You’ll receive all the disk space, bandwidth, RAM, and storage for your website and hosting needs. A dedicated server also offers root access. This can be incredibly important because it allows you to configure specific settings and add or remove access for other users. If you want complete control over your web hosting, a dedicated server is a way to achieve this.
  2. Better security: especially true for those hosting an eCommerce site, web security is critical to ensure customers will shop with you again. With web hacking on the rise, the security of your site needs to be a top priority to protect yourself and the personal information of your customers. The infrastructure of a dedicated server incorporates 24/7 web monitoring and firewalls so that you can rest easy knowing your data and information are secure. Dedicated servers also offer an unmatched level of customization so that you can find the security measures you need.
  3. Better performance: when it comes to web hosting, you shouldn’t ever have to sacrifice performance. Even if you’re just online gaming with friends, slow load times and lag can quickly ruin your favorite game and your entire online experience. For eCommerce companies, poor performance translates to fewer sales. Dedicated servers provide access to the best performance in the industry with unmatched RAM, memory, and faster page loading speeds. Take your web hosting to the next level with the power of a dedicated server.
  4. Reliable web hosting: whether you’re hosting a website or an online game, there’s nothing worse than a sudden server crash. A server crash can keep your site down for an extended period of time, and if this becomes a frequent occurrence, hurt the overall reputation of your site and your business. Reliability is one of the most important benefits of using a dedicated server. With a dedicated server at your disposal, crashes become far less likely, and with additional resources available for your hosting needs, the server will perform even during times of high traffic. More bandwidth also gives you more capabilities to expand the potential of your online gameplay and your site.

Do you need a Dedicated Server?

While the benefits of a dedicated server are quite clear by now, this doesn’t mean this technology is necessary for everyone. A dedicated server, as expected, comes with higher costs, which means that you may not want to make this upgrade unless you actually need it. But as your website or eCommerce business grows, you should also factor in the risks of having a website that fails to perform. In the long run, this could hurt more than the upfront costs of having your own dedicated server.

Conclusion

The right web hosting is essential for the success of any website or eCommerce company. Web hosting is essentially the engine behind your site, providing RAM, memory, speed, and performance for all your users. While shared hosting may work fine for smaller sites, as you grow you may find that you simply need more. If this sounds like your situation, a dedicated server could be the answer for you.

Dedicated servers provide exclusive access to a server for your site or online gaming experience. With better performance, faster loading speed, enhanced security, and customizable options, a dedicated server can transform your hosting experience and take your website to the next level. To make the jump, check out a dedicated server provider today.

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir