標(biāo)題: STM32 W5500 MQTT源程序 [打印本頁]

作者: dysuperman    時間: 2020-4-24 15:01
標(biāo)題: STM32 W5500 MQTT源程序
對剛學(xué)MQTT的師兄有幫助

單片機源程序如下:
  1. #include "usart.h"
  2. #include "device.h"
  3. #include "spi2.h"
  4. #include "ult.h"
  5. #include "socket.h"
  6. #include "w5500.h"
  7. #include "24c16.h"
  8. #include "md5.h"
  9. #include "mqtt.h"
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>

  13. extern uint8 txsize[];                                                                                // 引用外部變量,聲明Socket發(fā)送緩存大小
  14. extern uint8 rxsize[];                                                                                // 引用外部變量,聲明Socket接收緩存大小

  15. uint8_t domain_ip[4]={192,168,1,106};//115,29,225,215
  16. uint8_t domain_name[]="www.embed-net.com";

  17. uint8 buffer[2048];// 定義一個2KB的數(shù)組,用來存放Socket的通信數(shù)據(jù)

  18. int main(void)
  19. {
  20.         static char meassage[200];
  21.         int rc=0;
  22.   /***** MCU時鐘初始化 *****/                                                          
  23.         Systick_Init(72);
  24.         /***** 中斷控制器配置 *****/
  25.         NVIC_Configuration();
  26.         /*****TIM2 定時配置****/
  27.         TIM2_Configuration();
  28.         /* 實戰(zhàn)定時器的中斷優(yōu)先級 */
  29.         TIM2_NVIC_Configuration();
  30.         /***** GPIO、SPI初始化 *****/
  31.         GPIO_Configuration();                       
  32.         WIZ_SPI_Init();
  33.         /***** 串口初始化 *****/
  34.         USART1_Init();
  35.         /***** 初始化eeprom *****/
  36.   at24c16_init();
  37.         /***** 硬重啟W5500 *****/
  38.         Reset_W5500();
  39.         /***** W5500的IP信息初始化 *****/
  40.         set_default();// 設(shè)置默認(rèn)MAC、IP、GW、SUB、DNS
  41.         set_network();// 配置初始化IP信息并打印,初始化8個Socket
  42.        
  43.         /***** 打開W5500的Keepalive功能 *****/
  44.         //setkeepalive(0);
  45.        
  46.         printf("W5500 Init Complete!\r\n");
  47.   printf("Start TCP Client Test!\r\n");

  48.   srand(0);       

  49.         while(1)
  50.         {
  51.                 if(rc==0)
  52.                 {
  53.                         memset(meassage,0,sizeof(meassage));
  54.                   do_mqtt_subscrib("wizled",meassage);//訂閱主題pyboard_led
  55.                         rc++;
  56.                         printf("%d\n\r",rc);
  57.           }
  58.   }
  59. }
復(fù)制代碼

所有資料51hei提供下載:
STM32 W5500 MQTT.7z (1.87 MB, 下載次數(shù): 140)



作者: hank007    時間: 2021-7-16 11:30
剛好要做這方面的應(yīng)用。謝謝樓主




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1