Local fixes

Committer:
hudakz
Date:
Sun Nov 29 18:12:22 2015 +0000
Revision:
2:ca17c5d846e7
Parent:
1:87da395325fc
Child:
3:5e31b4687aad
Modified to make it work with the latest mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:83c732b10e95 1 /*
hudakz 0:83c732b10e95 2 MQTTClient.h - A simple client for MQTT.
hudakz 0:83c732b10e95 3 Nicholas O'Leary
hudakz 0:83c732b10e95 4 http://knolleary.net
hudakz 2:ca17c5d846e7 5
hudakz 1:87da395325fc 6 Ported to mbed by Zoltan Hudak <hudakz@inbox.com>
hudakz 0:83c732b10e95 7 */
hudakz 0:83c732b10e95 8 #ifndef MQTTClient_h
hudakz 0:83c732b10e95 9 #define MQTTClient_h
hudakz 0:83c732b10e95 10
hudakz 0:83c732b10e95 11 #include <mbed.h>
hudakz 0:83c732b10e95 12 #include "Client.h"
hudakz 0:83c732b10e95 13 //#include "Stream.h"
hudakz 0:83c732b10e95 14
hudakz 0:83c732b10e95 15
hudakz 2:ca17c5d846e7 16 #define MQTT_MAX_PACKET_SIZE 256 // MQTT_MAX_PACKET_SIZE : Maximum packet size
hudakz 2:ca17c5d846e7 17 #define MQTT_KEEPALIVE 15 // MQTT_KEEPALIVE : keepAlive interval in Seconds
hudakz 2:ca17c5d846e7 18 #define MQTTPROTOCOLVERSION 3
hudakz 2:ca17c5d846e7 19 #define MQTTCONNECT 1 << 4 // Client request to connect to Server
hudakz 2:ca17c5d846e7 20 #define MQTTCONNACK 2 << 4 // Connect Acknowledgment
hudakz 2:ca17c5d846e7 21 #define MQTTPUBLISH 3 << 4 // Publish message
hudakz 2:ca17c5d846e7 22 #define MQTTPUBACK 4 << 4 // Publish Acknowledgment
hudakz 2:ca17c5d846e7 23 #define MQTTPUBREC 5 << 4 // Publish Received (assured delivery part 1)
hudakz 2:ca17c5d846e7 24 #define MQTTPUBREL 6 << 4 // Publish Release (assured delivery part 2)
hudakz 2:ca17c5d846e7 25 #define MQTTPUBCOMP 7 << 4 // Publish Complete (assured delivery part 3)
hudakz 2:ca17c5d846e7 26 #define MQTTSUBSCRIBE 8 << 4 // Client Subscribe request
hudakz 2:ca17c5d846e7 27 #define MQTTSUBACK 9 << 4 // Subscribe Acknowledgment
hudakz 2:ca17c5d846e7 28 #define MQTTUNSUBSCRIBE 10 << 4 // Client Unsubscribe request
hudakz 2:ca17c5d846e7 29 #define MQTTUNSUBACK 11 << 4 // Unsubscribe Acknowledgment
hudakz 2:ca17c5d846e7 30 #define MQTTPINGREQ 12 << 4 // PING Request
hudakz 2:ca17c5d846e7 31 #define MQTTPINGRESP 13 << 4 // PING Response
hudakz 2:ca17c5d846e7 32 #define MQTTDISCONNECT 14 << 4 // Client is Disconnecting
hudakz 2:ca17c5d846e7 33 #define MQTTReserved 15 << 4 // Reserved
hudakz 2:ca17c5d846e7 34 #define MQTTQOS0 (0 << 1)
hudakz 2:ca17c5d846e7 35 #define MQTTQOS1 (1 << 1)
hudakz 2:ca17c5d846e7 36 #define MQTTQOS2 (2 << 1)
hudakz 0:83c732b10e95 37
hudakz 2:ca17c5d846e7 38 class MQTTClient
hudakz 0:83c732b10e95 39 {
hudakz 0:83c732b10e95 40 private:
hudakz 2:ca17c5d846e7 41 Client* _client;
hudakz 2:ca17c5d846e7 42 uint8_t buffer[MQTT_MAX_PACKET_SIZE];
hudakz 2:ca17c5d846e7 43 uint16_t nextMsgId;
hudakz 2:ca17c5d846e7 44 unsigned long lastOutActivity;
hudakz 2:ca17c5d846e7 45 unsigned long lastInActivity;
hudakz 2:ca17c5d846e7 46 bool pingOutstanding;
hudakz 2:ca17c5d846e7 47 void (*onMessage) (char*, uint8_t*, unsigned int);
hudakz 2:ca17c5d846e7 48 uint16_t readPacket(uint8_t* );
hudakz 2:ca17c5d846e7 49 uint8_t readByte(void);
hudakz 2:ca17c5d846e7 50 bool write(uint8_t header, uint8_t* buf, uint16_t length);
hudakz 2:ca17c5d846e7 51 uint16_t writeString(char* string, uint8_t* buf, uint16_t pos);
hudakz 2:ca17c5d846e7 52 IPAddress ip;
hudakz 2:ca17c5d846e7 53 char* domain;
hudakz 2:ca17c5d846e7 54 uint16_t port;
hudakz 2:ca17c5d846e7 55 Stream* stream;
hudakz 0:83c732b10e95 56 public:
hudakz 2:ca17c5d846e7 57 MQTTClient(void);
hudakz 2:ca17c5d846e7 58 MQTTClient(IPAddress& , uint16_t, void (* ) (char*, uint8_t*, unsigned int), Client& client);
hudakz 2:ca17c5d846e7 59 MQTTClient(IPAddress& , uint16_t, void (* ) (char*, uint8_t*, unsigned int), Client& client, Stream& );
hudakz 2:ca17c5d846e7 60 MQTTClient(char* , uint16_t, void (* ) (char*, uint8_t*, unsigned int), Client& client);
hudakz 2:ca17c5d846e7 61 MQTTClient(char* , uint16_t, void (* ) (char*, uint8_t*, unsigned int), Client& client, Stream& );
hudakz 2:ca17c5d846e7 62 bool connect(char* );
hudakz 2:ca17c5d846e7 63 bool connect(char* , char* , char* );
hudakz 2:ca17c5d846e7 64 bool connect(char* , char* , uint8_t, uint8_t, char* );
hudakz 2:ca17c5d846e7 65 bool connect(char* , char* , char* , char* , uint8_t, uint8_t, char* );
hudakz 2:ca17c5d846e7 66 void disconnect(void);
hudakz 2:ca17c5d846e7 67 bool publish(char* , char* );
hudakz 2:ca17c5d846e7 68 bool publish(char* , uint8_t* , unsigned int);
hudakz 2:ca17c5d846e7 69 bool publish(char* , uint8_t* , unsigned int, bool);
hudakz 2:ca17c5d846e7 70 bool subscribe(char* );
hudakz 2:ca17c5d846e7 71 bool subscribe(char* , uint8_t qos);
hudakz 2:ca17c5d846e7 72 bool unsubscribe(char* );
hudakz 2:ca17c5d846e7 73 bool loop(void);
hudakz 2:ca17c5d846e7 74 bool connected(void);
hudakz 0:83c732b10e95 75 };
hudakz 0:83c732b10e95 76 #endif