Skip to content

Data Interaction API

API Overview

FunctionDescription
Qth_cmdSendTsl()Sends TSL data to Developer Center.
Qth_cmdSendTrans()Sends transparent transmission data to Developer Center.
Qth_wanSendDevInfo()Reports device information to Developer Center.
Qth_wanSendDevStatus()Reports device status to Developer Center.
Qth_ntpSetResultCb()Sets callback function of receiving the NTP result.
Qth_ntpSendNtpReq()Sends an NTP request.

API Description

Qth_cmdSendTsl

This function sends TSL data to Developer Center.

Prototype

c
oprt_ret Qth_cmdSendTsl(Qth_sendMode_e mode, void *ttlvHead, quint16_t *pkgId, Qth_sendCb_f sendCb);

Parameter

  • Input Parameter

    • Qth_sendMode_emode: Data sending mode.

      ValueDescription
      QTH_SEND_AT_MOST_ONCEEach message is only sent once with no confirmation or resending required. Data loss or repetition may occur.
      QTH_SEND_AT_LEAST_ONCEEach message is sent at least once until the device receives the reception confirmation from Developer Center. Data repetition may occur.
      QTH_SEND_EXACTLY_ONCEEach message is only sent once by Developer Center and only received once by the receiver, with no data loss or repetition.
    • void * ttlvHead: TTLV data table.

    • Qth_sendCb_fsendCb: Callback function of data sending result. If you do not care about the sending result, set this parameter to NULL.

      • Prototype
        c
        typedef void (*Qth_sendCb_f)(quint16_t pkgId, qbool result);
      • Input Parameter
        • quint16_tpkgId: PkgID of the data sent.
        • qboolresult: Data sending result.
  • Output Parameter

  • quint16_t * pkgId: PkgID of the data sent. If you do not care about the sending result, set this parameter to NULL.

  • Return Value

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

Example

c
void *ttlvHead = NULL;

Quos_ttlvAddIdBool(&ttlvHead, 1, TRUE);
Qth_cmdSendTsl(QTH_SEND_AT_MOST_ONCE, ttlvHead, NULL, NULL);

Qth_cmdSendTrans

This function sends transparent transmission data to Developer Center.

Prototype

c
oprt_ret Qth_cmdSendTrans(Qth_sendMode_e mode, quint8_t *value, quint32_t valLen, quint16_t *pkgId, Qth_sendCb_f sendCb);

Parameter

  • Input Parameter

    • Qth_sendMode_emode: Data sending mode.

      ValueDescription
      QTH_SEND_AT_MOST_ONCEEach message is only sent once with no confirmation or resending required. Data loss or repetition may occur.
      QTH_SEND_AT_LEAST_ONCEEach message is sent at least once until the device receives the reception confirmation from Developer Center. Data repetition may occur.
      QTH_SEND_EXACTLY_ONCEEach message is only sent once by Developer Center and only received once by the receiver, with no data loss or repetition.
    • quint8_t * value: Transparent transmission data.

    • quint32_tvalLen: Length of transparent transmission data.

    • Qth_sendCb_fsendCb: Callback function of data sending result. If you do not care about the sending result, set this parameter to NULL.

      • Prototype
        c
        typedef void (*Qth_sendCb_f)(quint16_t pkgId, qbool result);
      • Input Parameter
        • quint16_tpkgId: PkgID of the data sent.
        • qboolresult: Data sending result.
  • Output Parameter

  • quint16_t * pkgId: PkgID of the data sent. If you do not care about the sending result, set this parameter to NULL.

  • Return Value

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

Example

c
void sendCb(quint16_t pkgId, qbool result)
{
    Quos_logPrintf(LL_DBG, "recv send event, pkgId:%u, result:%d", pkgId, result);
}
quint16_t pkgId = 0;
Qth_cmdSendTrans(QTH_SEND_AT_LEAST_ONCE, "hello world", 11, &pkgId, sendCb);

Qth_ntpSetResultCb

This function sets callback function of receiving the NTP result.

Prototype

c
oprt_ret Qth_ntpSetResultCb(Qth_ntpCb_f callback);

