L475VG-IOT01A+WIFI+MQTT

Dependencies:   HTS221 VL53L0X BSP_B-L475E-IOT01 MQTT

Files at this revision

API Documentation at this revision

Comitter:
cornetlin
Date:
Tue Jan 05 17:59:51 2021 +0000
Parent:
1:5a9fdc848911
Commit message:
202101060159

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Dec 10 07:13:20 2019 +0000
+++ b/main.cpp	Tue Jan 05 17:59:51 2021 +0000
@@ -9,7 +9,7 @@
 #include "MQTTNetwork.h"
 #include "MQTTmbed.h"
 #include "MQTTClient.h"
-
+#define MQTT_DEVICE_ID          "123"
 ISM43362Interface net;
 // WiFiInterface *wifi;
 
@@ -46,8 +46,8 @@
     
     // MQTT Example Start
     float version = 0.6;
-    char* publishtopic = "publishtest";
-    char* subscribetopic = "subscribtest";
+    char* publishtopic = "publishtestOS5";
+    char* subscribetopic = "subscribtestOS5";
 
     logMessage("HelloMQTT: version is %.2f\r\n", version);
 
@@ -60,7 +60,7 @@
 
     MQTT::Client<MQTTNetwork, Countdown> client(mqttNetwork);
 
-    const char* hostname = "192.168.0.120";
+    const char* hostname = "192.168.0.101";
     int port = 1883;
     logMessage("Connecting to %s:%d\r\n", hostname, port);
     int rc = mqttNetwork.connect(hostname, port);
@@ -82,22 +82,25 @@
    
 
     // Get device health data, send to Treasure Data every 10 seconds
+
     while(1){
         
         printf("\test\n");
          MQTT::Message message;
 
     // QoS 0
-    char buf[100];
-    sprintf(buf, "Hello World!  QoS 0 message from app version %f\r\n", version);
+    char buf[128];
+    //int n = snprintf(buf, sizeof(buf), "{\"S1\":%d,\"S2\":%s}",count, MQTT_DEVICE_ID);
+   //sprintf(buf, "Hello World!  QoS 0 message from app version %f\r\n", version);
+     sprintf(buf,"{\"S1\":%d,\"S2\":%s}",count, MQTT_DEVICE_ID);
     message.qos = MQTT::QOS0;
     message.retained = false;
     message.dup = false;
     message.payload = (void*)buf;
     message.payloadlen = strlen(buf)+1;
     rc = client.publish(publishtopic, message);
-    client.yield(100);
-
+    //client.yield(100);
+   count++;
 
     //int x = 0;
         wait(1);
--- a/mbed_app.json	Tue Dec 10 07:13:20 2019 +0000
+++ b/mbed_app.json	Tue Jan 05 17:59:51 2021 +0000
@@ -7,11 +7,11 @@
         },
          "wifi-ssid": {
             "help": "WiFi SSID",
-            "value": "\"cornetlin\""
+            "value": "\"cornetlinhome\""
         },
         "wifi-password": {
             "help": "WiFi Password",
-            "value": "\"tp67650421\""
+            "value": "\"67650421\""
         },
         "api-key":{
             "help":  "REST API Key for Treasure Data",