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

Committer:
mctouch
Date:
Thu Jun 28 21:29:07 2012 +0000
Revision:
0:7852eddd2a3c
For blog entry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mctouch 0:7852eddd2a3c 1 /**
mctouch 0:7852eddd2a3c 2 *A simple MQTT client for mbed, version 2.0
mctouch 0:7852eddd2a3c 3 *By Yilun FAN, @CEIT, @JAN 2011
mctouch 0:7852eddd2a3c 4 *
mctouch 0:7852eddd2a3c 5 */
mctouch 0:7852eddd2a3c 6 #ifndef MQTT_CLIENT_H
mctouch 0:7852eddd2a3c 7 #define MQTT_CLIENT_H
mctouch 0:7852eddd2a3c 8
mctouch 0:7852eddd2a3c 9 #include "mbed.h"
mctouch 0:7852eddd2a3c 10 #include "TCPSocket.h"
mctouch 0:7852eddd2a3c 11
mctouch 0:7852eddd2a3c 12 #define MQTTCONNECT 1<<4
mctouch 0:7852eddd2a3c 13 #define MQTTPUBLISH 3<<4
mctouch 0:7852eddd2a3c 14 #define MQTTSUBSCRIBE 8<<4
mctouch 0:7852eddd2a3c 15
mctouch 0:7852eddd2a3c 16 #define MAX_PACKET_SIZE 128
mctouch 0:7852eddd2a3c 17 #define KEEPALIVE 15000
mctouch 0:7852eddd2a3c 18
mctouch 0:7852eddd2a3c 19 class MQTTClient
mctouch 0:7852eddd2a3c 20 {
mctouch 0:7852eddd2a3c 21 public:
mctouch 0:7852eddd2a3c 22 MQTTClient(IpAddr server, int port, void (*callback)(char*, char*));
mctouch 0:7852eddd2a3c 23 ~MQTTClient();
mctouch 0:7852eddd2a3c 24 int connect(char *);
mctouch 0:7852eddd2a3c 25 void disconnect();
mctouch 0:7852eddd2a3c 26 int publish(char *, char *);
mctouch 0:7852eddd2a3c 27 int subscribe(char *);
mctouch 0:7852eddd2a3c 28 void live();
mctouch 0:7852eddd2a3c 29
mctouch 0:7852eddd2a3c 30 private:
mctouch 0:7852eddd2a3c 31 int open_session(char* id);
mctouch 0:7852eddd2a3c 32 void read_open_session();
mctouch 0:7852eddd2a3c 33 int send_data(const char* msg, int size);
mctouch 0:7852eddd2a3c 34 void read_data();
mctouch 0:7852eddd2a3c 35
mctouch 0:7852eddd2a3c 36 char* clientId;
mctouch 0:7852eddd2a3c 37 Timer timer;
mctouch 0:7852eddd2a3c 38 IpAddr serverIp;
mctouch 0:7852eddd2a3c 39 int port;
mctouch 0:7852eddd2a3c 40 bool connected;
mctouch 0:7852eddd2a3c 41 bool sessionOpened;
mctouch 0:7852eddd2a3c 42
mctouch 0:7852eddd2a3c 43 void onTCPSocketEvent(TCPSocketEvent e);
mctouch 0:7852eddd2a3c 44 TCPSocket* pTCPSocket;
mctouch 0:7852eddd2a3c 45 Host host;
mctouch 0:7852eddd2a3c 46
mctouch 0:7852eddd2a3c 47 int lastActivity;
mctouch 0:7852eddd2a3c 48 void (*callback_server)(char*, char*);
mctouch 0:7852eddd2a3c 49 };
mctouch 0:7852eddd2a3c 50
mctouch 0:7852eddd2a3c 51 #endif