Modified MQTT for Mbed OS.

Dependencies:   FP MQTTPacket

Dependents:   mbed-os-mqtt door_lock co657_IoT nucleo-f429zi-mbed-os-mqtt

Fork of MQTT by MQTT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSocket.h Source File

MQTTSocket.h

00001 #if !defined(MQTTSOCKET_H)
00002 #define MQTTSOCKET_H
00003 
00004 #include "MQTTmbed.h"
00005 #include "TCPSocket.h"
00006 
00007 class MQTTSocket
00008 {
00009 public:    
00010 
00011     int open(EthernetInterface& eth){
00012         return mysock.open(&eth);
00013     }    
00014 
00015     int connect(char* hostname, int port, int timeout=1000)
00016     {
00017         mysock.set_blocking(false);
00018         mysock.set_timeout(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);
00025         mysock.set_timeout(timeout);  
00026         return mysock.recv((char*)buffer, len);
00027     }
00028     
00029     int write(unsigned char* buffer, int len, int timeout)
00030     {
00031         mysock.set_blocking(false);
00032         mysock.set_timeout(timeout);  
00033         return mysock.send((char*)buffer, len);
00034     }
00035     
00036     int disconnect()
00037     {
00038         return mysock.close();
00039     }
00040     
00041 private:
00042 
00043     TCPSocket mysock; 
00044     
00045 };
00046 
00047 
00048 
00049 #endif