Wi-Fi QR- Code Generator in python

Sachinjose
2 min read6 days ago

--

Image by DALL.E 3

The motivation behind this blog emerged from my desire to share Wi-Fi passwords with friends and relatives who visit my home. So, I thought of creating a QR code generator that simplifies this task. Whether you’re an experienced developer or a Python beginner, this project provides a small yet rewarding entry point into the world of coding and automation.

First things first, you’ll need to install the `qrcode` module using pip:

pip install qrcode

The process is straightforward: import the module, and then use the `generate_wifi_qrcode()` function to create your QR code. You’ll need to provide the Wi-Fi name (SSID), security type (e.g., WPA), and Wi-Fi password.

import qrcode

def generate_wifi_qrcode(
ssid: str,
password: str,
security_type: str,
qr_code_file: str = "qrcode.png") -> None:

wifi_data = f"WIFI:T:{security_type};S:{ssid};P:{password};;"

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)

qr.add_data(wifi_data)
qr.make(fit=True)

qr_code_image = qr.make_image(
fill_color="black", back_color="white"
)

# Create and save the QR Code
qr_code_image.save(qr_code_file)


wifi_name = input("Enter the Wifi name : ")
wifi_password = input("Enter the Wifi password : ")
security_type = input("Enter the security type : ")
if not security_type:
security_type = "WPA"

generate_wifi_qrcode(wifi_name, wifi_password, security_type)

This script will generate a QR code that, when scanned, will allow others to connect to your Wi-Fi without having to type in the password manually. It’s a great tool for cafes, libraries, or even at home when you have guests.

For those who want to take it a step further, integrating this functionality into a web application is also possible. Using frameworks like Flask, you can create a simple web interface that generates a QR code on demand.

So, why not give it a try? You might just make connecting to Wi-Fi that much easier for everyone around you.

Happy coding and stay connected!

--

--