MQTT connection through WizFi310

Dependencies:   DHT MQTTforLecture WizFi310Interface_Legacynew mbed-src

Fork of w7500-RFID-mqtt by Biswajit Padhi

Files at this revision

API Documentation at this revision

Comitter:
akshaytom
Date:
Thu Dec 28 06:32:51 2017 +0000
Parent:
15:d4604c47da41
Commit message:
MQTT connection through WizFi310

Changed in this revision

WIZnetInterface.lib Show diff for this revision Revisions of this file
WizFi310Interface_Legacynew.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
--- a/WIZnetInterface.lib	Mon Sep 21 23:39:16 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/users/bangbh/code/WIZnetInterface/#77b21be5d255
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WizFi310Interface_Legacynew.lib	Thu Dec 28 06:32:51 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/akshaytom/code/WizFi310Interface_Legacynew/#aba7465a254d
--- a/main.cpp	Mon Sep 21 23:39:16 2015 +0000
+++ b/main.cpp	Thu Dec 28 06:32:51 2017 +0000
@@ -1,14 +1,25 @@
 #include "mbed.h"
+#include "WizFi310Interface.h"
 #include "DHT.h"
-#include "MQTTEthernet.h"
 #include "MQTTClient.h"
+#include "MQTTmbed.h"
+#include "MQTTSocket.h"
 
-#define ECHO_SERVER_PORT   7
+#define SECURE WizFi310::SEC_WPA2_MIXED
+#define SSID "CDI"
+#define PASS "Cdi*1717"
+/*
+    SET DHCP
+*/
+#define USE_DHCP    1
+//--------- Have to modify the mac address-------------
+unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56};
+#if defined(TARGET_WIZwiki_W7500)
+    WizFi310Interface wizfi310(D1, D0, D7, D6, D8, NC, 115200);
+    Serial pc(USBTX, USBRX);
+#endif
 
-#include "mbed.h"
- 
 int arrivedcount = 0;
- 
 void messageArrived(MQTT::MessageData& md)
 {
     MQTT::Message &message = md.message;
@@ -17,28 +28,43 @@
     ++arrivedcount;
 }
 
-void baud(int baudrate) {
-    Serial s(USBTX, USBRX);
-    s.baud(baudrate);
-}
-
-int main (void)
+class MQTTWIZ: public MQTTSocket
 {
-    DHT sensor(D4, DHT11);
-    AnalogIn ain(A1);
-    baud(115200);
-    printf("Wait a second...\r\n");
-    MQTTEthernet ipstack = MQTTEthernet();
+public:    
+    MQTTWIZ()
+    {
+        wait(1);
+        this->createSocket();
+    }
+};
+
+int main() {
+
+
+ 
+   pc.baud(115200);
+ 
+    printf("WizFi310  STATION. \r\n");
+    wizfi310.init();
+    printf("After Initialisation. \r\n");
+
+    printf("After Set Address. \r\n");
+    if ( wizfi310.connect(SECURE, SSID, PASS, WizFi310::WM_STATION))      return -1;
+    printf("After Connect. \r\n");
+    printf("IP Address is %s\r\n", wizfi310.getIPAddress()); 
     
-    MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
+    MQTTWIZ ipstack = MQTTWIZ();
+    MQTT::Client<MQTTWIZ, Countdown> client = MQTT::Client<MQTTWIZ, Countdown>(ipstack);
     
-    char* hostname = "222.98.173.244";
+    DHT sensor(D14, DHT11);
+    char* hostname = "172.16.73.4";
     int port = 1883;
     
     int rc = ipstack.connect(hostname, port);
     if (rc != 0)
         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;       
@@ -71,29 +97,14 @@
         sprintf(buf, "%3.1f", hum);
         message.payload = (void*)buf;
         message.payloadlen = strlen(buf);
-        rc = client.publish("Wiznet/humidity", message);
+        rc = client.publish("Wiz/humidity", message);
+        printf("Wiz/humidity : %s\r\n",message.payload);
         
         sprintf(buf, "%3.1f", temp);
         message.payload = (void*)buf;
         message.payloadlen = strlen(buf);
-        rc = client.publish("Wiznet/temperature", message);
-        
-        sprintf(buf, "%3.1f", (rand()%1000)/10.0);
-        message.payload = (void*)buf;
-        message.payloadlen = strlen(buf);
-        rc = client.publish("Wiznet/fluidgauge/A", message);
-        
-        sprintf(buf, "%3.1f", (rand()%1000)/10.0);
-        message.payload = (void*)buf;
-        message.payloadlen = strlen(buf);
-        rc = client.publish("Wiznet/fluidgauge/B", message);
-        
-        sprintf(buf, "%3.1f", (rand()%1000)/10.0);
-        message.payload = (void*)buf;
-        message.payloadlen = strlen(buf);
-        rc = client.publish("Wiznet/fluidgauge/C", message);
+        rc = client.publish("Wiz/temperature", message);
+        printf("Wiz/temperature : %s\r\n",message.payload);
         client.yield(1000);
-        //wait(100);
     }
 }
-
--- a/mbed-src.lib	Mon Sep 21 23:39:16 2015 +0000
+++ b/mbed-src.lib	Thu Dec 28 06:32:51 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-src/#30f9462b5296
+https://os.mbed.com/users/mbed_official/code/mbed-src/#a11c0372f0ba