找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1816|回复: 0
打印 上一主题 下一主题
收起左侧

MQTT-relay-sdk-v21程序源码

[复制链接]
跳转到指定楼层
楼主
ID:384304 发表于 2018-10-17 13:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
MQTT程序

单片机源程序如下:
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "stdint.h"
  4. #include "string.h"
  5. #include "system.h"
  6. #include "sys.h"
  7. #include "usart.h"
  8. #include "sim900a.h"
  9. #include "relay.h"
  10. #include "mqtt-user.h"
  11. #include "timer.h"
  12. #include "timer_task.h"
  13. #include "frozen.h"
  14. #include "parameter.h"
  15. #include "ctype.h"
  16. #include "MQTTPacket.h"

  17. /* 需要在这里更改服务器地址端口,用户名密码等信息 */
  18. /* 设备默认会将IMEI(SIM800C模块上的标号)设置为clientID */
  19. /*  */
  20. #define MQTT_SERVER_IP  "relay.mqtt.iot.gz.baidubce.com"
  21. #define MQTT_SERVER_PORT        "1883"

  22. char client_id[128] = {0};
  23. char user_name[128] = {"relay/relay"};
  24. char password[128] = {"Zqu9im83wlVp8++FgyVJb9d+J4EKd4ytXpa9w02N2hE="};
  25. char topic[64] = {"relay"};

  26. int main(void)
  27. {
  28.     SystemInit();
  29.     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  30.     delay_init();
  31.     usart1_init(921600);
  32.     usart3_init(115200);
  33.     timer3_init(10000, 7199);//10Khz的计数频率,计数到10000为1s
  34.     sim900a_gpio_init();
  35.     relay_init();
  36.     relay_on();
  37.    
  38.     sim900a_user_config();
  39.     sim900a_get_imei(client_id);   
  40.    
  41.     printf("\n*******MQTT INFO************\n");
  42.     printf("CLIENT ID:%s\n", client_id);
  43.     printf("USER NAME:%s\n", user_name);
  44.     printf("PASSWORD:%s\n", password);
  45.     printf("*******END************\n");

  46.     mqtt_connection_init(MQTT_SERVER_IP, MQTT_SERVER_PORT, client_id, user_name, password);
  47.     mqtt_subscribe(topic, 0);

  48.     while(1) {
  49.         while (!mqtt_state.connected || mqtt_state.error_count > 1) {
  50.             mqtt_connection_init(MQTT_SERVER_IP, MQTT_SERVER_PORT, client_id, user_name, password);
  51.             delay_ms(500);
  52.             sim900a_cmd_with_reply("AT+CIPSTATUS", "OK", NULL, GSM_CMD_WAIT_NORMAL);
  53.             mqtt_subscribe(topic, 0);
  54.             mqtt_send_beat("topic_server", curr_state);
  55.         }
  56.         user_task_loop();
  57.     }
  58. }
复制代码

所有资料51hei提供下载:
mqtt-relay-sdk-v21.zip (387.68 KB, 下载次数: 31)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶1 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表