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
MQTTSocket.h
- Committer:
- mapellil
- Date:
- 2016-09-28
- Revision:
- 48:66826ea709ea
- Parent:
- 47:24f2bf2819a5
File content as of revision 48:66826ea709ea:
#if !defined(MQTTSOCKET_H)
#define MQTTSOCKET_H
#include "MQTTmbed.h"
#include "TCPSocket.h"
class MQTTSocket
{
public:
int open(NetworkStack *ipstack)
{
return mysock.open(ipstack);
}
int connect(char* hostname, int port, int timeout=1000)
{
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_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_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:
TCPSocket mysock;
// Timer t;
};
#endif
