CHANG rozen / Mbed 2 deprecated Cayenne-X-NUCLEO-IDW01M1-TMP36

Dependencies:   Cayenne-MQTT-mbed NetworkSocketAPI X_NUCLEO_IDW01M1v2 mbed Servo

Fork of Cayenne-X-NUCLEO-IDW01M1-TMP36 by myDevicesIoT

Revision:
6:cec678bb15ef
Parent:
5:294a8b1bca28
Child:
7:fed254c30643
--- a/main.cpp	Fri Nov 11 18:31:11 2016 +0000
+++ b/main.cpp	Tue Aug 29 07:58:37 2017 +0000
@@ -7,16 +7,16 @@
 #include "CayenneMQTTClient.h"
 #include "MQTTNetworkIDW01M1.h"
 #include "SpwfInterface.h"
-#include "TMP36.h"
+#include "BME280.hpp"
 
 // WiFi network info.
-char* ssid = "ssid";
-char* wifiPassword = "wifiPassword";
+char* ssid = "megu megu fire";
+char* wifiPassword = "66666667";
 
 // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
-char* username = "MQTT_USERNAME";
-char* password = "MQTT_PASSWORD";
-char* clientID = "CLIENT_ID";
+char* username = "1f764db0-122b-11e7-b235-9359079e690e";
+char* password = "0d4e9d94e7897df9af861007853ed3f906b0627d";
+char* clientID = "8ff46d80-8c81-11e7-a491-d751ec027e48";
 
 SpwfSAInterface interface(D8, D2); // TX, RX
 MQTTNetwork<SpwfSAInterface> network(interface);
@@ -136,12 +136,14 @@
 {
     // Start the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval.
     MQTTTimer timer(5000);
-    TMP36 tmpSensor(A5);
+    //TMP36 tmpSensor(A5);
+    BME280 bmpSensor;
+    
     
     while (true) {
         // Yield to allow MQTT message processing.
         mqttClient.yield(1000);
-
+        //printf("%d\n",bmpSensor->Temp_read());
         // Check that we are still connected, if not, reconnect.
         if (!network.connected() || !mqttClient.connected()) {
             network.disconnect();
@@ -152,11 +154,11 @@
                 printf("Reconnect failed, retrying\n");
             }
         }
-
+        printf("before you post data,your temp is %d\n",bmpSensor.Temp_read());
         // Publish some example data every few seconds. This should be changed to send your actual data to Cayenne.
         if (timer.expired()) {
             int error = 0;
-            if ((error = mqttClient.publishData(DATA_TOPIC, 5, TYPE_TEMPERATURE, UNIT_CELSIUS, tmpSensor.read())) != CAYENNE_SUCCESS) {
+            if ((error = mqttClient.publishData(DATA_TOPIC, 5, TYPE_TEMPERATURE, UNIT_CELSIUS,(float)bmpSensor.Temp_read())) != CAYENNE_SUCCESS) {
                 printf("Publish temperature failed, error: %d\n", error);
             }
             // Restart the countdown timer for publishing data every 5 seconds. Change the timeout parameter to publish at a different interval.
@@ -173,7 +175,7 @@
     // Initialize the network interface.
     printf("Initializing interface\n");
     interface.connect(ssid, wifiPassword, NSAPI_SECURITY_WPA2);
-
+    printf("connect AP successful\n");
     // Set the default function that receives Cayenne messages.
     mqttClient.setDefaultMessageHandler(messageArrived);
 
@@ -187,9 +189,12 @@
     }
 
     if (mqttClient.connected())
+        printf("client disconnect\n");
         mqttClient.disconnect();
     if (network.connected())
+        printf("network disconnect\n");
         network.disconnect();
+    
 
     return 0;
 }