tencent cloud

IoT Hub

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Features
Strengths
Use Cases
Use Limits
Basic Concepts
Getting Started
Quick Start
Scenario 1: Device Interconnection
Scenario 2: Device Status Reporting and Setting
MQTT.fx Connection Guide
Console Guide
Product Management
Rule Engine
Sub-account Access to IoT Hub
Firmware Upgrade
Resource Management
Certificate Management
Developer Manual
Feature Components
Signature Algorithm
Device Authentication
Device Connection Protocol
Gateway Subdevice
Message Communication
Device Shadow
Device Firmware Upgrade
Remote Device Configuration
Resource Management
Device Log Reporting
NTP Service
Device Connection Manual
Device Connection Overview
Connection Based on SDK for C
Connection Based on SDK for Android
Connection Based on SDK for Java
Connection Based on SDK for Python
API Documentation
History
Introduction
API Category
Making API Requests
Device Shadow APIs
Device APIs
CA Certificate APIs
Product APIs
Data Types
Error Codes
FAQs
General
Device Connection and Reporting
Rule Engine
Console
IoT Hub Policy
Privacy Policy
Data Privacy And Security Agreement
Glossary

SDK for Python Use Instructions

PDF
Focus Mode
Font Size
Last updated: 2024-12-27 17:03:43
In addition to the device connection feature, the SDK for Python also provides gateway subdevice and device shadow features with the following APIs.

MQTT APIs

MQTT APIs are defined in the hub.py class and support publishing and subscribing. If you want to support the device shadow feature, you need to use the shadow.py class and its methods as detailed below:
Method
Description
connect
Establishes MQTT connection
disconnect
Closes MQTT connection
subscribe
Subscribes to topic over MQTT
unsubscribe
Unsubscribes from topic over MQTT
publish
Publishes message over MQTT
registerMqttCallback
Registers MQTT callback function
registerUserCallback
Registers user callback function
isMqttConnected
Checks whether MQTT is normally connected
getConnectState
Gets MQTT connection status
setReconnectInterval
Sets MQTT reconnection attempt interval
setMessageTimout
Sets message sending timeout period
setKeepaliveInterval
Sets MQTT keepalive interval

MQTT Gateway APIs

Devices that don't have direct access to the Ethernet can be connected to the network of the local gateway device first and then connected to the IoT Hub platform through the communication feature of the gateway device.
For the subdevices that join or leave the LAN, they need to be bound or unbound through the platform.
Note:
After a subdevice is connected once, as long as the gateway is successfully connected subsequently, the backend will show that the subdevice is online until it is disconnected.
MQTT gateway APIs are defined in the gateway.py class as detailed below:
Method
Description
gatewayInit
Initializes gateway
isSubdevStatusOnline
Determines whether subdevice is connected
updateSubdevStatus
Updates subdevice's connection status
gatewaySubdevGetConfigList
Gets subdevice list from configuration file
gatewaySubdevOnline
Proxies subdevice connection
gatewaySubdevOffline
Proxies subdevice disconnection
gatewaySubdevBind
Binds subdevice
gatewaySubdevUnbind
Unbinds subdevice
gatewaySubdevSubscribe
Proxies subdevice subscription

Dynamic Registration APIs

If you want to use the dynamic registration feature, you need to use the APIs in the hub.py class as detailed below:
Method
Description
dynregDevice
Gets the dynamic registration information of device

OTA APIs

If you want to use the OTA feature, you need to use the APIs in the hub.py class as detailed below:
Method
Description
otaInit
Initializes OTA
otaIsFetching
Determines whether the download is in progress
otaIsFetchFinished
Determines whether the download is completed
otaReportUpgradeSuccess
Reports update success message
otaReportUpgradeFail
Reports update failure message
otaIoctlNumber
Gets the information of the downloaded firmware in int type, such as the size
otaIoctlString
Gets the information of the downloaded firmware in String type, such as MD5
otaResetMd5
Resets MD5 information
otaMd5Update
Updates MD5 information
httpInit
Initializes HTTP
otaReportVersion
Reports the information of current firmware version
otaDownloadStart
Starts firmware download
otaFetchYield
Reads firmware

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback