mbed mqtt

Dependencies:   TextLCD MQTT IAP

Files at this revision

API Documentation at this revision

Comitter:
hungnguyenm
Date:
Sat Oct 07 14:52:56 2017 +0000
Parent:
0:f0db757d6ffe
Child:
2:562744909841
Commit message:
Added HW6 codebase

Changed in this revision

MQTT.lib Show annotated file Show diff for this revision Revisions of this file
MQTTNetwork.h Show annotated file Show diff for this revision Revisions of this file
MQTTmbed.h Show annotated file Show diff for this revision Revisions of this file
esp8266-driver.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- /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
--- /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_
--- /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
--- /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
--- 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
--- /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
--- /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
+        }
+    }
+}