Bladeren bron

kawaii mqtt release v1.1.0 ...

jiejietop 5 jaren geleden
bovenliggende
commit
05b39e8253
3 gewijzigde bestanden met toevoegingen van 24 en 20 verwijderingen
  1. 6 6
      common/mqtt_log.h
  2. 8 1
      platform/RT-Thread/platform_timer.c
  3. 10 13
      test/test.c

+ 6 - 6
common/mqtt_log.h

@@ -10,6 +10,12 @@
 
 #include "mqtt_defconfig.h"
 
+#define KAWAII_MQTT_LOG_BASE_LEVEL      (0)
+#define KAWAII_MQTT_LOG_ERR_LEVEL       (KAWAII_MQTT_LOG_BASE_LEVEL + 1)
+#define KAWAII_MQTT_LOG_WARN_LEVEL      (KAWAII_MQTT_LOG_ERR_LEVEL + 1)
+#define KAWAII_MQTT_LOG_INFO_LEVEL      (KAWAII_MQTT_LOG_WARN_LEVEL + 1)
+#define KAWAII_MQTT_LOG_DEBUG_LEVEL     (KAWAII_MQTT_LOG_INFO_LEVEL + 1)
+
 #ifdef KAWAII_MQTT_LOG_IS_SALOF
     #include "salof.h"
 
@@ -21,12 +27,6 @@
 #else
     #include <stdio.h>
     
-    #define KAWAII_MQTT_LOG_BASE_LEVEL      (0)
-    #define KAWAII_MQTT_LOG_ERR_LEVEL       (KAWAII_MQTT_LOG_BASE_LEVEL + 1)
-    #define KAWAII_MQTT_LOG_WARN_LEVEL      (KAWAII_MQTT_LOG_ERR_LEVEL + 1)
-    #define KAWAII_MQTT_LOG_INFO_LEVEL      (KAWAII_MQTT_LOG_WARN_LEVEL + 1)
-    #define KAWAII_MQTT_LOG_DEBUG_LEVEL     (KAWAII_MQTT_LOG_INFO_LEVEL + 1)
-
 #if KAWAII_MQTT_LOG_LEVEL < KAWAII_MQTT_LOG_DEBUG_LEVEL
     #define KAWAII_MQTT_LOG_D(fmt, ...)
 #else

+ 8 - 1
platform/RT-Thread/platform_timer.c

@@ -55,5 +55,12 @@ unsigned long platform_timer_now(void)
 
 void platform_timer_usleep(unsigned long usec)
 {
-    rt_thread_mdelay(usec);
+    uint32_t ms = 0;
+    if(usec != 0) {
+        ms = usec / 1000;
+        if (ms == 0) {
+            ms = 1;
+        }
+    }
+    rt_thread_mdelay(ms);
 }

+ 10 - 13
test/test.c

@@ -28,16 +28,16 @@ static int mqtt_publish_handle1(mqtt_client_t *client)
     memset(&msg, 0, sizeof(msg));
 
     msg.qos = QOS0;
-    msg.payload = (void *) "T2MB7TIlYNL7F5pJ4Qp0";
+    msg.payload = (void *)"this is a kawaii mqtt test ...";
 
-    return mqtt_publish(client, "sub_topic1", &msg);
+    return mqtt_publish(client, "rtt-topic", &msg);
 }
 
 
 int main(void)
 {
     mqtt_client_t *client = NULL;
-
+    
     rt_thread_delay(6000);
     
     mqtt_log_init();
@@ -46,21 +46,18 @@ int main(void)
 
     mqtt_set_host(client, "www.jiejie01.top");
     mqtt_set_port(client, "1883");
-    mqtt_set_user_name(client, "FoBxDRFwe6");
-    mqtt_set_password(client, "EDgftkg6rY");
-    mqtt_set_client_id(client, "5PtUa6aJ5h");
+    mqtt_set_user_name(client, "rt-thread");
+    mqtt_set_password(client, "rt-thread");
+    mqtt_set_client_id(client, "rt-thread");
     mqtt_set_clean_session(client, 1);
-    mqtt_set_keep_alive_interval(client, 50);
-    mqtt_set_cmd_timeout(client, 5000);
-    mqtt_set_read_buf_size(client, 2048);
-    mqtt_set_write_buf_size(client, 2048);
 
     mqtt_connect(client);
-    mqtt_subscribe(client, "sub_topic1", QOS0, sub_topic_handle1);
-
+    
+    mqtt_subscribe(client, "rtt-topic", QOS0, sub_topic_handle1);
+    
     while (1) {
         mqtt_publish_handle1(client);
-                                                                                
+                               
         mqtt_sleep_ms(4 * 1000);
     }
 }