PureBasic 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.
PureBasic
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 PureBasic Downloads
IncludeFile "CkFormats.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(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::ckUpdateString(json,"encoding.qr.errorCorrection","Q")
CkJsonObject::ckUpdateInt(json,"render.moduleSize",8)
; Say which network it is under the code.
CkJsonObject::ckUpdateBool(json,"render.text.enabled",1)
CkJsonObject::ckUpdateString(json,"render.text.value","Wi-Fi: Chilkat Guest")
CkJsonObject::ckUpdateInt(json,"render.text.scale",2)
CkJsonObject::ckUpdateString(json,"output.path","qa_output/qr_wifi.png")
CkJsonObject::ckUpdateBool(json,"output.overwrite",1)
CkJsonObject::ckUpdateString(json,"output.return","none")
fmt.i = CkFormats::ckCreate()
If fmt.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
jsonOut.i = CkJsonObject::ckCreate()
If jsonOut.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkFormats::ckQrCode(fmt,"generate",json,jsonOut)
If success = 0
Debug CkFormats::ckLastErrorText(fmt)
CkJsonObject::ckDispose(json)
CkFormats::ckDispose(fmt)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndIf
Debug "file: " + CkJsonObject::ckStringOf(jsonOut,"outputs[0].path")
Debug "QR version: " + Str(CkJsonObject::ckIntOf(jsonOut,"symbols[0].selectedEncoding.version"))
Debug "image: " + Str(CkJsonObject::ckIntOf(jsonOut,"outputs[0].width")) + " x " + Str(CkJsonObject::ckIntOf(jsonOut,"outputs[0].height")) + " pixels"
; 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
CkJsonObject::ckDispose(json)
CkFormats::ckDispose(fmt)
CkJsonObject::ckDispose(jsonOut)
ProcedureReturn
EndProcedure