Skip to content

Quick Access to Developer Center

Description

The capability of the gateway is to convert the communication protocols between different devices, allowing sub-devices that do not have networking capabilities to connect to the IoT platform through the gateway. To achieve this purpose, the gateway should connect to Developer Center first, and then you need to add the sub-device to the gateway to establish the connection between the sub-device and Developer Center. This chapter tells you how to connect the sub-devices to Developer Center through the gateway with QuecOpen solution.

FunctionDescription
Ql_iotConfigSetSubDevEventCB()Registers the callback function for the interaction event between the sub-device and the gateway.
Ql_iotSubDevConn()Connects sub-device to gateway or authenticates sub-device.
Ql_iotSubDevDisconn()Disconnects the sub-device from the gateway.
Ql_iotSubDevPassTransSend()Sends transparent transmission data of the sub-device to Developer Center.
Ql_iotSubDevPassTransSend_ex()Sends transparent tranmission data of the sub-device to Developer Center.
Ql_iotSubDevTslReport()Sends TSL data of sub-device to Developer Center.
Ql_iotSubDevTslReport_ex()Sends TSL data of sub-device to Developer Center.
Ql_iotSubDevTslAck()Replies to TSL data requested by Developer Center to the sub-device.
Ql_iotSubDevDeauth()De-registers the sub-device.
Ql_iotSubDevHTB()Refreshes the last interaction time between sub-device and gateway.

Note: For details see API Overview on Gateway and Sub-device

Procedures

1. Log in to Developer Center

Log in to Developer Center. If you don't have an account click Register Now to register.

2. Create Product

1) Create a Gateway Product

Creating a gateway product is similar to creating a cellular product. In the Device Type option, select Gateway.

img

2) Create a Sub-device Product

img
  • Device Type: A directly connected device can directly access the network. A gateway device can help sub-devices to connect to Developer Center. A sub-device is a device that relies on the gateway to connect to the network.
  • Specified Gateway:
    • Disable: Sub-devices can access Developer Center through any gateway.
    • Enable: Sub-devices can access Developer Center only through the specified gateway.
  • Gateway Access Mode: Developer Center authorizes the gateway device.
    • Access Network Only:The sub-device uses the gateway as a channel for Internet access and data forwarding, and it is managed as a directly connected device.
      • Enable Dynamical Gateway Switching: Sub-devices that have connected to Developer Center through a gateway can switch to another gateway to access Developer Center.
      • Disable Dynamical Gateway Switching: Sub-devices that have connected to Developer Center through a gateway cannot switch to another gateway to access Developer Center.
    • Product Integrated: The sub-device is integrated into the gateway and can be queried and controlled by the gateway.

3. Configure Gateway Device

1) Initialization

Before development, please complete the initialization of the QuecOpen solution of the project. The function below needs to be called before using the networking service. Initialization refers to completing the basic configuration of the module after the module is powered on to connected to the IoT platform.

c
/* Initialize QuecThing SDK */
Ql_iotInit();

2) Register Callback Function of Gateway Event

The event callback function is simply to add a monitoring task to the event source (component). When the gateway device triggers an event, the listener will process the event. The developer only needs to deal with the event notified by the event callback function.

c
/* Register QuecThing event callback function */
Ql_iotConfigSetEventCB(Ql_iotEventCB);

3) Configure Product Info (Required at the first connection)

QuecThing SDK provides interfaces and reference implementations for reading and writing device information, which can be adapted according to specific project requirements. When the gateway device sends a bootstrap/authentication, Developer Center authenticates ProductKey and ProductSecret that the bootstrap/ authentication carries. If the bootstrap/authentication is passed, a connection is established and the information required for the device access is delivered.

c
/* Configure product info*/
Ql_iotConfigSetProductinfo("pxxxxS", "VnhyxxxxxxxxSTFh");

4) Connect to Developer Center

The module enables to connect to Developer Center, establishes a safe and stable communication between Developer Center and the device, and realizes device management, monitoring, control and other operations.

c
/* Enable to connect to Developer Center */
Ql_iotConfigSetConnmode(1);

