My goal with this project was to create a quick operations console to interface with embedded hardware for messaging and switching. As I am part of an active project called Kivy.org I figured it would be a perfect tool to provide the user interface for the console. Kivy is a cross platform development framework based on Python and the C language. For further reading I urge you to click over to the http://kivy.org website and download a copy of the framework for your operating system and run some examples. The API is ultra easy and very feature rich including 2D & 3D support with standard widget libraries and Advanced multitouch gesturing support that all runs in the hardware GPU on Microsoft windows operating systems, Apple Mac OSx operating systems including IOS for the iPhone and iPad as well as support for Android and Linux. The example code I am providing in this blog entry can easily be built simultaneously for each of the above operating systems. See http://mctouch.wordpress.com

Dependencies:   EthernetNetIf TextLCD mbed

Revision:
0:7852eddd2a3c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MQTTClient.h	Thu Jun 28 21:29:07 2012 +0000
@@ -0,0 +1,51 @@
+/**
+ *A simple MQTT client for mbed, version 2.0
+ *By Yilun FAN, @CEIT, @JAN 2011
+ *
+ */
+#ifndef MQTT_CLIENT_H
+#define MQTT_CLIENT_H
+
+#include "mbed.h"
+#include "TCPSocket.h"
+
+#define MQTTCONNECT 1<<4
+#define MQTTPUBLISH 3<<4
+#define MQTTSUBSCRIBE 8<<4
+
+#define MAX_PACKET_SIZE 128
+#define KEEPALIVE 15000
+
+class MQTTClient 
+{
+public:
+    MQTTClient(IpAddr server, int port, void (*callback)(char*, char*));
+    ~MQTTClient();
+    int connect(char *);
+    void disconnect();
+    int publish(char *, char *);
+    int subscribe(char *);
+    void live();
+	
+private:
+    int open_session(char* id);
+    void read_open_session();
+    int send_data(const char* msg, int size);
+    void read_data();
+    
+    char* clientId;
+    Timer timer;
+    IpAddr serverIp;
+    int port;
+    bool connected;
+    bool sessionOpened;
+    
+    void onTCPSocketEvent(TCPSocketEvent e);
+    TCPSocket* pTCPSocket;
+    Host host;
+    
+    int lastActivity;
+    void (*callback_server)(char*, char*);
+};
+
+#endif
\ No newline at end of file