nc

Dependencies:   mbed-src WizFi310Interface_Legacynew DHT MQTTforLecture

Revision:
17:39b1ebb505b1
Parent:
16:2794fcca7629
--- a/main.cpp	Thu Dec 28 06:32:51 2017 +0000
+++ b/main.cpp	Thu Dec 13 10:24:36 2018 +0000
@@ -6,8 +6,8 @@
 #include "MQTTSocket.h"
 
 #define SECURE WizFi310::SEC_WPA2_MIXED
-#define SSID "CDI"
-#define PASS "Cdi*1717"
+#define SSID "CDI_STAFF"
+#define PASS "YYkpbQBC"
 /*
     SET DHCP
 */
@@ -42,9 +42,10 @@
 
 
  
-   pc.baud(115200);
+    pc.baud(115200);
  
     printf("WizFi310  STATION. \r\n");
+     char* topicfan = "fan";
     wizfi310.init();
     printf("After Initialisation. \r\n");
 
@@ -57,7 +58,7 @@
     MQTT::Client<MQTTWIZ, Countdown> client = MQTT::Client<MQTTWIZ, Countdown>(ipstack);
     
     DHT sensor(D14, DHT11);
-    char* hostname = "172.16.73.4";
+    char* hostname = "iot.eclipse.org";
     int port = 1883;
     
     int rc = ipstack.connect(hostname, port);
@@ -65,6 +66,7 @@
         printf("rc from TCP connect is %d\n", rc);
     printf("rc from TCP connect is %d\n", rc);
     
+    
     char MQTTClientID[30];
     
     MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
@@ -73,10 +75,17 @@
     data.clientID.cstring = MQTTClientID;
     data.username.cstring = "testuser";
     data.password.cstring = "testpassword";  
+    
+    
 
     if ((rc = client.connect(data)) != 0)
         printf("rc from MQTT connect is %d\n", rc);
         
+        
+    if ((rc = client.subscribe(topicfan, MQTT::QOS1, messageArrived)) == 0)
+    printf("rc from MQTT subscribe for fan is %d\n", rc);
+    
+        
     MQTT::Message message;
     char buf[100];
     int error = 0;
@@ -98,13 +107,13 @@
         message.payload = (void*)buf;
         message.payloadlen = strlen(buf);
         rc = client.publish("Wiz/humidity", message);
-        printf("Wiz/humidity : %s\r\n",message.payload);
+//        printf("Wiz/humidity : %s\r\n",message.payload);
         
-        sprintf(buf, "%3.1f", temp);
-        message.payload = (void*)buf;
-        message.payloadlen = strlen(buf);
-        rc = client.publish("Wiz/temperature", message);
-        printf("Wiz/temperature : %s\r\n",message.payload);
+        //sprintf(buf, "%3.1f", temp);
+//        message.payload = (void*)buf;
+//        message.payloadlen = strlen(buf);
+//        rc = client.publish("Wiz/temperature", message);
+//        printf("Wiz/temperature : %s\r\n",message.payload);
         client.yield(1000);
     }
 }