An API for using MQTT over multiple transports
Dependencies: FP MQTTPacket
Dependents: IBMIoTClientEthernetExample_W5500 IBMIoTClientEthernetExample_W5200
Fork of MQTT by
MQTTSocket.h
00001 #if !defined(MQTTSOCKET_H) 00002 #define MQTTSOCKET_H 00003 00004 #include "MQTT_mbed.h" 00005 #include "TCPSocketConnection.h" 00006 00007 class MQTTSocket 00008 { 00009 public: 00010 ~MQTTSocket() 00011 { 00012 if(mysock) 00013 delete mysock; 00014 } 00015 00016 int connect(char* hostname, int port, int timeout=1000) 00017 { 00018 mysock->set_blocking(false, timeout); // 1 second Timeout 00019 return mysock->connect(hostname, port); 00020 } 00021 00022 int read(unsigned char* buffer, int len, int timeout) 00023 { 00024 mysock->set_blocking(false, timeout); 00025 return mysock->receive((char*)buffer, len); 00026 } 00027 00028 int write(unsigned char* buffer, int len, int timeout) 00029 { 00030 mysock->set_blocking(false, timeout); 00031 return mysock->send((char*)buffer, len); 00032 } 00033 00034 int disconnect() 00035 { 00036 return mysock->close(); 00037 } 00038 00039 protected: 00040 void createSocket() { mysock = new TCPSocketConnection(); } 00041 00042 private: 00043 00044 TCPSocketConnection *mysock; 00045 00046 }; 00047 00048 00049 00050 #endif
Generated on Sat Jul 23 2022 06:15:21 by 1.7.2