Zig Requires Chilkat v11.7.0+
;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.
Zig
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:Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("payload.text", "WIFI:T:WPA;S:Chilkat Guest;P:correct-horse-battery-staple;;") catch {};
// Level Q, so that the code still scans when it is printed small or gets worn.
json.updateString("encoding.qr.errorCorrection", "Q") catch {};
json.updateInt("render.moduleSize", 8) catch {};
// Say which network it is under the code.
json.updateBool("render.text.enabled", true) catch {};
json.updateString("render.text.value", "Wi-Fi: Chilkat Guest") catch {};
json.updateInt("render.text.scale", 2) catch {};
json.updateString("output.path", "qa_output/qr_wifi.png") catch {};
json.updateBool("output.overwrite", true) catch {};
json.updateString("output.return", "none") catch {};
const fmt = try chilkat.Formats.init();
defer fmt.deinit();
const json_out = try chilkat.JsonObject.init();
defer json_out.deinit();
fmt.qrCode("generate", json, json_out) catch {
std.debug.print("{s}\n", .{try fmt.getLastErrorText(alloc)});
return;
};
std.debug.print("file: {s}\n", .{try json_out.stringOf(alloc, "outputs[0].path")});
std.debug.print("QR version: {d}\n", .{json_out.intOf("symbols[0].selectedEncoding.version")});
std.debug.print("image: {d} x {d} pixels\n", .{ json_out.intOf("outputs[0].width"), json_out.intOf("outputs[0].height") });
// The image written to qa_output/qr_wifi.png:
//
// Sample output:
// file: qa_output/qr_wifi.png
// QR version: 5
// image: 360 x 374 pixels
}