It is considered bad practice to hard-code WiFi credentials into Arduino sketches.
Typical recommendations include the WiFiManager library for ESP8266, and SmartConfig for ESP32.
Both require the user to have a smartphone to send command to the ESP chip, which otherwise does not have any User Interface (UI).
My ESP32 board is the Heltec WiFi_Kit_32 that comes with a 0.96 inch OLED display and a little PRG button connected to pin #0.
Can I use these minimal UI to enter WiFi credentials without involving a smartphone?
Design with Minimal UI
I took inspiration from Prof Stephen Hawking's computer:
A captive portal is a web page displayed to newly connected users before they are granted broader access to network resource.
ESP8266, when configured as a WiFi access point, can serve a captive portal.
On the other side of the spectrum, ESP8266 can be used as a WiFi client (aka STAtion), and it should be able to "click through" a captive portal as well.
Clearwave Solutions LLC provides WiFi service at my apartment.
Their WiFi network shows a captive portal to each connected client once a week.
The captive portal page has a giant Connect button, which instantly enables Internet access.
Having to press the Connect button every week is an annoyance on a computer or mobile phone.
When it comes to little devices such as a temperature and humidity sensor, the existence of captive portal is a bigger problem because the ESP8266 does not have a web browser, so it is impossible for me press the Connect button.
However, from network point of view, as long as the ESP8266 sends the correct packets, the WiFi gateway would think the button has been pressed.
To click through the captive portal without a web browser on the ESP8266, I just need to:
Each ESP8266, like every other WiFi network interface card, comes with a MAC address that identifies itself to the network.
Sometimes you want to change the MAC address of an ESP8266.
How to do that?
ESP8266 Arduino core does not provide an API to change ESP8266's WiFi MAC address.
While there is a
WiFi.macAddress function, it actually retrieves the current WiFi MAC address, instead of setting it.
However, Espressif SDK offers an API to change the WiFi STA MAC address:
Gogo offers WiFi Internet access on American Airlines domestic flights within United States.
The Internet services are provided through Air-To-Ground (ATG) technology: a cellular radio network of over 200 towers in North America points their antennas to the sky; a Gogo-equipped airliner connects to one of these cellular towers, and provides Internet to passengers via WiFi.
Pricing for Internet access via Gogo in-flight WiFi starts at USD 4.95 for 30 minutes.
American Airlines and Gogo also provide inflight personal device entertainment through the same
gogoinflight Wi-Fi signal.
This service is free of charge, and allows passengers to watch movies and TV episodes on their own smartphones and tablets.
Presumably, contents are pre-downloaded to a server located inside the aircraft, and therefore accessing those contents do not consume radio bandwidth.
While watching videos are permitted during the flight, Gogo does not want passengers to download these copyrighted movies for watching later at home.
Therefore, users must have the Gogo Entertainment app on their mobile devices in order to watch movies.
The app is compatible with the Digital Rights Management technology used in the entertainment server, to ensure that the movies can be watched for free, but cannot be (easily) downloaded.
But what if the device does not already have the Gogo Entertainment app?
Many outdoor places do not have permanent Wi-Fi access points.
Occasionally I can get a weak unencrypted WiFi signal from a nearby shop; otherwise, I'll have to face the fact of not having WiFi, and resort to my slow and expensive SIM card for cellular Internet access.
Since I learned that the ESP8266 can serve as a WiFi hotspot, I got an idea.
I can make the ESP8266 as a Wi-Fi access point (AP), and provide free WiFi to everyone at the outdoor venue.
Except that, this is a freewifi prank: I am providing free WiFi, but my WiFi does not offer Internet access.
ESP8266 makes a
freewifi WiFi access point SSID:
While hackers do good most of the time, we occasionally do evil and play a prank.
The ESP8266, unlike JSON, allows me to do evil.
Thus, I programmed the microcontroller for an evil purpose: slow down the WiFi.
How it Works
802.11 WiFi typically operates in infrastructure mode, where a router acts as an access point, and other hosts (stations) connect to the router on a wireless frequency (a channel).
One property of the wireless channel is that, at any moment, only one party (station or access point) can be transmitting.
If multiple senders are transmitting at the same time, the wireless signal will be jammed, and the recipient is unlikely to receive the packet correctly.
In this case, the sender would have to transmit the packet again at a later time.
Packets can be transmitted at different speeds on the wireless channel.
With 802.11g standard, the maximum speed is 54Mbps, and the minimum is as slow as 1Mbps.
The sender (station or access point) dynamically chooses a speed for every packet depending on its perception of wireless channel quality.
Usually, we prefer to transmit at a higher speed, so that the wireless channel can be freed as soon as possible for other senders to use.
However, if the sender and recipient are far apart, high speed transmission is less likely to succeed because signals can be faded, and a slower speed is necessary to increase the chance of a successful transmission.