Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MQTT by
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(NetworkStack *ipstack) 00012 { 00013 return mysock.open(ipstack); 00014 } 00015 00016 int connect(char* hostname, int port, int timeout=1000) 00017 { 00018 int err; 00019 mysock.set_timeout(timeout); 00020 err = mysock.connect(hostname, port); 00021 // t.start(); 00022 return err; 00023 } 00024 00025 int read(unsigned char* buffer, int len, int timeout) 00026 { 00027 mysock.set_timeout(timeout); 00028 //t.reset(); 00029 // int start = t.read_ms(); 00030 int rc = mysock.recv((char*)buffer, len); 00031 // int stop = t.read_ms(); 00032 // if (rc>0) printf ("recv File: %s, Line: %d Read nB: %d rc: %d timeout: %d elaps: %d\n\r",__FILE__,__LINE__, len, rc, timeout, stop-start); 00033 return rc; 00034 } 00035 00036 int write(unsigned char* buffer, int len, int timeout) 00037 { 00038 mysock.set_timeout(timeout); 00039 // mysock.set_blocking(false, timeout); 00040 // mysock.set_blocking(false); 00041 int rc = mysock.send((char*)buffer, len); 00042 // printf ("send File: %s, Line: %d Write nB: %d rc: %d\n\r",__FILE__,__LINE__, len, rc); 00043 return rc; 00044 } 00045 00046 int disconnect() 00047 { 00048 // t.stop(); 00049 return mysock.close(); 00050 } 00051 00052 private: 00053 TCPSocket mysock; 00054 // Timer t; 00055 00056 }; 00057 #endif
Generated on Thu Jul 14 2022 00:21:46 by
1.7.2
