Camera Onboarding and Pairing

In this section, we will guide you to connect Smarter AI camera to the Smarter AI camera platform using required internet and pairing credentials.

Concept

Overall our onboarding process has two steps

Step1: Connecting to the internet
In this step the camera is connected to the internet. Wifi is a popular way to be connected to internet.

Step2: Onboarding through pairing
In IoT, the word Pairing, refers to a process of linking a IoT device with an user account.
This process is also referred as device association.

Understanding the Process

To onboard a smarter camera, it needs to be given Internet connectivity to the camera. If the camera supports WiFi, the onboarding process is done through giving WiFI credential to the camera. If the camera comes with a SIM slot, then it is possible to onboard it over 3G/4G/5G Internet connection.

To pair a camera with user account, it needs pairing token and user Id to be sent to camera.

Process Flow in Brief

  1. App connects with camera
  2. Camera sends it's onboard state to app
  3. App sends onboarding and pairing credentials to camera
  4. Camera uses the onboarding credentials to onboard itself to Smarter AI camera platform
  5. Upon successful onboarding, the camera uses the pairing credentials to pair itself with the user account
  6. Camera notifies the app about success or fail status over the connection

Connecting With Camera

At first, the Smarter AI camera needs to be turned on. Make sure to use a reliable power source.

If the camera is not connected to internet or not paired, it will soon come into paring mode.
When the camera comes into pairing mode, you can connect with the camera to onboard and pair it.

Connecting Using Bluetooth

Finding the Camera Using Bluetooth

Make a Bluetooth device scan to find your camera.

Recognizing the Smarter AI camera as Bluetooth device

The Smarter AI cameras will have Smarter AI in it's name.

Connecting over Bluetooth Socket

The Smarter AI cameras acts as a Bluetooth server. So, you need to connect with it as a Bluetooth client.
You will need an UUID to create a secure socket connection.
For sake of security, we will share the UUID with you privately. Please contact us here.

Connecting Using WiFi

Finding the camera using WiFi

Make a WiFi scan to find your camera.

Recognizing the Smarter AI camera from WiFi list

The Smarter AI cameras will have the word Smarter AI in it's SSID.

Connecting over WiFi Socket

The Smarter AI camera creates a WiFi hotspot and acts as a TCP server for establishing connection with the client.
You need to connect to the camera with specified Security option and password (If needed) provided by Smarter AI.
After you are connected to the WiFi hotspot of the camera, you have to create a TCP client socket with a specified hostname and port on the local network of the camera.
The camera will transmit and receive data over that TCP socket.
For sake of security, we will share the Security option, password, hostname and port with you privately. Please contact us here.

The Onboarding Credentials {docsify-ignore}

The wifi credentials consists of

  1. Wifi SSID
    This is the wifi network name.
  2. Wifi Password
    This is the wifi password to get access to the wifi network.
  3. Pairing token
    Server gives this key to a user and when receives a pairing request from camera with a key, server finds to whom this key was given and pair the camera with that user account.
  4. User Id
    Server uses this user id to find the pairing token given to this user. With this, the search space narrows down making the search process efficient for the server.

These four credentials are required to onboard the camera to Smarter AI network and you'll get these four essential things from mobile app using socket connection either by bluetooth or wifi interface.

Developing Camera App: Onboarding

Necessary resources

  1. libonboard.so
    Aavailable in lib folder. Load this library using dlopen
  2. libaconboard.so
    Available in lib folder. You don't need to load this explicitly.
  3. libacaccess.so
    Available in lib folder. Follow the init process to initialize it.
  4. OnboardService.h
    Available in include folder.
  5. Access.h
    Available in include folder.

Dependency

Onboarding library internally uses

  • libaconboard.so

Stream library internally uses

  • libacconnect.so
  • libvision.so

Access library internally uses

  • libsensor.so

Steps

  1. get available Interface
  2. Enable interface
  3. Receive credentials
  4. Notify Client with message
  5. Connect to Wifi
  6. Onboard the camera using pairing token

Implementing steps

For implementing the steps we shall use the API which are present in OnboardServiec.h and Access.h. The functional descriptions of the APIs are present the respective header files.

Connecting to Internet

1. Get available interfaces

By using following API will provide all available interfaces.

    virtual void getAvailableInterfaces(std::vector<std::string> &interfaceList) = 0;

Sample Code of the implementation

    std::vector<std::string> ifaceList;
    onboardInstance->getAvailableInterfaces(ifaceList);