Note: Sub-device messages received by the gateway before it is connected to Developer Center are discarded. Once connected, it starts forwarding sub-device messages to Developer Center.

4. Sub-device Operation Procedures

The capability of the gateway is to convert the communication protocols between different devices, allowing sub-devices that do not have networking capabilities to connect to the IoT platform through the gateway. To achieve this purpose, you need to add the sub-device to the gateway to establish the connection between the sub-device and the gateway.

1) Register Sub-device Event Callback

The event callback function is simply to add a monitoring task to the event source (component). When the sub-device triggers an event, the listener will process the event. The developer only needs to deal with the event notified by the event callback function.

c
/* Register event callback function */
Ql_iotConfigSetSubDevEventCB(Ql_iotSubEventCB);

2) Authenticate Sub-device

Connecting to Developer Center for the first time requires sub-device authentication, which can be done through Ql_iotSubDevConn(). After the MCU receives the successful authentication event report, the sub-device will automatically connect to Developer Center. If the authenticated sub-device is not connected to Developer Center, it can be deregistered through Ql_iotSubDevDeauth().

c
/* Authenticate the sub-device to Developer Center */
Ql_iotSubDevConn("pxxxxm", VnhyxxxxxxxxSTFh, "123xxxx89", NULL, 0, 30);

Note: This function connects the sub-device to the gateway or authenticates the sub-device. The connection/authentication result is notified by the interaction event between the sub-device and the gateway. If subDs is set to NULL, it means to authenticate the sub-device; If subDs is specified, it means to connect the sub-device to the gateway.

5. Sub-device Sends Heartbeat Packets

To maintain the connection between the sub-device and the gateway, a heartbeat message is sent between them. The sub-device sends these packets periodically based on a sub-device keepalive time configured during connection to the gateway. To initiate the sending of these packets, the MCU must execute AT+QIOTSUBHTB.

c
/* The sub-device sends heartbeat packet through the gateway to Developer Center */
Ql_iotSubDevHTB("pxxxxm","123123123");

6. TSL Data Interaction of Sub-device

For remote control of a smart device, a gateway must report the status of the device, receive and execute commands from the IoT platform. Therefore, data transmission is the core capability of the gateway. The smart LGB light sub-device will be used to illustrate TSL model interaction.

Sub-devices can adopt different strategies to detect and process data properties based on the service scenarios. For example, sub-devices can read data from smart tri-color light sensor switches through the serial port, and then upload the read data to Developer Center through the gateway.

The TSL data sent is shown in the table below.

IDTypeValue
1Booltrue
2Int30

Sample code:

c
void *ttlvHead = NULL;
Ql_iotTtlvIdAddBool(&ttlvHead, 1, TRUE);
Ql_iotTtlvIdAddInt(&ttlvHead, 2, 30);
Ql_iotSubDevTslReport_ex("pxxxxm","123xxxx89",ttlvHead);
Ql_iotTtlvFree(&ttlvHead);

Note: After adding the TSL node and calling it, call Ql_iotTtlvFree(), which will release a memory block pointed to by the pointer to avoid problems such as memory leakage.

1) Developer Center Issues TSL Service

On the Device Debug page of Developer Center, click "Property Debug", select the TSL property to be issued, and click "Send Command" in the lower left corner to issue the TSL property to the sub-device.

img

2) Sub-device Receives and Processes TSL Data

When the module receives the TSL data, it will automatically enter the sub-device event processing callback function Ql_iotSubEventCB, and you can perform data response processing according to the corresponding event.

  • The sample code for event callback processing:

    c
    void Ql_iotSubEventCB(quint32_t event, qint32_t errcode, const char *subPk, const char *subDk, const void *value, quint32_t valLen)
    {
    	switch (event)
    	{
    	/* Operation of receiving the data */
    	case QIOT_ATEVENT_TYPE_RECV:
    		printf("data recv event,code:%d\r\n",errcode);
    		/* Received TSL data issued by Developer Center */
    		if(10210 == errcode)
    		{
    			/* TSL handle */
    			Ql_iotTtlvHandle(value);
    		}
    
    	default:
    		break;
    	}
    }