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.
Dependents: IDW01M1_QuickStart_cloud
Fork of MQTT by
Diff: MQTTSocket.h
- Revision:
- 47:24f2bf2819a5
- Parent:
- 43:21da1f744243
- Child:
- 48:66826ea709ea
--- a/MQTTSocket.h Tue Aug 18 09:57:19 2015 +0000
+++ b/MQTTSocket.h Wed Sep 28 13:11:35 2016 +0000
@@ -2,40 +2,57 @@
#define MQTTSOCKET_H
#include "MQTTmbed.h"
-#include "TCPSocketConnection.h"
+#include "TCPSocket.h"
class MQTTSocket
{
-public:
+public:
+
+ int open(NetworkStack *ipstack)
+ {
+ return mysock.open(ipstack);
+ }
+
int connect(char* hostname, int port, int timeout=1000)
{
- mysock.set_blocking(false, timeout); // 1 second Timeout
- return mysock.connect(hostname, port);
+ int err;
+ mysock.set_timeout(timeout);
+ err = mysock.connect(hostname, port);
+// t.start();
+ return err;
}
int read(unsigned char* buffer, int len, int timeout)
{
- mysock.set_blocking(false, timeout);
- return mysock.receive((char*)buffer, len);
+ mysock.set_timeout(timeout);
+//t.reset();
+// int start = t.read_ms();
+ int rc = mysock.recv((char*)buffer, len);
+// int stop = t.read_ms();
+ 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);
+ return rc;
}
int write(unsigned char* buffer, int len, int timeout)
{
- mysock.set_blocking(false, timeout);
- return mysock.send((char*)buffer, len);
+ mysock.set_timeout(timeout);
+// mysock.set_blocking(false, timeout);
+// mysock.set_blocking(false);
+ int rc = mysock.send((char*)buffer, len);
+// printf ("send File: %s, Line: %d Write nB: %d rc: %d\n\r",__FILE__,__LINE__, len, rc);
+ return rc;
}
int disconnect()
{
+// t.stop();
return mysock.close();
}
-
+
private:
-
- TCPSocketConnection mysock;
+ TCPSocket mysock;
+ // Timer t;
};
-
-
-
#endif
