Generate QR Code for WiFi

Generate QR Code for WiFi

Instead of having your guests hunting for WiFi name and type in your weird password, let them scan a QR code and connect with ease.

Change wifi-name , wifi-password below and save the QR code.

const wifi_name = "wifi-name"
const wifi_password = "wifi-password"

escape = (s) => s.replace(/\\|;|,|:/g, c => `\\{c}`)
const name = escape(wifi_name)
const pass = escape(wifi_password)

const str = `WIFI:T:WPA;S:${name};P:${pass};;`

const dataUrl = jQuery('#qrcode').empty().qrcode({text: str}).find('canvas')[0].toDataURL()
jQuery('#qr_img').attr('src',dataUrl)
str

To download the code, right-click and select "Save Image As..". Or Long-press and "Save Image" if you are on iOS.

Scanning the Code (iOS)

  1. Open iOS camera
  2. Point it at the QR Code
  3. Tap the popped up notification

Generate code from terminal

Understandably, you may not be comfortable typing your wifi-password in a browser. We could also generate a QR code via terminal.

brew install qrencode

qrencode -o code.png "WIFI:T:WPA;S:wifi-name;P:wifi-password;;"

References