This is an simple example to send the data to the MQTT broker using W7500 ECO module

Dependencies:   MQTT WIZnetInterface mbed

Fork of W7500_ECO_Sending_String_to_MQTT_Broker by HARSHA B.M

Files at this revision

API Documentation at this revision

Comitter:
HarshaDRAGNEEL
Date:
Mon Aug 06 11:28:02 2018 +0000
Child:
1:9c13b9f1f2b3
Commit message:
Used older mbed libraries to restrict the timer.h warning in Serial PC display

Changed in this revision

MQTT.lib Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface.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.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MQTT.lib	Mon Aug 06 11:28:02 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/HarshaDRAGNEEL/code/MQTT/#97d1b3487179
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnetInterface.lib	Mon Aug 06 11:28:02 2018 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#c91884bd2713
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Aug 06 11:28:02 2018 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+#include "SPI.h"
+#include "MQTTEthernet.h"
+#include "MQTTClient.h"
+
+#define ECHO_SERVER_PORT   7
+ 
+Serial pc(USBTX, USBRX);   //Enabling the Serial transmission between WIZ750SR and PC.
+char c[100]="Hello testing";
+ 
+int main(void) {
+    printf("Wait a second...\r\n");
+    char* topic = "ack";                    //if we are subscribing the acknowledgement.
+    MQTTEthernet ipstack = MQTTEthernet();
+    
+    MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
+    
+    char* hostname = "iot.eclipse.org";   //Give the IP Address of the MQTT Broker.
+    int port = 1883;                  // Port number of the MQTT broker.  
+    
+ 
+    int rc = ipstack.connect(hostname, port);
+    if (rc != 0)
+    printf("rc from TCP connect is %d\n", rc);
+    printf("Topic: %s\r\n",topic);
+    
+    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
+    data.MQTTVersion = 3;
+    data.clientID.cstring = "Gintama";
+
+    if ((rc = client.connect(data)) == 0)
+    printf("rc from MQTT connect is %d\n", rc);
+   
+                              
+   while (true) {
+  
+     pc.printf("The value Sent to MQTT is: %s \n ",c);
+     MQTT::Message message;
+     char buf[100];
+     sprintf(buf, "%s", c);
+     message.qos = MQTT::QOS0;
+         message.retained = false;
+         message.dup = false;
+
+         message.payload = (void*)c;
+         message.payloadlen = strlen(c);
+
+         rc = client.publish("hellooo", message);
+        // pc.printf("Rc result: %c \n ",rc);
+         client.yield(60);
+         wait(60);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Aug 06 11:28:02 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file