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

Rust

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

let json = chilkat::JsonObject::new();
let _ = json.update_string("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.
let _ = json.update_string("encoding.qr.errorCorrection", "Q");
let _ = json.update_int("render.moduleSize", 8);

// Say which network it is under the code.
let _ = json.update_bool("render.text.enabled", true);
let _ = json.update_string("render.text.value", "Wi-Fi: Chilkat Guest");
let _ = json.update_int("render.text.scale", 2);

let _ = json.update_string("output.path", "qa_output/qr_wifi.png");
let _ = json.update_bool("output.overwrite", true);
let _ = json.update_string("output.return", "none");

let fmt = chilkat::Formats::new();
let json_out = chilkat::JsonObject::new();
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("file: {}", json_out.string_of("outputs[0].path").unwrap_or_default());
println!("QR version: {}", json_out.int_of("symbols[0].selectedEncoding.version"));
println!("image: {} x {} pixels", json_out.int_of("outputs[0].width"), json_out.int_of("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