Skip to main content

Connecting to a Micro Web Server

ESP8266 can be programmed to serve a micro web server which can be accessed through WiFi. However, connecting to the module involves multiple steps.

Connecting to a WiFi Access Point (AP) is like physically plugging-in a cable of a Local Area Network (LAN) into its switch. Yet it does not immediately connect our device to a web server. A connection to an AP may not necessarily get our device into an Internet Protocol (IP) network where a web server is hosted because a WiFi AP does not necessarily implement IP. Similarly, a LAN switch may not necessarily implement IP. At the very low level of networking the devices may identify each other through Media Access Control (MAC) addresses. A mesh networking implements a communication layer below IP. It is up to the devices to implement their own networking protocol. However, IP happens to be pervasive in WiFi networking.

ESP8266 does implement IP and a Dynamic Host Configuration Protocol (DHCP) server which assign our device with a dynamic IP address.

A micro web server in ESP8266 is assigned with the IP address 192.168.4.1 by default.

Generally, we connect our device to a WiFi AP through a Service Set Identifier (SSID) which appears in our device's WiFi list. For ESP8266, the module itself defines its own SSID such as "ESP_70056A" or whatever name which can be changed programmatically. Please note that SSID has nothing to do with IP.

Once our device is connected to a ESP8266 WiFi AP, open a web browser in our device and enter 192.168.4.1 into the search or address bar, and press enter. The micro web server's home page will show up.

User Experience


Usually, we connect to a WiFi because we want to access the Internet. We do the connection once and forget about it since our device will auto-connect whenever it is near to the WiFi AP. And we don't usually enter an IP address in the search or address bar. Hence, the steps to connect to a ESP8266 micro web server is a little bit awkward.

The Steps to Connect to a Micro Web Server:

  1. Open the WiFi list from the device's settings.
  2. Select the SSID.
  3. Open a web browser.
  4. Enter the micro web server IP address.

Notice that we have to be prepared with the SSID and the IP address of the micro web server. And we have to apply them in two different applications. This is not good from the point of user experience (UX).

Bookmark


We can bookmark the IP address in the browser. But we still have to manage the bookmark. Generally in the Internet realm, we don't manage bookmarks because we can simply search the Internet for a web server. Hence, bookmarking is also not a good UX.

Common WiFi


The ESP8266 can be configured as a WiFi station where it connect itself into an existing WiFi network. However, the process to connect to that micro web server is about the same. The only different is the SSID. Instead of the SSID of the module, we connect to the SSID of the network that the module is connected to. Hopefully it is the SSID that connect our device to the Internet. And our device may have already been connected to it automatically. Hence, it reduces the steps to connect to the micro web server.

However, the WiFi network may assign a different IP address to the module. The module needs to be assigned with a fixed IP address. Otherwise, our device may not be able to connect to the module.

Captive DNS


The IP address of the micro web server is still a UX problem. The Internet solves the IP address problem through the Domain Name Service (DNS) which substitutes IP addresses with domain names such as www.google.com. The ESP8266 module in AP mode can use a simple trick by implementing a captive DNS server which will redirect any domain name to a fixed IP address. However, if we use a Chrome browser then the redirection will only work with valid domain names. For anything other than a domain name Chrome will treat it as a search phrase and will handle it differently. One way is to advertise a fake domain name for the module instead of the IP address. Actually, any fake domain name will do since the module will not be exposed to the Internet unless the module also shares the same WiFi that connect to the Internet.

mDNS


The ESP8266 SDK implements multicast DNS (mDNS). However, the feature is not yet supported in major browsers like Chrome. With mDNS we can give our module a domain name such as esp8266.local. 

Add to Home Screen


Still a user has to enter something into the address bar of a browser to reach for a micro web server. Alternatively in a browser, we can create a short cut or add it to home screen so that we can skip entering something into the address bar. However, that is not a common thing to do, and it adds another step in the process. Anyway, that may work for now.

Comments

  1. Your website is really cool and this is a great inspiring article. Thank you so much.
    Fixed IP

    ReplyDelete

Post a Comment

Popular posts from this blog

Setting Up PyScripter for Quantum GIS

PyScripter is a general purpose Python Integrated Development Environment (IDE). Quantum GIS (QGIS) is a desktop GIS application that can be extended with Python plugins. Both are open source softwares. We intend to use PyScripter as an IDE to build QGIS Python plugin. We are using PyScripter 2.4.1.0 and QGIS 1.6.0 in Windows. PyScripter does not come with Python. On the other hand, QGIS is built in with Python. Thus, we will setup up PyScripter to use the build in Python in QGIS. We assume both PyScripter and QGIS are already installed. Preparing PyScripter batch file We assume that QGIS is installed in C:\OSGeo4W\ folder and PyScripter is installed in C:\Program Files\PyScripter\ . 1. Copy qgis.bat in C:\OSGeo4W\ bin to pyscripter.bat 2. Edit pyscripter.bat to remove the last line that read something like this start "Quantum GIS" /B "%OSGEO4W_ROOT%"\apps\qgis\bin\qgis.exe %* and replace it with this in one line Start "PyScripter" /B "C:\Progr

Sending Emails via SMTP

msmtp  requires a minimal setup for sending emails via SMTP compared to sendmail. Here is a configuration for you to send emails from a web host to an external SMTP server. Prior to doing that, you must check whether there is a clear communication channel between your web host and the SMTP server. You can use Telnet . Set up msmtp You are going to set msmtp as an MTA . Hence, you need to remove all other MTAs such as postfix and sendmail: $ sudo apt-get --purge autoremove postfix sendmail Install msmtp and related utilities: $ sudo apt-get install msmtp msmtp-mta mailutils Configure msmtp: $ sudo nano /etc/msmtprc # Set default values for all following accounts. defaults # Use the mail submission port 587 instead of the SMTP port 25. port 587 # Always use TLS. tls on # Set a list of trusted CAs for TLS. The default is to use system settings, but # you can select your own file. tls_trust_file /etc/ssl/certs/ca-certificates.crt # The SMTP server account mx host mail.mx.example

fatal: Couldn't find remote ref master

If you are using Github then  master is now known as main . Whatever you want to do with a master must now be referred to a main . If you search for this error message on the Internet then you will encounter with a lot of old discussions on how to set up your master properly which is probably not what you are looking for. The master  is your problem. Rename it to main . I wrote Git My Way about two years ago. Today I created another Github repository. I got this  "fatal: Couldn't find remote ref master"  error message when I wanted to sync the new repo for the first time with my notebook using the notes I wrote in the blog. All the discussions around the error message I found on the Internet were perplexing. Then I recalled that Github had renamed master to main  due to the master-slave connotation. We always have a master copy of a code, never a slave copy. Now suddenly a word context has been diminished for good. What is going to happen to the existing vast documen