<p><iframe name="ifd" src="https://mnifdv.cn/resource/cnblogs/ZLCH579M/Air724UG/my.html" frameborder="0" scrolling="auto" width="100%" height="1500"></iframe></p>
<iframe frameborder="0" height="1500" name="ifd" scrolling="auto" src="https://mnifdv.cn/resource/cnblogs/ZLCH579M/Air724UG/my.html" width="100%"></iframe>
#include "mqtt.h" /*MQTT*/ char mqtt_connect_flag=0;//1:Á¬½ÓÉÏMQTT·þÎñÆ÷; 0:δÁ¬½ÓÉÏMQTT·þÎñÆ÷ char mqtt_client_id[50] = "11223344";//ClientID char mqtt_username[20] = "yang";//Óû§Ãû char mqtt_password[50] = "11223344";//ÃÜÂë char mqtt_keepalive = 30;//ÐÄÌø°üʱ¼ä /**¶©ÔÄÖ÷Ìâ³É¹¦**/ void subscribedCb(int pdata){ printf("\r\n³É¹¦¶©ÔÄÖ÷Ìâ\r\n"); } /**¶©ÔÄÖ÷Ìâʧ°Ü**/ void failsubscribedCb(int pdata){ printf("\r\n¶©ÔÄÖ÷Ìâʧ°Ü\r\n"); } /**·¢²¼³É¹¦**/ void PublishedCb(){ printf("\r\n·¢²¼³É¹¦\r\n"); } /*Á¬½ÓÉÏMQTT»Øµ÷º¯Êý*/ void MqttConnect(){ printf("\r\nÁ¬½Ó³É¹¦**********************************************************\r\n"); mqtt_connect_flag = 1; } /**MQTT¶Ï¿ªÁ¬½Ó»Øµ÷**/ void MqttDisConnect(){ printf("\r\nÁ¬½Ó¶Ï¿ª**********************************************************\r\n"); mqtt_init(&mymqtt); mqtt_connect_flag=0; } /** * @brief MQTT½ÓÊÕÊý¾Ý»Øµ÷ * @param topic:Ö÷Ìâ * @param topic_len:Ö÷Ìⳤ¶È * @param data:½ÓÊÕµÄÊý¾Ý * @param lengh:½ÓÊÕµÄÊý¾Ý³¤¶È * @retval None * @warning None * @example **/ void MqttReceive(const char* topic, uint32_t topic_len,const char *data, uint32_t lengh) { } /*MQTT*/ mqtt_init(&mymqtt); mqtt_connect_reg(&mymqtt,MqttConnect);//×¢²áÁ¬½Ó»Øµ÷º¯Êý mqtt_disconnect_reg(&mymqtt,MqttDisConnect);//×¢²á¶Ï¿ªÁ¬½Ó»Øµ÷º¯Êý mqtt_received_reg(&mymqtt,MqttReceive);//×¢²á½ÓÊÕÊý¾Ý»Øµ÷º¯Êý
//Á¬½ÓÉÏMQTT·þÎñÆ÷ if(mqtt_connect_flag) { mqtt_send_function(&mymqtt);//ÌáÈ¡·¢ËÍ»º´æµÄMQTTÐÒé mqtt_keep_alive(&mymqtt);//´¦Àí·¢ËÍÐÄÌø°ü }
/*³¬¹ýÁ¬½Ó´ÎÊý,ÖØÐÂÅäÖÃÄ£×éÁ¬½ÓTCP*/ mqtt_connect_cnt++; if(mqtt_connect_cnt>3) { mqtt_connect_cnt=0; mqtt_connect_flag=0; /*ÖØÐÂÅäÖÃÄ£¿éÁ¬½ÓTCP*/ ConfigModuleNoBlockCaseValue=0; ConfigModuleNoBlockFlage = 0; }