2. Enable Interface

You can use following api to enable a specific interface by interfaceId.

    virtual void enableInterface(std::string interfaceId) = 0;

There is another API that should be used to disable a specific interface by interfaceId.

    virtual void disableInterface(std::string interfaceId) = 0;

3. Receive Onboarding Credentials

To connect with wifi connection camera app needs to know the Wifi credentials. Below is an example that illustrate how to take Wifi credencials. You can design to take Wifi and Pairing credentials in single-go or in seperate calls.

Interface List These three are the three interfaces which our library supports.

    #define INTERAFCE_ID_BLE          "BLE"
    #define INTERAFCE_ID_WIFI_AP      "WiFi-AP"
    #define INTERAFCE_ID_WIFI_CLIENT  "WiFi-CLIENT"

Handler There is an API setDataReceiveCallback which takes a callback methods. It callbacks with informations which is received from mobile app through interfaces.

    typedef std::function<void(const std::string &interfaceId, std::string &receivedData, size_t length)> DataReceiveHandler;
    virtual void setDataReceiveCallback(DataReceiveHandler handler) = 0;

Following Sample Code shows how to receive credentials or any other information in receivedData and the length of data is in length

    onboardInstance->setDataReceiveCallback([this](const std::string &interfaceId, >std::string &receivedData, size_t length) {
        //receive the credentials or any other information
    });

4. Send Data to notify client (Mobile app)

sendData API is used to send notification to client through interface to keep client updated with current status.

Sending Data Sending data using network interfaces.

    virtual void sendData(std::string interfaceId, std::string data, int length) = 0;

Sample Code following code shows how to send a message to interface.

    std::stringstream ss;
    ss.str("[STATUS]SEND_MSG Pairing started...");
    onboardInstance->sendData("BLE", ss.str(), ss.str().size());

Available Signal messages for RPi devices

[STATUS]BT_ADVERTISE - Camera starts to advertise bluetooth interface.

[STATUS]PARSER_SUCCEEDED - Notify client that the received credentials through interface is successfully parsed.

[STATUS]PARSER_FAILED - Notify client that the received credentials through interface is successfully parsed.

[STATUS]PAIRING_STARTED - Notify client that the camera has just started to pair with Smarter AI platform.

[STATUS]PAIRING_SUCCEEDED - Notify client that the pairing with Smarter AI platform is successful.

[STATUS]PAIRING_FAILED - Notify client that the pairing with Smarter AI platform failed.

[STATUS]WIFI_STARTED - Notify client that camera just started connecting with Wifi.

[STATUS]WIFI_SUCCEEDED - Notify client that camera has connected to wifi succcefully.

[STATUS]WIFI_FAILED - Nofity client that the camera failed to connect to wifi.

[STATUS]APP_ONBOARDED - Notify client that the camera is already onboarded.

[STATUS]APP_ONBOARDING - Notify client that the camera is waiting for onboarding credentials from client.

[STATUS]APP_READY - Notify client that camera is ready for streaming

[STATUS]RESET_STARTED - Notify client that the reset operation is started

[STATUS]RESET_SUCCEEDED - Notify client that the reset operation is successful

[STATUS]RESET_FAILED - Notify client that the reset operation is failed

[STATUS]SEND_MSG - Notify client with any other customized messagae. For example to send a message hello world use [STATUS]SEND_MSG helloworld

5. Connect to Wifi

To connect with a wifi network you can use connecttoWifi API and send Wifi credentials like security, SSID and password by paramenter. Please check the sample code below:

    virtual WifiStatus connecttoWifi(std::string wifiSecurity, std::string wifiSSID, std::string password) = 0;
    auto retConnect = onboardInstance->connecttoWifi("WPA2", ssid, pass);
    if(com::anyconnect::onboard::WifiStatus::SUCCESS == retConnect) {
        //take action for sueccessful connection
    }
    else{
        //take action for failed connection   
    }

Available Wifi Status

    enum WifiStatus {
        SUCCESS,//wifi connection successful
        AUTH_FAIL,//wifi credential failed to authenticate
        UNAVAILABLE,//wifi network unavilable
        FAIL//wifi connection failed for other reason
    };

6. Pairing using Access

Pairing Camera

Once the camera got connected to internet now you can send the pairing credentials to Smarter AI System over the internet. Smarter AI will assign the camera to corresponding user. Now from the mobile app the user can find the camera in his ACL (Access Control List). In Library Initialization we have shown what are the credentials and how to send it.