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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTClient.h Source File

MQTTClient.h

00001 /**
00002  *A simple MQTT client for mbed, version 2.0
00003  *By Yilun FAN, @CEIT, @JAN 2011
00004  *
00005  */
00006 #ifndef MQTT_CLIENT_H
00007 #define MQTT_CLIENT_H
00008 
00009 #include "mbed.h"
00010 #include "TCPSocket.h"
00011 
00012 #define MQTTCONNECT 1<<4
00013 #define MQTTPUBLISH 3<<4
00014 #define MQTTSUBSCRIBE 8<<4
00015 
00016 #define MAX_PACKET_SIZE 128
00017 #define KEEPALIVE 15000
00018 
00019 class MQTTClient 
00020 {
00021 public:
00022     MQTTClient(IpAddr server, int port, void (*callback)(char*, char*));
00023     ~MQTTClient();
00024     int connect(char *);
00025     void disconnect();
00026     int publish(char *, char *);
00027     int subscribe(char *);
00028     void live();
00029     
00030 private:
00031     int open_session(char* id);
00032     void read_open_session();
00033     int send_data(const char* msg, int size);
00034     void read_data();
00035     
00036     char* clientId;
00037     Timer timer;
00038     IpAddr serverIp;
00039     int port;
00040     bool connected;
00041     bool sessionOpened;
00042     
00043     void onTCPSocketEvent(TCPSocketEvent e);
00044     TCPSocket* pTCPSocket;
00045     Host host;
00046     
00047     int lastActivity;
00048     void (*callback_server)(char*, char*);
00049 };
00050 
00051 #endif