Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Child:
8:80d49dd91542
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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