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

C
#include <C_CkJsonObject.h>
#include <C_CkFormats.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJsonObject json;
    HCkFormats fmt;
    HCkJsonObject jsonOut;

    success = FALSE;

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

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"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.
    CkJsonObject_UpdateString(json,"encoding.qr.errorCorrection","Q");
    CkJsonObject_UpdateInt(json,"render.moduleSize",8);

    //  Say which network it is under the code.
    CkJsonObject_UpdateBool(json,"render.text.enabled",TRUE);
    CkJsonObject_UpdateString(json,"render.text.value","Wi-Fi: Chilkat Guest");
    CkJsonObject_UpdateInt(json,"render.text.scale",2);

    CkJsonObject_UpdateString(json,"output.path","qa_output/qr_wifi.png");
    CkJsonObject_UpdateBool(json,"output.overwrite",TRUE);
    CkJsonObject_UpdateString(json,"output.return","none");

    fmt = CkFormats_Create();
    jsonOut = CkJsonObject_Create();
    success = CkFormats_QrCode(fmt,"generate",json,jsonOut);
    if (success == FALSE) {
        printf("%s\n",CkFormats_lastErrorText(fmt));
        CkJsonObject_Dispose(json);
        CkFormats_Dispose(fmt);
        CkJsonObject_Dispose(jsonOut);
        return;
    }

    printf("file: %s\n",CkJsonObject_stringOf(jsonOut,"outputs[0].path"));
    printf("QR version: %d\n",CkJsonObject_IntOf(jsonOut,"symbols[0].selectedEncoding.version"));
    printf("image: %d x %d pixels\n",CkJsonObject_IntOf(jsonOut,"outputs[0].width"),CkJsonObject_IntOf(jsonOut,"outputs[0].height"));

    //  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


    CkJsonObject_Dispose(json);
    CkFormats_Dispose(fmt);
    CkJsonObject_Dispose(jsonOut);

    }