Skip to content

Device Connection API

API Overview

FunctionDescription
Qth_devInit()Initializes QuecThing SDK.
Qth_devStart()Initiates the connection to Developer Center.
Qth_devReset()Resets the device.
Qth_devRemove()Deletes the device.
Qth_devGetStatus()Gets the device status.

API Description

Qth_devInit

This function automatically calls the initialization functions of all component objects to initialize QuecThing SDK. This function must be called before other functions are used.

Prototype

c
oprt_ret Qth_devInit();

Parameter

  • Input Parameter

    • None
  • Output Parameter

    • None
  • Return Value

    • OPRT_OK: Successful execution
    • Other value: Failed execution. See Error Code List for details.

Example

c
oprt_ret ret = OPRT_OK;

ret = Qth_devInit();
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "sdk init error");
}

Qth_devStart

This function initiates the connection to Developer Center. Before the connection, relevant configurations (such as product information configuration) should be done. After initiating the connection, the device will automatically connect to the router and Developer Center if there is Wi-Fi network provisioning information, and it will enter the network provisioning mode if there is no Wi-Fi network provisioning information.

Prototype

c
oprt_ret Qth_devStart();

Parameter

  • Input Parameter

    • None
  • Output Parameter

    • None
  • Return Value

    • OPRT_OK: Successful execution
    • Other value: Failed execution. See Error Code List for details.

Example

c
oprt_ret ret = OPRT_OK;

Qth_devInit();
/* Configure server information, product information, etc. */
ret = Qth_devStart();
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "sdk start error");
}

Qth_devReset

This function resets the device. After this function is called, the Wi-Fi information will be cleared, and the device will reboot to enter the network provisioning mode. When the device reconnects to Developer Center, the binding information and DeviceSecret will be reset.

Prototype

c
oprt_ret Qth_devReset();

Parameter

  • Input Parameter

    • None
  • Output Parameter

    • None
  • Return Value

    • OPRT_OK: Successful execution
    • Other value: Failed execution. See Error Code List for details.

Example

c
oprt_ret ret = OPRT_OK;

ret = Qth_devReset();
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "dev reset error");
}

Qth_devRemove

This function deletes the device. After this function is called, the Wi-Fi information will be cleared and the device will automatically enter the network provisioning mode.

Prototype

c
oprt_ret Qth_devRemove();

Parameter

  • Input Parameter

    • None
  • Output Parameter

    • None
  • Return Value

    • OPRT_OK: Successful execution
    • Other value: Failed execution. See Error Code List for details.

Example

c
oprt_ret ret = OPRT_OK;

ret = Qth_devRemove();
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "dev remove error");
}

Qth_devGetStatus

This function gets the device status.

Prototype

c
oprt_ret Qth_devGetStatus(Qth_devStatus_e *status);

Parameter

  • Input Parameter

  • None

  • Output Parameter

    • Qth_devStatus_estatus: Device status.
      ValueDescription
      QTH_DEV_STATUS_SLIENTIdle status, with Bluetooth broadcast off.
      QTH_DEV_STATUS_NETCFGNetwork provisioning, with Bluetooth broadcast on.
      QTH_DEV_STATUS_NETCFGEDNetwork provisioned.
      QTH_DEV_STATUS_CONNECTED_ROUTERouter connected.
      QTH_DEV_STATUS_CONNECTED_DMPPlatform connected.
  • Return Value

    • OPRT_OK: Successful execution
    • Other value: Failed execution. See Error Code List for details.

Example

c
oprt_ret ret = OPRT_OK;
Qth_devStatus_e status;

ret = Qth_devGetStatus(&status);
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "get dev connect status error");
}

Error Code List

Enumeration ValueHexadecimalDecimalDescription
OPRT_OK-0x0000-0Successful execution.
OPRT_COM_ERROR-0x0001-1General error.
OPRT_INVALID_PARM-0x0002-2Invalid parameter.
OPRT_MALLOC_FAILED-0x0003-3Memory allocation failed.
OPRT_NOT_SUPPORTED-0x0004-4Not supported.
OPRT_NOT_FOUND-0x0005-5Object not found.
OPRT_INDEX_OUT_OF_BOUND-0x0006-6Index out of bounds.
OPRT_EXCEED_UPPER_LIMIT-0x0007-7Exceed upper limit.
OPRT_NOT_EXIST-0x0008-8Not exist.
OPRT_QTH_DMP_SERVER_ERROR-0x1700-5888Exceptions occurred for some server APIs.
OPRT_QTH_DMP_SEND_NOT_ALLOW-0x1701-5889Device messages are limited.
OPRT_QTH_DMP_AUTH_NOT_ALLOW-0x1702-5890The device cannot be activated.
OPRT_QTH_DMP_AUTH_ALREADY-0x1703-5891The device has been authenticated.
OPRT_QTH_DMP_PK_NOT_FOUND-0x1704-5892No product information is found via the ProductKey.
OPRT_QTH_DMP_PAYLOAD_INVALID-0x1705-5893Password parsing error.
OPRT_QTH_DMP_SIGN_ERROR-0x1706-5894Sign error.
OPRT_QTH_DMP_RAND_ILLEGAL-0x1707-5895Rand is illegal.
OPRT_QTH_DMP_MISMATCH-0x1708-5896The passed DeviceKey and ProductKey are inconsistent with those stored in the database.
OPRT_QTH_DMP_DK_ILLEGAL-0x1709-5897DeviceKey is illegal.
OPRT_QTH_DMP_FLAG_ILLEGAL-0x170a-5898Flag is illegal.
OPRT_QTH_DMP_CLIENTID_ERROR-0x170b-5899ClientID is not matched with the password.
OPRT_QTH_DMP_DS_ERROR-0x170c-5900DeviceSecret is incorrect.
OPRT_QTH_DMP_DK_NOT_FOUND-0x170d-5901Device information not found.
OPRT_QTH_DMP_SUB_RELATED-0x170e-5902The gateway is not associated with the sub-device.
OPRT_QTH_DMP_SUB_CONNECT_ALREADY-0x170f-5903The sub-device is already online.
OPRT_QTH_DMP_DEV_OFFLINE-0x1710-5904Device offline.
OPRT_QTH_DMP_UNKNOWN_ERROR-0x1711-5905Unknown error.
OPRT_QTH_DEV_GET_CONFIG_FAILED-0x1100-4352Failed to get the configuration.
OPRT_QTH_DEV_NOT_AUTH-0x1101-4353Device not authenticated.
OPRT_QTH_DEV_CONN_FAILED-0x1102-4354Device connection failed.
OPRT_QTH_DEV_RESET_FAILED-0x1103-4355Device reset failed.
OPRT_QTH_DEV_REMOVE_FAILED-0x1104-4356Failed to delete the device.
OPRT_QTH_DEV_ALREADY_CONNECTED-0x1105-4357Device connected.
OPRT_QTH_DEV_RESET_ABNORMAL-0x1106-4358Device reset error (New DeviceSecret has been received for the device with unique-DeviceSecret-per-device authentication).