Pairing via QR Code

Pre-requisite:

  • The user has to be signed in, and a pairing session key must already exist. See Pairing a Camera.
  • No Bluetooth permission and no BLE connection is required for this path — if a BLE session is still open, call InstaVision.bleService.release() before showing the QR code.

The phone displays a QR code; the camera reads it with its own lens and uses the values inside to join the Wi-Fi network and claim the pairing session. The SDK does not generate the image — it only supplies the session key — so the payload below is what you have to encode yourself.

Create the session key first with createPairingSession, described in Pairing a Camera.


QR Code Payload

The payload is plain text — no JSON, no URL, no prefix. Fields are separated by a single newline (\n) and must appear in exactly this order:

<ssid>
<password>
<sessionKey>
<regionId>
<environmentId>
Field Required Value
ssid Yes SSID of the 2.4 GHz Wi-Fi network the camera should join.
password Yes Password for that network. For an open network write an empty line — never drop the line, the camera counts fields by position.
sessionKey Yes PairingSession.sessionKey returned by createPairingSession.
regionId Yes id of the ServerRegions the SDK was initialised with.
environmentId Yes value of the Environment the SDK was initialised with.

regionId values:

Region ServerRegions.id
ServerRegions.US 1
ServerRegions.APAC 1

environmentId values:

Environment Environment.value
Environment.RELEASE 1
Environment.STAGING 2
Environment.DEBUG 3

When there are no Wi-Fi credentials to hand over — the camera already has connectivity and only needs to claim the session — omit the two Wi-Fi fields and encode a three-line payload of sessionKey, regionId and environmentId. The choice is made by whether an SSID is available, not by the camera model.


Generating the QR Code

Any QR encoder works as long as the encoded text is byte-identical to the payload above. ZXing (com.google.zxing:core) is one option — it is not an SDK dependency, so add it yourself if you use it:

val payload = listOf(ssid, password, sessionKey, region.id, environment.value)
  .joinToString(separator = "\n")

val hints: MutableMap<EncodeHintType, Any> = HashMap()
hints[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.L
hints[EncodeHintType.MARGIN] = 1

val bitMatrix = MultiFormatWriter().encode(
  payload,
  BarcodeFormat.QR_CODE,
  1_200,             // width in px
  1_200,             // height in px
  hints
)

Best Practice: Render the code square and as large as the screen allows, raise the screen brightness to maximum, keep the screen awake, and hold the phone roughly 20–30 cm from the camera lens.


Confirming the Pairing

The camera never reports back over the QR path, so poll getPairingSessionStatus (see Pairing a Camera) with the same session key until status equals PairingStatus.PROCESSED.type; the response then carries the deviceId of the paired camera. Treat expired == true, isLoginFailed() or isPairingFailed() as a failed attempt that has to restart from a fresh session key. Polling every 3 seconds is a reasonable interval.


This site uses Just the Docs, a documentation theme for Jekyll.