Parameter

  • Input Parameter

    • Qth_ntpCb_fcallback: Callback function of receiving the NTP result.
      • Prototype
      c
      typedef void (*Qth_ntpCb_f)(quint16_t pkgId, Qth_ntpInfo_t *ntpInfo);
  • Output Parameter

  • None

  • Return Value

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

Example

c
oprt_ret ret = OPRT_OK;

void ntpDataCb(quint16_t pkgId, Qth_ntpInfo_t *ntpInfo)
{
    Quos_logPrintf(LL_DBG, "recv ntp info, pkgId:%u", pkgId);
    Quos_logPrintf(LL_DBG, "%04d-%02d-%02d %02d:%02d:%02d.%03d, %s, "PRINTF_FORMAT_U64,
                    ntpInfo->tm.tm_year, ntpInfo->tm.tm_mon, ntpInfo->tm.tm_mday, ntpInfo->tm.tm_hour, ntpInfo->tm.tm_min, ntpInfo->tm.tm_sec, ntpInfo->tm.tm_ms,
                    ntpInfo->timezone, PRINTF_CONV_U64(ntpInfo->timestamp));
}

ret = Qth_ntpSetResultCb(ntpDataCb);
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "set ntp result callback error");
}

Qth_ntpSendNtpReq

This function sends an NTP request.

Prototype

c
oprt_ret Qth_ntpSendNtpReq(quint16_t *pkgId, Qth_sendCb_f sendCb);

Parameter

  • Input Parameter

    • Qth_sendCb_fsendCb: Callback function of data reporting result. If you do not care about the sending result, set this parameter to NULL.
      • Prototype
      c
      typedef void (*Qth_sendCb_f)(quint16_t pkgId, qbool result);
  • Output Parameter

  • quint16_tpkgId: PkgID of the data reported. If you do not care about the sending result, set this parameter to NULL.

  • Return Value

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

Example

c
oprt_ret ret = OPRT_OK;

void ntpDataCb(quint16_t pkgId, Qth_ntpInfo_t *ntpInfo)
{
    Quos_logPrintf(LL_DBG, "recv ntp info, pkgId:%u", pkgId);
    Quos_logPrintf(LL_DBG, "%04d-%02d-%02d %02d:%02d:%02d.%03d, %s, "PRINTF_FORMAT_U64,
                    ntpInfo->tm.tm_year, ntpInfo->tm.tm_mon, ntpInfo->tm.tm_mday, ntpInfo->tm.tm_hour, ntpInfo->tm.tm_min, ntpInfo->tm.tm_sec, ntpInfo->tm.tm_ms,
                    ntpInfo->timezone, PRINTF_CONV_U64(ntpInfo->timestamp));
}

Qth_ntpSetResultCb(ntpDataCb);
ret = Qth_ntpSendNtpReq(NULL, NULL);
if (OPRT_OK != ret)
{
    Quos_logPrintf(APPS_OPEN, LL_ERR, "send ntp request error");
}

Qth_wanSendDevInfo

This function reports device information to Developer Center.

Prototype

c
void Qth_wanSendDevInfo();

Parameter

  • Input Parameter

    • None
  • Return Value

    • None

Example

c
Qth_wanSendDevInfo();

Qth_wanSendDevStatus

This function reports device status to Developer Center.

Prototype

c
void Qth_wanSendDevStatus();

Parameter

  • Input Parameter

    • None
  • Return Value

    • None

Example

c
Qth_wanSendDevStatus();

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_CMD_PKG_FORMAT_INVALID-0x1200-4608Data packet format error.
OPRT_QTH_CMD_PKG_GENERATE_FAILED-0x1201-4609Failed to generate the data packet.
OPRT_QTH_CMD_UNSUPPORTED-0x1202-4610Unsupported data command.
OPRT_QTH_CMD_PKG_SEND_FAILED-0x1203-4611Failed to send the data packet.
OPRT_QTH_WAN_PKG_FORMAT_INVALID-0x1300-4864WAN data packet format error.
OPRT_QTH_WAN_PKG_REPEATED-0x1301-4865Duplicate WAN data packet.
OPRT_QTH_WAN_GET_TOPIC_FAILED-0x1302-4866Failed to get the topic over WAN.
OPRT_QTH_WAN_UNKNOWN_FAILED-0x1303-4867WAN connection unknown error.