iot_water_monitor_v2

Dependencies:   easy-connect-v16 Watchdog FP MQTTPacket RecordType-v-16 watersenor_and_temp_code

Committer:
DuyLionTran
Date:
Tue Apr 03 17:03:01 2018 +0000
Revision:
57:898fcb6692cd
Parent:
32:8226837c56ae
;   * version 2.9.8  	03-04-2018  Minor changes. Time frame updated to IBM Watson every 60s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DuyLionTran 32:8226837c56ae 1 #ifndef _MQTTNETWORK_H_
DuyLionTran 32:8226837c56ae 2 #define _MQTTNETWORK_H_
DuyLionTran 32:8226837c56ae 3
DuyLionTran 32:8226837c56ae 4 #include "NetworkInterface.h"
DuyLionTran 32:8226837c56ae 5
DuyLionTran 32:8226837c56ae 6 class MQTTNetwork {
DuyLionTran 32:8226837c56ae 7 public:
DuyLionTran 32:8226837c56ae 8 MQTTNetwork(NetworkInterface* aNetwork) : network(aNetwork) {
DuyLionTran 32:8226837c56ae 9 socket = new TCPSocket();
DuyLionTran 32:8226837c56ae 10 }
DuyLionTran 32:8226837c56ae 11
DuyLionTran 32:8226837c56ae 12 ~MQTTNetwork() {
DuyLionTran 32:8226837c56ae 13 delete socket;
DuyLionTran 32:8226837c56ae 14 }
DuyLionTran 32:8226837c56ae 15
DuyLionTran 32:8226837c56ae 16 int read(unsigned char* buffer, int len, int timeout) {
DuyLionTran 32:8226837c56ae 17 socket->set_timeout(timeout);
DuyLionTran 32:8226837c56ae 18 return socket->recv(buffer, len);
DuyLionTran 32:8226837c56ae 19 }
DuyLionTran 32:8226837c56ae 20
DuyLionTran 32:8226837c56ae 21 int write(unsigned char* buffer, int len, int timeout) {
DuyLionTran 32:8226837c56ae 22 socket->set_timeout(timeout);
DuyLionTran 32:8226837c56ae 23 return socket->send(buffer, len);
DuyLionTran 32:8226837c56ae 24 }
DuyLionTran 32:8226837c56ae 25
DuyLionTran 32:8226837c56ae 26 int connect(const char* hostname, int port) {
DuyLionTran 32:8226837c56ae 27 socket->open(network);
DuyLionTran 32:8226837c56ae 28 return socket->connect(hostname, port);
DuyLionTran 32:8226837c56ae 29 }
DuyLionTran 32:8226837c56ae 30
DuyLionTran 32:8226837c56ae 31 int disconnect() {
DuyLionTran 32:8226837c56ae 32 return socket->close();
DuyLionTran 32:8226837c56ae 33 }
DuyLionTran 32:8226837c56ae 34
DuyLionTran 32:8226837c56ae 35 private:
DuyLionTran 32:8226837c56ae 36 NetworkInterface* network;
DuyLionTran 32:8226837c56ae 37 TCPSocket* socket;
DuyLionTran 32:8226837c56ae 38 };
DuyLionTran 32:8226837c56ae 39
DuyLionTran 32:8226837c56ae 40 #endif // _MQTTNETWORK_H_