USE YHTANG AWS ACCOUNT TO TEST MQTT

Dependencies:   MQTTPacket FP

Dependents:   NuMaker-mbed-AWS-IoT-example

Committer:
icraggs
Date:
Thu May 22 23:58:08 2014 +0000
Revision:
31:a51dd239b78e
Child:
36:2f1ada427e56
Create MQTTSocket.h to not use EthernetInterface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
icraggs 31:a51dd239b78e 1 #if !defined(MQTTSOCKET_H)
icraggs 31:a51dd239b78e 2 #define MQTTSOCKET_H
icraggs 31:a51dd239b78e 3
icraggs 31:a51dd239b78e 4 #include "MQTT_mbed.h"
icraggs 31:a51dd239b78e 5 #include "TCPSocketConnection.h"
icraggs 31:a51dd239b78e 6
icraggs 31:a51dd239b78e 7 class MQTTSocket
icraggs 31:a51dd239b78e 8 {
icraggs 31:a51dd239b78e 9 public:
icraggs 31:a51dd239b78e 10 int connect(char* hostname, int port, int timeout=1000)
icraggs 31:a51dd239b78e 11 {
icraggs 31:a51dd239b78e 12 mysock.set_blocking(false, timeout); // 1 second Timeout
icraggs 31:a51dd239b78e 13 return mysock.connect(hostname, port);
icraggs 31:a51dd239b78e 14 }
icraggs 31:a51dd239b78e 15
icraggs 31:a51dd239b78e 16 int read(char* buffer, int len, int timeout)
icraggs 31:a51dd239b78e 17 {
icraggs 31:a51dd239b78e 18 mysock.set_blocking(false, timeout);
icraggs 31:a51dd239b78e 19 return mysock.receive(buffer, len);
icraggs 31:a51dd239b78e 20 }
icraggs 31:a51dd239b78e 21
icraggs 31:a51dd239b78e 22 int write(char* buffer, int len, int timeout)
icraggs 31:a51dd239b78e 23 {
icraggs 31:a51dd239b78e 24 mysock.set_blocking(false, timeout);
icraggs 31:a51dd239b78e 25 return mysock.send(buffer, len);
icraggs 31:a51dd239b78e 26 }
icraggs 31:a51dd239b78e 27
icraggs 31:a51dd239b78e 28 int disconnect()
icraggs 31:a51dd239b78e 29 {
icraggs 31:a51dd239b78e 30 return mysock.close();
icraggs 31:a51dd239b78e 31 }
icraggs 31:a51dd239b78e 32
icraggs 31:a51dd239b78e 33 private:
icraggs 31:a51dd239b78e 34
icraggs 31:a51dd239b78e 35 TCPSocketConnection mysock;
icraggs 31:a51dd239b78e 36
icraggs 31:a51dd239b78e 37 };
icraggs 31:a51dd239b78e 38
icraggs 31:a51dd239b78e 39
icraggs 31:a51dd239b78e 40
icraggs 31:a51dd239b78e 41 #endif