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

React Native
import { Formats, JsonObject } from '@chilkat/react-native'

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

  const json = new JsonObject();
  json.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.
  json.updateString('encoding.qr.errorCorrection', 'Q');
  json.updateInt('render.moduleSize', 8);

  // Say which network it is under the code.
  json.updateBool('render.text.enabled', true);
  json.updateString('render.text.value', 'Wi-Fi: Chilkat Guest');
  json.updateInt('render.text.scale', 2);

  json.updateString('output.path', 'qa_output/qr_wifi.png');
  json.updateBool('output.overwrite', true);
  json.updateString('output.return', 'none');

  const fmt = new Formats();
  const jsonOut = new JsonObject();
  try {
    fmt.qrCode('generate', json, jsonOut);
  } catch {
    console.log(fmt.lastErrorText);
    return;
  }

  console.log(`file: ${jsonOut.stringOf('outputs[0].path')}`);
  console.log(`QR version: ${jsonOut.intOf('symbols[0].selectedEncoding.version')}`);
  console.log(`image: ${jsonOut.intOf('outputs[0].width')} x ${jsonOut.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
}