广和通L610_ADP对腾讯云通信笔记——01

本文记录了广和通L610模块通过AT指令从开机到设备在线的过程,包括连接腾讯云、订阅下行消息及上报属性的操作。还介绍了腾讯云如何下发控制指令和设备如何响应并上报属性。

从开机到设备在线的AT指令:

AT+CPIN?
AT+CSQ
AT+CGREG?
AT+MIPCALL=1
AT+MIPCALL?
AT+TCDEVINFOSET=1,“IGA6ZV5NNK”,“lamp_01”,“n41ziNuSI2jyY3jbYh1HvQ==” //需要替换成当前的设备密钥
AT+TCMQTTCONN=1,20000,240,1,1 //连接
AT+TCMQTTSUB="$thing/down/property/IGA6ZV5NNK/lamp_01",1 //订阅下行

下发信息:

腾讯云下发控制指令:

下发控制指令:2021-12-05 16:05:10.945
{
   
   
  "method": "control",
以下是基于STM32广L610通信模组与腾讯云连接的代码示例: ```c #include "stm32f10x.h" #include "gprs.h" #include "string.h" #include "stdio.h" #define APN "CMNET" #define USER "" #define PASS "" #define IP "mqtt.tencentdevices.com" #define PORT 1883 #define CLIENT_ID "my_client_id" #define USERNAME "my_username" #define PASSWORD "my_password" #define MQTT_TOPIC "/my_topic" #define MQTT_QOS 0 #define GPRS_RX_BUF_SIZE 1024 #define GPRS_TX_BUF_SIZE 1024 uint8_t gprs_rx_buf[GPRS_RX_BUF_SIZE]; uint8_t gprs_tx_buf[GPRS_TX_BUF_SIZE]; uint8_t mqtt_rx_buf[GPRS_RX_BUF_SIZE]; uint8_t mqtt_tx_buf[GPRS_TX_BUF_SIZE]; int main(void) { uint8_t ip[16]; uint16_t port; uint8_t client_id[32]; uint8_t username[32]; uint8_t password[32]; uint8_t topic[64]; // 初始化GPRS模块 gprs_init(gprs_rx_buf, GPRS_RX_BUF_SIZE, gprs_tx_buf, GPRS_TX_BUF_SIZE); // 连接GPRS网络 if (!gprs_connect(APN, USER, PASS)) { printf("GPRS connect failed!\n"); while (1); } // 获取IP地址端口号 if (!gprs_get_ip_port(IP, PORT, ip, &port)) { printf("Get IP and port failed!\n"); while (1); } // 连接MQTT服务器 if (!mqtt_connect(ip, port, client_id, username, password)) { printf("MQTT connect failed!\n"); while (1); } // 发布消息 if (!mqtt_publish(MQTT_TOPIC, MQTT_QOS, "Hello, world!")) { printf("MQTT publish failed!\n"); while (1); } // 订阅消息 if (!mqtt_subscribe(MQTT_TOPIC, MQTT_QOS)) { printf("MQTT subscribe failed!\n"); while (1); } // 接收消息 mqtt_receive(mqtt_rx_buf, GPRS_RX_BUF_SIZE); // 断开MQTT连接 mqtt_disconnect(); // 断开GPRS连接 gprs_disconnect(); while (1); } ``` 其中,`gprs_init`、`gprs_connect`、`gprs_get_ip_port`、`gprs_disconnect`是自定义的GPRS模块初始化、连接、获取IP地址端口号、断开连接函数;`mqtt_connect`、`mqtt_publish`、`mqtt_subscribe`、`mqtt_receive`、`mqtt_disconnect`是自定义的MQTT连接、发布消息、订阅消息、接收消息、断开连接函数。你需要根据你使用的GPRS模块MQTT库进行相应的修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值