### Cloud.getDeviceInfo() Example Source: https://www.thingscloud.xyz/docs/guide/rules/built-in-cloud-func.html Example of reading current device information. ```javascript { "id": "sw52w1ps", // 设备 ID "name": "DTU-5728", // 设备名称 "type": "dms60h1k", // 所属设备类型 ID "tags": {}, // 设备 Tags "device_key": "867135052265477", // 设备唯一标识符 "device_code": "82595616", // 设备码,用户可输入设备码或扫码添加设备 "sub_device_addr": "", // 子设备地址,仅对子设备有效。 "sub_device_addr_hex": "" // 子设备地址 HEX 格式,仅对 Modbus 子设备有效。 } ``` -------------------------------- ### Configuration Example for Sending Properties to Devices Source: https://www.thingscloud.xyz/docs/guide/automations/actions-overview.html This example demonstrates how to configure an action to send properties to a device, specifically setting the brightness of an indoor light by referencing the light value from an outdoor light sensor. ```text Action: Send Properties Device: Indoor Light Property: Brightness Operation: Reference Source Device: Outdoor Light Sensor Source Property: Light Value Effect: Indoor light brightness = Outdoor light sensor's light value ``` -------------------------------- ### HTTP GET Request Example Source: https://www.thingscloud.xyz/docs/basics/protocol/http-https.html A simple HTTP GET request example, showing the request method, URL, and host. ```http GET /index.html HTTP/1.1 Host: example.com ``` -------------------------------- ### unixTimestampMills Example Source: https://www.thingscloud.xyz/docs/guide/rules/built-in-cloud-func.html Examples of getting Unix timestamps in milliseconds. ```javascript Cloud.Utils.unixTimestampMills() // 当前时间戳(毫秒),例如:1703121965000 Cloud.Utils.unixTimestampMills("2023-01-01") // 1672502400000 Cloud.Utils.unixTimestampMills("2023-01-01 12:00") // 1672545600000 Cloud.Utils.unixTimestampMills("2023-01-01 12:00:00") // 1672545600000 ``` -------------------------------- ### Cloud.Utils.byteToBits Examples Source: https://www.thingscloud.xyz/docs/guide/rules/built-in-cloud-func.html Examples demonstrating the conversion of an 8-bit unsigned integer to a byte's binary sequence. ```javascript Cloud.Utils.byteToBits(1) // [0,0,0,0,0,0,0,1] Cloud.Utils.byteToBits(3) // [0,0,0,0,0,0,1,1] Cloud.Utils.byteToBits(15) // [0,0,0,0,1,1,1,1] ``` -------------------------------- ### unixTimestamp Example Source: https://www.thingscloud.xyz/docs/guide/rules/built-in-cloud-func.html Examples of getting Unix timestamps in seconds. ```javascript Cloud.Utils.unixTimestamp() // 当前时间戳(秒),例如:1703121965 Cloud.Utils.unixTimestamp("2023-01-01") // 1672502400 Cloud.Utils.unixTimestamp("2023-01-01 12:00") // 1672545600 Cloud.Utils.unixTimestamp("2023-01-01 12:00:00") // 1672545600 ``` -------------------------------- ### Arduino IDE Library Manager Installation Source: https://www.thingscloud.xyz/docs/tutorials/connect-device/esp32-arduino-sdk.html Install the ThingsCloud_ESP_SDK via the Arduino Library Manager. ```text ThingsCloud ``` -------------------------------- ### Example: Publishing Temperature and Humidity Data Source: https://www.thingscloud.xyz/docs/guide/connect-device/mqtt.html Example of a device publishing both temperature and humidity data for the same timestamp. ```json [ {"ts": 1714534200, "values": { "temperature": 22.5, "humidity": 68.3 } }, ] ``` -------------------------------- ### Example: Publishing Temperature Data Source: https://www.thingscloud.xyz/docs/guide/connect-device/mqtt.html Example of a device publishing temperature data for a specific past timestamp. ```json [ {"ts": 1714534200, "values": { "temperature": 22.5 } }, ] ``` -------------------------------- ### Example of get attribute topic with ID Source: https://www.thingscloud.xyz/docs/guide/connect-device/mqtt.html An example of the 'attributes/get/' topic with a specific ID. ```mqtt attributes/get/1000 ``` -------------------------------- ### Example 4: Lifecycle Event (Device Startup) Source: https://www.thingscloud.xyz/docs/guide/device-manage/device-events.html An example of a lifecycle event message reported when a device starts up or restarts. ```JSON { "method": "device_startup", "params": { "firmware_version": "v2.1.0", "boot_reason": "power_on", "ip_address": "192.168.1.100", "rssi": -65 } } ``` -------------------------------- ### Example: Send device code when the device boots up Source: https://www.thingscloud.xyz/docs/guide/rules/attrs-rpt.html This cloud function example demonstrates how to send a device code to a device upon boot-up. It checks for the 'start_ts' attribute (indicating boot time) and then uses `Cloud.getDeviceInfo()` to retrieve the device's code, which is then sent as the 'device_code' attribute. ```javascript module.exports = function (report_attributes) { /** * report_attributes: 上报的属性对象,作为函数参数传入 * push_attributes: 构造下发的属性对象,作为函数返回值,下发到硬件 */ var push_attributes = {}; // 判断设备是否上报了开机时间戳,仅在开机时下发设备码 if (report_attributes.start_ts !== undefined) { // 获取当前设备信息 var device_info = Cloud.getDeviceInfo(); // 将设备码下发给设备 push_attributes.device_code = device_info.device_code; } return push_attributes; } ``` -------------------------------- ### Cloud.Utils.bitsToByte Examples Source: https://www.thingscloud.xyz/docs/guide/rules/built-in-cloud-func.html Examples demonstrating the conversion of a byte's binary sequence to an unsigned integer. ```javascript Cloud.Utils.bitsToByte([0,0,0,0,0,0,0,1]) // 1 Cloud.Utils.bitsToByte([0,0,0,0,0,0,1,1]) // 3 Cloud.Utils.bitsToByte([0,0,0,0,1,1,1,1]) // 15 ``` -------------------------------- ### Cloud.Utils.dateStartOf Source: https://www.thingscloud.xyz/docs/guide/rules/built-in-cloud-func.html Gets the start time of a specified time unit. ```javascript Cloud.Utils.dateStartOf("month", "YYYY-MM-DD HH:mm:ss") // 2023-01-01 00:00:00 Cloud.Utils.dateStartOf("day", "YYYY-MM-DD") // 2023-01-10 ``` -------------------------------- ### Read Holding Registers Request Example Source: https://www.thingscloud.xyz/docs/basics/protocol/modbus-tcp.html An example of a Modbus TCP request to read 3 holding registers starting from address 100. ```plaintext 00 01 00 00 00 06 01 03 00 64 00 03 ``` -------------------------------- ### 克隆仓库 Source: https://www.thingscloud.xyz/docs/tutorials/connect-device/esp32-micropython-sdk-tutorials.html 克隆 SDK 仓库或直接下载 Python 文件。 ```bash # 克隆仓库 git clone https://github.com/IoT-ThingsCloud/thingscloud-micropython-sdk.git # 或直接下载 thingscloud_mqtt_lib.py 文件 ```