Initial port of the Arduino MQTT Client: http://knolleary.net/arduino-client-for-mqtt/
Dependents: MQTTTest 2lemetryNXP MyTempuratureMqtt MqttClientEthInt ... more
PubSubClient.h
00001 /* 00002 PubSubClient.h - A simple client for MQTT. 00003 Nicholas O'Leary 00004 http://knolleary.net 00005 */ 00006 #include "mbed.h" 00007 #include "EthernetInterface.h" 00008 #include "TCPSocketConnection.h" 00009 00010 #ifndef PubSubClient_h 00011 #define PubSubClient_h 00012 00013 00014 00015 // MQTT_MAX_PACKET_SIZE : Maximum packet size 00016 #define MQTT_MAX_PACKET_SIZE 128 00017 00018 // MQTT_KEEPALIVE : keepAlive interval in Seconds 00019 #define MQTT_KEEPALIVE 15 00020 00021 #define MQTTPROTOCOLVERSION 3 00022 #define MQTTCONNECT 1 << 4 // Client request to connect to Server 00023 #define MQTTCONNACK 2 << 4 // Connect Acknowledgment 00024 #define MQTTPUBLISH 3 << 4 // Publish message 00025 #define MQTTPUBACK 4 << 4 // Publish Acknowledgment 00026 #define MQTTPUBREC 5 << 4 // Publish Received (assured delivery part 1) 00027 #define MQTTPUBREL 6 << 4 // Publish Release (assured delivery part 2) 00028 #define MQTTPUBCOMP 7 << 4 // Publish Complete (assured delivery part 3) 00029 #define MQTTSUBSCRIBE 8 << 4 // Client Subscribe request 00030 #define MQTTSUBACK 9 << 4 // Subscribe Acknowledgment 00031 #define MQTTUNSUBSCRIBE 10 << 4 // Client Unsubscribe request 00032 #define MQTTUNSUBACK 11 << 4 // Unsubscribe Acknowledgment 00033 #define MQTTPINGREQ 12 << 4 // PING Request 00034 #define MQTTPINGRESP 13 << 4 // PING Response 00035 #define MQTTDISCONNECT 14 << 4 // Client is Disconnecting 00036 #define MQTTReserved 15 << 4 // Reserved 00037 00038 #define MQTTQOS0 (0 << 1) 00039 #define MQTTQOS1 (1 << 1) 00040 #define MQTTQOS2 (2 << 1) 00041 00042 class PubSubClient { 00043 private: 00044 TCPSocketConnection _client; 00045 char buffer[MQTT_MAX_PACKET_SIZE]; 00046 int nextMsgId; 00047 unsigned long lastOutActivity; 00048 unsigned long lastInActivity; 00049 bool pingOutstanding; 00050 void (*callback)(char*,char*,unsigned int); 00051 int readPacket(int); 00052 char readByte(); 00053 bool write(short header, char* buf, int length); 00054 int writeString(char* string, char* buf, int pos); 00055 char* ip; 00056 int port; 00057 public: 00058 PubSubClient(); 00059 PubSubClient(char*, int, void(*)(char*,char*,unsigned int)); 00060 bool connect(char *); 00061 bool connect(char *, char *, char *); 00062 bool connect(char *, char *, short, short, char *); 00063 bool connect(char *, char *, char *, char *, short, short, char*); 00064 void disconnect(); 00065 bool publish(char *, char *); 00066 bool publish(char *, char *, unsigned int); 00067 bool publish(char *, char *, unsigned int, bool); 00068 // bool publish_P(char *, short PROGMEM *, unsigned int, bool); 00069 bool subscribe(char *); 00070 bool unsubscribe(char *); 00071 bool loop(); 00072 bool connected(); 00073 }; 00074 00075 00076 #endif
Generated on Wed Jul 13 2022 23:16:09 by
