Sample code for 30+ languages & platforms
DataFlex 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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Handle hoFmt
    Variant vJsonOut
    Handle hoJsonOut
    String sTemp1
    Integer iTemp1
    Integer iTemp2

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "payload.text" "WIFI:T:WPA;S:Chilkat Guest;P:correct-horse-battery-staple;;" To iSuccess

    //  Level Q, so that the code still scans when it is printed small or gets worn.
    Get ComUpdateString Of hoJson "encoding.qr.errorCorrection" "Q" To iSuccess
    Get ComUpdateInt Of hoJson "render.moduleSize" 8 To iSuccess

    //  Say which network it is under the code.
    Get ComUpdateBool Of hoJson "render.text.enabled" True To iSuccess
    Get ComUpdateString Of hoJson "render.text.value" "Wi-Fi: Chilkat Guest" To iSuccess
    Get ComUpdateInt Of hoJson "render.text.scale" 2 To iSuccess

    Get ComUpdateString Of hoJson "output.path" "qa_output/qr_wifi.png" To iSuccess
    Get ComUpdateBool Of hoJson "output.overwrite" True To iSuccess
    Get ComUpdateString Of hoJson "output.return" "none" To iSuccess

    Get Create (RefClass(cComChilkatFormats)) To hoFmt
    If (Not(IsComObjectCreated(hoFmt))) Begin
        Send CreateComObject of hoFmt
    End
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonOut
    If (Not(IsComObjectCreated(hoJsonOut))) Begin
        Send CreateComObject of hoJsonOut
    End
    Get pvComObject of hoJson to vJson
    Get pvComObject of hoJsonOut to vJsonOut
    Get ComQrCode Of hoFmt "generate" vJson vJsonOut To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFmt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStringOf Of hoJsonOut "outputs[0].path" To sTemp1
    Showln "file: " sTemp1
    Get ComIntOf Of hoJsonOut "symbols[0].selectedEncoding.version" To iTemp1
    Showln "QR version: " iTemp1
    Get ComIntOf Of hoJsonOut "outputs[0].width" To iTemp1
    Get ComIntOf Of hoJsonOut "outputs[0].height" To iTemp2
    Showln "image: " iTemp1 " x " iTemp2 " 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


End_Procedure