Skip to content

Example of TSL Data Interaction

Introduction

This chapter explains how to send and receive TSL data by AT command.

AT CommandDescription
AT+QIOTCFGConfigure Optional Parameters
AT+QIOTMODELTDSend TSL Data to Developer Center
AT+QIOTMODELRDRead TSL Data Issued by Developer Center

Note: See Data Interaction Commands for details.

Procedure

Operation on Developer Center

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 a Product

For details about product creation, see Create a Product.

Operation on Device

TSL Data Interaction

TSL is a data model established by Developer Center for physical devices, which is used to describe product features to facilitate data parsing. You can execute AT+QIOTMODELTD and AT+QIOTMODELRD to make the device interact with Developer Center after the device successfully accesses Developer Center.

Feature IDTypeFeature NameData TypeValue RangeReferenceExample
1PropertySwitchBOOLTRUE: On FALSE: Off{"1":true}
2PropertyBattery LevelINT0–100{"2":100}
3PropertyRemaining Content of Essential OilFLOAT0–300{"3":25.6}
4PropertyWorking ModeENUM1–HPC 2–CPL{"4":1}
5PropertyDevice IDTEXT0–20{"5":"ZWS"}
6PropertyTimeDATE--{"6":1659664758817}
7PropertyStructureSTRUCT--Feature IDs: 8, 9
{"7":{"8":true,"9":100}}
8 (parent feature ID: 7)Parameter {$Parameter} BOOLTRUE: On FALSE: Off
9 (parent feature ID: 7)Parameter {$Parameter} INT0–100
10PropertyInteger ArrayARRAYMaximum quantity: 10 Element type: INT"10":[10,20,30]
11PropertyStructure ArrayARRAYFeature IDs: 12, 13{"11":[{"12":true,"13":100},{"12":false,"13":98}]}
12 (parent feature ID: 11)Parameter {$Parameter} BOOLTRUE: On FALSE: Off
13 (parent feature ID: 11)Parameter {$Parameter} INT0–100

Example 1 (Send TSL data in JSON format)

1) Set data format to JSON

MCU can configure TSL data format by AT+QIOTCFG="tsl"[,<tsl_mode>] . If the optional parameter is not set, the data format defaults to 0: TTLV.

c
[TX]AT+QIOTCFG="tsl",1

[RX]AT+QIOTCFG="tsl",1

OK

2) Send TSL data in JSON format

Send 149-byte TSL data {"1":true,"2":100,"3":25.6,"4":1,"5":"ZWS","6":1659664758817,"7":{"8":true,"9":100},"10":[10,20,30],"11":[{"12":true,"13":100},{"12":false,"13":98}]}. If QoS = 1, the module executes AT+QIOTMODELTD=1,149. After > is returned, MCU sends the TSL data to the module.

c
[TX]AT+QIOTMODELTD=1,149
[RX]>
[TX]{"1":true,"2":100,"3":25.6,"4":1,"5":"ZWS","6":1659664758817,"7":{"8":true,"9":100},"10":[10,20,30],"11":[{"12":true,"13":100},{"12":false,"13":98}]}
[RX]OK

[RX]+QIOTEVT: 4,10210

Note: If QoS = 1 or 2, the module will return OK and report +QIOTEVT: 4,10210 after sending data successfully. If QoS = 0, the module will return OK but not report any event after sending data successfully.

Example 2 (MCU replies to the request for TSL data from Developer Center according to PkgID)

1) Developer Center reads real-time TSL data in batches

On the "Device Debug" tab of the "Device Details" page, click "Read Data in Batches" to read TSL property value in batches.

2) The module receives the Read Command and prints the event code to MCU

  • Parse the event code: +QIOTEVT: 5,10211,1,1,2,3,4,5,6,7,10,11

    5: Event type indicating that the downlink data was received.

    10211: Event code indicating that the MCU received the TSL read command issued by Developer Center.

    1: Package ID, which is only valid when the module replies to Developer Center with TSL data after receiving the reading request.

    1,2,3,4,5,6,7,10,11: Feature IDs of TSL properties to be read, i.e. 1, 2, 3, 4, 5, 6, 7, 10, 11.

3) MCU determines the returned pkgID and the real-time data of TSL ID according to the event code

c
[TX]AT+QIOTMODELTD=1,149,7
[RX]>
[TX]{"1":true,"2":100,"3":25.6,"4":1,"5":"ZWS","6":1659664758817,"7":{"8":true,"9":100},"10":[10,20,30],"11":[{"12":true,"13":100},{"12":false,"13":98}]}
[RX]OK

[RX]+QIOTEVT: 4,10210

Note: If QoS = 1 or 2, the module will return OK and report +QIOTEVT: 4,10210 after sending data successfully. If QoS = 0, the module will return OK but not report any event after sending data successfully.

Example 3 (Report TSL alert event)

Feature IDTypeFeature NameData TypeValue RangeReference
14EventAlert to lack of essential oilBOOLOutput feature IDs: 15, 16
15 (parent ID: 14)ParameterBattery LevelINT0–100
16 (parent ID: 14)ParameterRemaining Content of Essential OilFLOAT0–300

MCU executes AT+QIOTMODELTD to report TSL data to Developer Center. After ">" is sent from the module, MCU will send the organized TSL data.

c
[TX]AT+QIOTMODELTD=2,28
[RX]>
[TX]{"14":{"15":100,"16":32.89}}
[RX]OK

+QIOTEVT: 4,10210

Note: If QoS = 1 or 2, the module will return OK and report +QIOTEVT: 4,10210 after sending data successfully. If QoS = 0, the module will return OK but not report any event after sending data successfully.

Example 4 (Read TSL data issued by Developer Center in unbuffered mode)

Feature IDTypeFeature NameData TypeValue RangeReference
17ServiceServiceBOOLOutput feature IDs: 18
18 (parent ID: 17)Input ParameterModeENUM0–2

The mode defaults to 0 (Disable buffer mode).

1) Developer Center issues TSL service

On the "Device Debug" page, click "Service Calls", then select the service to be issued, and click Send Command in the lower left corner.

2) The module receives the issued command and prints the event code and data to MCU

When the module receives the TSL service command, it will print event code +QIOTEVT: 5,10210,15 and the issued TSL service data {"17":{"18":1}} to MCU.

c
[RX]+QIOTEVT: 5,10210,15
{"17":{"18":1}}

Example 5 (Read TSL data issued by Developer Center in buffer mode)

1) Enable buffer mode for downlink data

MCU can configure the buffer mode for downlink data by AT+QIOTCFG="buffer"[,<buffer_mode>].

c
[TX]AT+QIOTCFG="buffer",1

[RX]AT+QIOTCFG="buffer",1

OK

2) Developer Center issues TSL service

On the "Device Debug" page, click "Service Calls", then select the service to be issued, and finally click Send Command in the lower left corner.

3) The module receives the issued command and prints the event to MCU

  • Parse the event code: +QIOTEVT: 5,10210

    5: Event type indicating that the downlink data was received.

    10210: Event code indicating that the TSL data issued by Developer Center was received.

4) MCU queries the service according to the event code

c
[TX]AT+QIOTMODELRD=512

[RX]AT+QIOTMODELRD=512

+QIOTMODELRD: 15,0,0
{"17":{"18":1}}
OK