QR Code Scanning

Last Updated on : 2023-08-09 09:25:02

This topic describes how an IP camera (IPC) is paired by QR code scanning. Pairing with QR code relies on Wi-Fi. The client obtains IPC pairing information from the cloud and creates a QR code that includes details about the IPC pairing and the Wi-Fi network it connects to. The IPC scans the QR code, connects to the Wi-Fi, and communicates with the cloud for activation.

Pairing process

The component app_user_qrcode is used to start and stop QR code scanning. Steps to process QR code scanning:

  1. Get the video stream.
  2. Enhance the video image using the SDK.
  3. Invoke the open source ZBar to read the QR code.
  4. Determine the result of QR code reading:
    • On success, notify the event module of the result to proceed to activate the device and proactively stop QR code scanning.
    • On failure, request the video stream again until the QR code is read successfully or the pairing process ends due to timeout.
ClientIPCCloudGet the token.Return the token.Generate QR code with the token and the Wi-Fi SSID and password.Scan the QR code with the IPC.Get the video stream and return the QR code.Extract the token and the Wi-Fi SSID and password from the QR code.Connect to the AP.Get registered and activated.Poll for device.Pairing is successful if the poll result is returned.ClientIPCCloud

Pairing process on the client:

QR Code Scanning

Requirements

  • A device that has never been paired.
  • A device that has been removed from the client.
  • A device that has been reset manually.

How it works

  • QR code scanning process

    QR Code Scanning
  • The SSID and password of the Wi-Fi network and a token are decoded from the QR code.

    {
        "p":"hi1234567",
        "s":"home_15",
        "t":"AYTWEpxSR66CVz"
    }
    
  • The device connects to the designated Wi-Fi network to access the internet. It then sends the token to the cloud for activation. After successful activation, the device can connect to the MQTT server.

Development guide

Runtime environment

Components

  • app_sys_msg: the messaging component.
  • app_sys_net: used to send the command for pairing with QR code.
  • app_user_event: used to receive and execute the command for pairing with QR code.
  • app_user_video_capture: gets the stream and called back in the QR scanning thread.

Implement pairing with QR code

  • Implement the execution of pairing with QR code in the message receiving thread of the app_user_event at the application layer.

    • Call ty_user_qrcode_start on receiving E_TY_MSG_SYS_NET_CONFIG_START to start QR code scanning.
    • Call ty_user_qrcode_stop on receiving E_TY_MSG_SYS_NET_CONFIG_STOP to stop QR code scanning.
  • In the app_sys_net module at the application layer, implement the callbacks for starting and stopping access point (AP) and then register the callbacks to the Wi-Fi module. This enables you to start and stop pairing with QR code through callbacks.

    • In the tkl_wifi_start_ap callback, configure the AP parameter, start AP, and send E_TY_MSG_SYS_NET_CONFIG_START to the event module to start QR code scanning.
    • In the tkl_wifi_stop_ap callback, recycle the AP process and send E_TY_MSG_SYS_NET_CONFIG_STOP to the event module to stop QR code scanning.

API description

Start QR code scanning

/**
 * @brief Start QR code parsing, which is called during device startup.
 *
 * @return int
 */
int ty_user_qrcode_start();

Stop QR code scanning

/**
 * @brief Stop QR code parsing, which is called when parsing is completed.
 *
 * @return int
 */
int ty_user_qrcode_stop();

FAQs

Why can’t the QR code be recognized?

Check if:

  • The camera lens is clean.
  • The camera can focus properly.
  • The YUV data is complete.
    You can save the YUV data to the local device and scan it with your phone to see if it can be recognized.

Why doesn’t QR code scanning work well in a long or short distance or some angles?

  • Check the camera lens and the focal length.
  • Make sure you have enabled QR code enhancement.
  • Check if image distortion occurs in different angles.