MQTT Client for mbed LPC1768 and Application Board over Ethernet; publish only.

Dependencies:   C12832 MMA7660 MQTT

Fork of HelloMQTT by MQTT

Machine-to-Machine-Communication

Das Message Queue Telemetry Transport (MQTT) Protokoll ist ein effizientes Internet of Things (IoT) Protokoll mit wenig Protokolloverhead. Es wurde als lightweight publish/subscribe messaging transport entworfen. Es ist sinnvoll für Verbindungen mit Remote-Standorten, wo nur wenig Resourcen benötigt werden bzw. geringe Bandbreite zur Verfügung steht. Neben MQTT gibt es weitere IoT-Protokoll, wie HTTP, CoAP, XMPP, ... (Überischt über IoT Protokolle). Eine Beschreibung des MQTT ist z.B. hier zu finden.

MQTT implementiert das Publish/Subscribe-Pattern, daher wird ein Brocker für die Vermittlung der Nachrichten (topics) benötigt. Neben vielen quelloffenen Implementierungen (z. B. mosquitto) gibt es auch kommerzielle bzw. freie Server (Broker), die unterschiedliche Features bereit stellen (z. B. den in Deutschland entwickelten HiveMQ).

Für die Programmierung der Clients bzw. Ebedded Systems stehen ebenso sehr viele Libaries in verschiedenen Programmiersprachen zur Verfügung.

Desktop MQTT-Clients

M3-Ethernet MQTT Client

M3-Ethernet ThingSpeak

C# Wpf Client

Weitere Kommunikationsmöglichkeiten

Files at this revision

API Documentation at this revision

Comitter:
icraggs
Date:
Sun May 11 19:17:05 2014 +0000
Parent:
5:4a257f6ac09a
Parent:
6:e4c690c45021
Child:
8:a3e3113054a1
Commit message:
Merge latest changes

Changed in this revision

MQTT.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
--- a/MQTT.lib	Fri May 09 23:06:43 2014 +0000
+++ b/MQTT.lib	Sun May 11 19:17:05 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/mqtt/code/MQTT/#d13a6c558164
+http://mbed.org/teams/mqtt/code/MQTT/#8b2abe9bd814
\ No newline at end of file
--- a/main.cpp	Fri May 09 23:06:43 2014 +0000
+++ b/main.cpp	Sun May 11 19:17:05 2014 +0000
@@ -45,34 +45,12 @@
     lcd.puts((char*)message->payload);
 }
 
-int connect(MQTT::Client<IPStack, Countdown>::connectionLostInfo* info)
-{
-    char* hostname = "m2m.eclipse.org";
-    int port = 1883;
-    
-    lcd.cls();
-    lcd.locate(0,3);
-    lcd.printf("%s:%d\n", hostname, port);
-    printf("Connecting to %s:%d\n", hostname, port);
-    int rc = info->network->connect(hostname, port);
-    lcd.printf("TCP connect = %d\n", rc);
-    printf("rc from TCP connect is %d\n", rc);
- 
-    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
-    data.MQTTVersion = 3;
-    data.clientID.cstring = "mbed-icraggs";
-    rc = info->client->connect(&data);
-    lcd.printf("MQTT connect = %d\n", rc);
-    printf("rc from MQTT connect is %d\n", rc);
-    
-    return rc;
-}
 
 
 int main(int argc, char* argv[])
 {   
     IPStack ipstack = IPStack();
-    float version = 0.3;
+    float version = 0.43;
     char* topic = "mbed-sample";
     
     lcd.printf("Version is %f\n", version);
@@ -80,10 +58,19 @@
               
     MQTT::Client<IPStack, Countdown> client = MQTT::Client<IPStack, Countdown>(ipstack);
     
-    client.setConnectionLostHandler(connect);
-
-    MQTT::Client<IPStack, Countdown>::connectionLostInfo info = {&client, &ipstack};
-    int rc = connect(&info);
+    char* hostname = "m2m.eclipse.org";
+    int port = 1883;
+    lcd.printf("Connecting to %s:%d\n", hostname, port);
+    int rc = ipstack.connect(hostname, port);
+    if (rc != 0)
+        lcd.printf("rc from TCP connect is %d\n", rc);
+ 
+    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
+    data.MQTTVersion = 3;
+    data.clientID.cstring = "mbed-icraggs";
+    rc = client.connect(&data);
+    if (rc != 0)
+        lcd.printf("rc from MQTT connect is %d\n", rc);
     
     rc = client.subscribe(topic, MQTT::QOS1, messageArrived);   
     if (rc != 0) {
--- a/mbed-rtos.lib	Fri May 09 23:06:43 2014 +0000
+++ b/mbed-rtos.lib	Sun May 11 19:17:05 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#f88660a9bed1
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d