当前位置:网站首页>Tencent cloud Internet of things - gateway device experience
Tencent cloud Internet of things - gateway device experience
2022-04-22 07:04:00 【Quietly flowing kerxi】
sdk Code, please click here obtain
Introduction to gateway equipment
about BLE、Zigbee and 485 And other devices that do not have direct access to the network , You need to access the gateway first , Then through the gateway proxy , Indirectly realize equipment access to Tencent Internet of things development platform IoT Explorer, The specific process framework is as follows :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-laOq4Nby-1650454646545)(https://main.qcloudimg.com/raw/f419fff3725378c770b7264ddb93b170.svg)]
So for a gateway device , Its basic Core functions yes :
-
The gateway device itself is a fully functional Tencent cloud Internet of things development platform device . When not acting as a sub device agent , The gateway device can be operated as a device of an ordinary Tencent cloud Internet of things development platform . Many beginners have a misunderstanding , The gateway device is used to communicate with the proxy sub device , It has no business communicating with the platform , This understanding is totally wrong . for instance : The gateway device can be a built-in 433 Wireless transceiver WiFi Smart socket , So as a socket , You should first have the function of socket switch , Then it's around the agent 433 Sub equipment online and offline .
-
Dynamic binding / Unbound sub equipment . Obviously , To bind and unbind a subdevice is to establish a topology relationship between the subdevice and the gateway . for instance : Like children and fathers , A father may have two or three children , Then the father should be responsible for the child's clothing, food, housing and transportation , And for other unrelated children , Then the father is not responsible . Binding is equivalent to recognizing the parent-child relationship , Unbound is equivalent to severing the relationship between father and son . Yes, of course , In the real world , This parent-child relationship is not dynamic .
-
Agent sub equipment online and offline . for instance , When a Bluetooth gateway scans the Bluetooth broadcast of nearby sub devices and establishes a connection , You can notify the cloud platform through the gateway , There are currently sub devices active , Can go online . alike , When a sub device does not communicate with the Bluetooth gateway for a long time and sends a message without reply ( The specific offline strategy can be defined by yourself , Such as : No sub device message is received within one hour and ping No sub equipment ) It can be considered that the current sub equipment is offline , So as to notify the offline sub equipment of the cloud platform .
-
Agent sub device communication . This function is the meaning of gateway equipment , The reason why gateway devices are needed is to proxy some data that cannot be directly connected to Internet of things devices . The gateway functions as a messenger here . The gateway device of Tencent cloud Internet of things is completely transparent to the messages of sub devices . for instance , We know that the attributes of Tencent cloud IOT development platform are through this
mqtt topicTo transmit :- Data up Topic( For publishing ):
$property/up/${productid}/${devicename} - Data down Topic( To subscribe to ):
$property/down/${productid}/${devicename}
Then the gateway will not reuse other topic To transmit the data of the sub equipment . let me put it another way , Binding between gateway product and sub product , Get the name of the sub device Topic After permission , Gateway devices can use sub devices Topic The agent sends and receives messages , At the same time, it can be debugged in the equipment - Check the communication information in the device log .
- Data up Topic( For publishing ):
-
Agent sub device upgrade . The sub equipment also needs to update the firmware , Then the gateway device can pull down the firmware of the sub device from the background , Then send it to the sub equipment for upgrading , The whole process is shown in the figure :

The same as ordinary equipment upgrade is , The whole upgrading process will follow the same process as that of ordinary equipment upgrading , Including version reporting 、 upgrade url Acquisition of and so on . however , Unlike ordinary device upgrades , The gateway device needs to save the firmware of the sub device before upgrading the sub device , Then through a private agreement ( It can be BLE zigbee 433 wait ) Send firmware to sub devices , After obtaining the upgrade status of the sub device , Then tell the cloud platform the result of the upgrade .
Specific gateway sub device topology relationship management protocol , Please click on here obtain .
Gateway device code design
Understand the functions of gateway devices , Let's think about how to design the gateway code , Then take a look at the device side of Tencent cloud Internet of things development platform sdk How to design the gateway function .
First , The number of sub devices is unknown , Some gateways may bring 3 Sub devices , Some may bring 30 individual , So when designing the gateway , You need to consider using the list function to manage sub devices . secondly , The gateway device must have the function of managing sub devices , That is, you can bind and unbind the child devices by proxy 、 Online and offline data communication, etc ; This requires maintaining the status of the sub equipment . Let's take a look at the structure of the gateway structure :
typedef struct {
void *mqtt_client; // The gateway is based on mqtt Protocol to design , Here's a maintenance mqtt client
MQTTEventHandler evt_handle; // Sub device event callback , Including binding / Unbundling Notify the user when going online or offline
GatewayClientPriv *priv; // List of sub equipment
void *event_context; // Callback Arguments
gateway_event_handle_cb_t gateway_evt_cb; // Callback function
char gateway_pub_topic[MAX_SIZE_OF_GATEWAY_PUB_TOPIC]; // store gateway pub topic
} GatewayClient;
Let's take a look at the structure of the equipment :
typedef enum {
GATEWAY_SUBDEV_STATUS_ONLINE = 0,
GATEWAY_SUBDEV_STATUS_OFFLINE,
} GatewaySubStatus;
// Sub equipment structure
typedef struct {
DeviceInfo dev_info; // Sub equipment information , Products including sub equipment ID Equipment name, etc
GatewaySubStatus status; // Sub equipment status
int is_binded; // Is it bound
void *node; // Linked list
} GatewaySub;
Demo Log analysis
After the gateway equipment is powered on , Will use their own triple information to connect to Tencent cloud Internet of things development platform
INF|2022-04-20 17:48:42|mqtt_client.c|_qcloud_iot_mqtt_client_init(213): SDK_Ver: 4.0.0, Product_ID: 40FA6IALWV, Device_Name: gateway001
DBG|2022-04-20 17:48:42|qcloud_iot_tls_client.c|qcloud_iot_tls_client_connect(212): Setting up the SSL/TLS structure...
DBG|2022-04-20 17:48:42|qcloud_iot_tls_client.c|qcloud_iot_tls_client_connect(252): Performing the SSL/TLS handshake...
DBG|2022-04-20 17:48:42|qcloud_iot_tls_client.c|qcloud_iot_tls_client_connect(253): Connecting to /40FA6IALWV.iotcloud.tencentdevices.com/8883...
DBG|2022-04-20 17:48:43|qcloud_iot_tls_client.c|qcloud_iot_tls_client_connect(281): connected with /40FA6IALWV.iotcloud.tencentdevices.com/8883...
INF|2022-04-20 17:48:43|mqtt_client.c|IOT_MQTT_Construct(329): mqtt connect with id: C81F6 success
INF|2022-04-20 17:48:43|gateway_sample.c|main(303): Cloud Device Construct Success
After successful connection , Will subscribe to the gateway topic, Accept gateway downlink messages
DBG|2022-04-20 17:48:43|mqtt_client_subscribe.c|qcloud_iot_mqtt_subscribe(329): subscribe topic_name=$gateway/operation/result/40FA6IALWV/gateway001|packet_id=7041
INF|2022-04-20 17:48:43|gateway_sample.c|_mqtt_event_handler(75): subscribe success, packet-id=7041
send out describe_sub_devices news , Pull the topology relationship of the current gateway device from the cloud platform
DBG|2022-04-20 17:48:43|mqtt_client_publish.c|qcloud_iot_mqtt_publish(264): publish qos=0|packet_id=0|topic_name=$gateway/operation/40FA6IALWV/gateway001|payload={
"type":"describe_sub_devices"}
Cloud platform reply :
DBG|2022-04-20 17:48:43|gateway_message_handle.c|gateway_message_handler(204): receive gateway message {
"type":"describe_sub_devices","payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev001"},{
"product_id":"KRLT1QGQW5","device_name":"subdev002"},{
"product_id":"KRLT1QGQW5","device_name":"subdev003"},{
"product_id":"KRLT1QGQW5","device_name":"subdev004"}]}}
At present, four sub devices have been bound to the gateway device .
Bind sub devices
Binding a sub device requires the gateway device to know the triple information of the sub device , This triple information can be obtained from the sub device , Or get it from the cloud platform . After getting the triple information , The gateway device needs to make a signature locally , Generate signature Field .
DBG|2022-04-20 17:48:43|gateway_sub_manage.c|IOT_Gateway_AddSub(332): Add 0x5647bd29fb70 KRLT1QGQW5:subdev006
DBG|2022-04-20 17:48:43|mqtt_client_publish.c|qcloud_iot_mqtt_publish(264): publish qos=0|packet_id=0|topic_name=$gateway/operation/40FA6IALWV/gateway001|payload={
"type":"bind",
"payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev006","signature":"+j45scCBXI9qCDioF7m1NB4VuOU=","random":1603981974,"timestamp":1650448123,"signmethod":"hmacsha1","authtype":"psk"}]}}
Cloud platform reply :
DBG|2022-04-20 17:48:43|gateway_message_handle.c|gateway_message_handler(204): receive gateway message {
"type":"bind","payload":{
"devices":[{
"result":0,"product_id":"KRLT1QGQW5","device_name":"subdev006"}]}}
INF|2022-04-20 17:48:43|gateway_message_handle.c|gateway_message_handler(211): Get type 2 from server
DBG|2022-04-20 17:48:43|gateway_message_handle.c|_gateway_down_array_result_parse(113): bind device KRLT1QGQW5:subdev006
INF|2022-04-20 17:48:43|gateway_sample.c|_mqtt_event_handler(111): gateway topology changed --- subdev KRLT1QGQW5:subdev006 change to binded
At the same time, we also received a message _mqtt_event_handler Event to notify a new device to join the topology relationship of the current gateway device . When this device goes online , You can communicate normally on behalf of this sub device .
Unbound sub equipment
Unbinding is easier , Directly send the list of devices to be unbound to the cloud platform , At the same time, the topology relationship should also be updated locally
DBG|2022-04-20 17:49:02|mqtt_client_publish.c|qcloud_iot_mqtt_publish(264): publish qos=0|packet_id=0|topic_name=$gateway/operation/40FA6IALWV/gateway001|payload={
"type":"unbind", "payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev006"}]}}
Cloud platform reply :
DBG|2022-04-20 17:49:02|gateway_message_handle.c|gateway_message_handler(204): receive gateway message {
"type":"unbind","payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev006","result":0}]}}
INF|2022-04-20 17:49:02|gateway_message_handle.c|gateway_message_handler(211): Get type 3 from server
DBG|2022-04-20 17:49:02|gateway_message_handle.c|_gateway_down_array_result_parse(117): del device KRLT1QGQW5:subdev006
INF|2022-04-20 17:49:02|gateway_sample.c|_mqtt_event_handler(111): gateway topology changed --- subdev KRLT1QGQW5:subdev006 change to unbinded
At the same time, I received a message _mqtt_event_handler Event to notify that a device is unbound , The messages of this device should not be sent through the gateway proxy in the future .
The agent sub equipment goes online
DBG|2022-04-20 17:48:45|mqtt_client_publish.c|qcloud_iot_mqtt_publish(264): publish qos=0|packet_id=0|topic_name=$gateway/operation/40FA6IALWV/gateway001|payload={
"type":"online", "payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev001"}]}}
After the current sub equipment is successfully online , You can interact with the cloud platform .
Agent sub equipment offline
DBG|2022-04-20 17:48:51|mqtt_client_publish.c|qcloud_iot_mqtt_publish(264): publish qos=0|packet_id=0|topic_name=$gateway/operation/40FA6IALWV/gateway001|payload={
"type":"offline", "payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev001"}]}}
DBG|2022-04-20 17:48:51|gateway_sample.c|_test_array_cb(243): test return 0
DBG|2022-04-20 17:48:51|gateway_message_handle.c|gateway_message_handler(204): receive gateway message {
"type":"offline","payload":{
"devices":[{
"product_id":"KRLT1QGQW5","device_name":"subdev001","result":0}]}}
INF|2022-04-20 17:48:51|gateway_message_handle.c|gateway_message_handler(211): Get type 1 from server
INF|2022-04-20 17:48:51|gateway_sample.c|_mqtt_event_handler(117): gateway status changed --- subdev KRLT1QGQW5:subdev001 change to offline
At the same time, I received a message _mqtt_event_handler Event to notify that a device is offline , The information of the sub equipment should not be reported to the gateway in the future .
版权声明
本文为[Quietly flowing kerxi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220604319778.html
边栏推荐
- 环网冗余CAN光端机在保得威尔消防火灾报警系统中的应用
- If there is a design, it can improve the signal quality without increasing the cost
- STM32 定时器同步 触发 代码 实验 验证分享
- Before glide 4.0, glide set the round picture and set the round corner of the picture (four corners can be set together or some corners can be set separately)
- CS5202芯片规格书|CS5202替代CS5212|HDMI转VGA芯片
- [蓝桥杯复习] 生命之树
- Various commonly used tools status bar cache conversion to obtain app information clipboard file operation encryption and decryption operation
- MCS-5 中断技术(实践)
- 示波器只能测波形-格局小啦
- 沁恒CH573开发板上手
猜你喜欢

沁恒CH573开发板上手

Inverse Clark transform of PMSM FOC control MATLAB / Simulink simulation

911数据中不同月份不同类型的电话的次数的变化情况

SSS1700

DDR4信号参考电源层,阻抗会有影响吗?

Audio type 523 + VGA + 5 + HDC to 5 + VGA

阻抗标注你遇到崩溃吗?

示波器只能测波形-格局小啦

If there is a design, it can improve the signal quality without increasing the cost

一阶数字低通滤波器-C语言/matlab实现
随机推荐
Qt QFile 删除文件最后n个字节的数据
Glide conflicts with picture selector Matisse after 4.0.0
如果有一种设计不增加成本又能改善信号质量
HDMI2. Design circuit comparison between asw3642 and ts3dv642
It's hard to believe that this pair of high-speed signals have changed through holes so many times!!!
Rtd2171u scheme 𞓜 ag9310mfq replaces rtd2171u design circuit | typec to HDMI 4k30hz HD projection scheme design
It's nothing to be able to dismantle the host. Mr. expressway can also test it
Before glide 4.0, glide set the round picture and set the round corner of the picture (four corners can be set together or some corners can be set separately)
沁恒CH573开发板上手
PCB上邮票孔的添加方式,你真的做对了吗……
在消防联网(楼宇、工厂、海上风电、管廊等)中CAN光纤转换器、CAN总线光端机典型应用案例
USBCAN卡在动力电池组EOL测试系统中CAN总线的应用
Ag9310mcq supports the design reference circuit of mother seat forward and reverse plug typec to HDMI projection scheme
一阶数字低通滤波器-C语言/matlab实现
FreeRTOS v10.1.0源码中文注释版
Add files to the server
Very easy to use bar code and QR code recognition tool class zxing ZBar
Introduction to basic terms of machine learning
[蓝桥杯省赛] 负载均衡
我走过太多的路,却走不出DDRX调试的套路