Hung Nguyen
/
CIS541-HW-MQTT
This is the codebase provided for CIS541 - Homework MQTT.
Revision 1:91e33a7fe0b5, committed 2017-10-07
- Comitter:
- hungnguyenm
- Date:
- Sat Oct 07 14:52:56 2017 +0000
- Parent:
- 0:f0db757d6ffe
- Commit message:
- Added HW6 codebase
Changed in this revision
diff -r f0db757d6ffe -r 91e33a7fe0b5 MQTT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTT.lib Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/teams/mqtt/code/MQTT/#ff9e5c4b52d0
diff -r f0db757d6ffe -r 91e33a7fe0b5 MQTTNetwork.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTTNetwork.h Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,38 @@ +#ifndef _MQTTNETWORK_H_ +#define _MQTTNETWORK_H_ + +#include "NetworkInterface.h" + +class MQTTNetwork { +public: + MQTTNetwork(NetworkInterface* aNetwork) : network(aNetwork) { + socket = new TCPSocket(); + } + + ~MQTTNetwork() { + delete socket; + } + + int read(unsigned char* buffer, int len, int timeout) { + return socket->recv(buffer, len); + } + + int write(unsigned char* buffer, int len, int timeout) { + return socket->send(buffer, len); + } + + int connect(const char* hostname, int port) { + socket->open(network); + return socket->connect(hostname, port); + } + + int disconnect() { + return socket->close(); + } + +private: + NetworkInterface* network; + TCPSocket* socket; +}; + +#endif // _MQTTNETWORK_H_
diff -r f0db757d6ffe -r 91e33a7fe0b5 MQTTmbed.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTTmbed.h Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,50 @@ +// hot fix for NonCopyable error +// @Hung Nguyen + +#if !defined(MQTT_MBED_H) +#define MQTT_MBED_H + +#include "mbed.h" + +class Countdown +{ +public: + Countdown() { + t = new Timer(); + } + + Countdown(int ms) { + t = new Timer(); + countdown_ms(ms); + } + + ~Countdown() { + delete t; + } + + + bool expired() { + return t->read_ms() >= interval_end_ms; + } + + void countdown_ms(unsigned long ms) { + t->stop(); + interval_end_ms = ms; + t->reset(); + t->start(); + } + + void countdown(int seconds) { + countdown_ms((unsigned long)seconds * 1000L); + } + + int left_ms() { + return interval_end_ms - t->read_ms(); + } + +private: + Timer* t; + unsigned long interval_end_ms; +}; + +#endif \ No newline at end of file
diff -r f0db757d6ffe -r 91e33a7fe0b5 esp8266-driver.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/esp8266-driver.lib Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/esp8266-driver/#fdb44a4bedbb5879a8ff9afd864e296765c20f22
diff -r f0db757d6ffe -r 91e33a7fe0b5 main.cpp --- a/main.cpp Sat Oct 07 03:48:31 2017 +0000 +++ b/main.cpp Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,12 @@ +#define MQTTCLIENT_QOS2 1 + +#include "ESP8266Interface.h" +#include "MQTTNetwork.h" +#include "MQTTmbed.h" +#include "MQTTClient.h" + +ESP8266Interface wifi(p28, p27); + +int main(int argc, char* argv[]) { + return 0; +} \ No newline at end of file
diff -r f0db757d6ffe -r 91e33a7fe0b5 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#3179b1cffddea0f0feed1dd551b0e7dc946c12f5
diff -r f0db757d6ffe -r 91e33a7fe0b5 mbed_app.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Sat Oct 07 14:52:56 2017 +0000 @@ -0,0 +1,19 @@ +{ + "config": { + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"your ssid\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"your ssid password\"" + } + }, + "target_overrides": { + "*": { + "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"], + "platform.stdio-convert-newlines": true, + "mbed-trace.enable": 0 + } + } +}