Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.7.0+

Create a Wi-Fi QR Code

See more QR Code Examples

Demonstrates a QR code that joins a phone to a Wi-Fi network when scanned. A QR code only holds text. Phones recognize text of the form WIFI:T:;S:;P:;; and offer to join the network. T is WPA (also used for WPA2 and WPA3), WEP, or nopass for an open network, and H:true can be added for a hidden network. In the name and the password, the characters backslash, semicolon, comma, colon and double quote must each be preceded by a backslash.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJson
LOCAL oFmt
LOCAL oJsonOut

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("payload.text", "WIFI:T:WPA;S:Chilkat Guest;P:correct-horse-battery-staple;;")

//  Level Q, so that the code still scans when it is printed small or gets worn.
oJson:UpdateString("encoding.qr.errorCorrection", "Q")
oJson:UpdateInt("render.moduleSize", 8)

//  Say which network it is under the code.
oJson:UpdateBool("render.text.enabled", 1)
oJson:UpdateString("render.text.value", "Wi-Fi: Chilkat Guest")
oJson:UpdateInt("render.text.scale", 2)

oJson:UpdateString("output.path", "qa_output/qr_wifi.png")
oJson:UpdateBool("output.overwrite", 1)
oJson:UpdateString("output.return", "none")

oFmt := CreateObject("Chilkat.Formats")
oJsonOut := CreateObject("Chilkat.JsonObject")
nSuccess := oFmt:QrCode("generate", oJson, oJsonOut)
IF (nSuccess == 0)
    ? oFmt:LastErrorText
    oJson:destroy()
    oFmt:destroy()
    oJsonOut:destroy()
    RETURN
ENDIF

? "file: " + oJsonOut:StringOf("outputs[0].path")
? "QR version: " + Str(oJsonOut:IntOf("symbols[0].selectedEncoding.version"))
? "image: " + Str(oJsonOut:IntOf("outputs[0].width")) + " x " + Str(oJsonOut:IntOf("outputs[0].height")) + " pixels"

//  The image written to qa_output/qr_wifi.png:

//  image

//  Sample output:

//  file: qa_output/qr_wifi.png
//  QR version: 5
//  image: 360 x 374 pixels

oJson:destroy()
oFmt:destroy()
oJsonOut:destroy()