Thinger.io Client Library for the WIZnet platform

Dependencies:   ThingerClient WIZnetInterface

Fork of ThingerWIZnetClient by Alvaro Luis Bustamante

Files at this revision

API Documentation at this revision

Comitter:
alvarolb
Date:
Thu Dec 24 18:42:10 2015 +0000
Child:
1:db9212d9415d
Commit message:
Initial Commit

Changed in this revision

TCPSocket.h Show annotated file Show diff for this revision Revisions of this file
ThingerClient.lib Show annotated file Show diff for this revision Revisions of this file
ThingerEthernetClient.h Show annotated file Show diff for this revision Revisions of this file
WIZnetInterface.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCPSocket.h	Thu Dec 24 18:42:10 2015 +0000
@@ -0,0 +1,15 @@
+#include "TCPSocketConnection.h"
+
+class TCPSocket : public TCPSocketConnection
+{
+public:
+    TCPSocket() {
+    }
+
+    virtual ~TCPSocket() {
+    }
+
+    int available() {
+        return eth->wait_readable(_sock_fd, _blocking ? -1 : _timeout);
+    }
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThingerClient.lib	Thu Dec 24 18:42:10 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/alvarolb/code/ThingerClient/#b75d784c7c1a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThingerEthernetClient.h	Thu Dec 24 18:42:10 2015 +0000
@@ -0,0 +1,71 @@
+#include "ThingerClient.h"
+#include "EthernetInterface.h"
+#include "TCPSocket.h"
+
+class ThingerEthernetClient : public ThingerClient
+{
+private:
+    EthernetInterface ethernet;
+    TCPSocket socket;
+
+public:
+    ThingerEthernetClient(const char* user, const char* device, const char* device_credential) :
+        ThingerClient(user, device, device_credential), connected_(false)
+    {}
+
+    virtual ~ThingerEthernetClient() {
+    }
+
+protected:
+
+    virtual bool socket_start(const char* host, int port) {
+        return socket.connect(host, port)==0;
+    }
+
+    virtual bool socket_stop() {
+        return socket.close()==0;
+    }
+
+    virtual bool socket_connected() {
+        return socket.is_connected();
+    }
+
+    virtual size_t socket_read(char* buffer, size_t size) {
+        return socket.receive_all(buffer, size);
+    }
+
+    virtual size_t socket_write(char* buffer, size_t size) {
+        return socket.send_all(buffer, size);
+    }
+
+    virtual size_t socket_available() {
+        return socket.available();
+    }
+
+    virtual bool connect_network() {
+        if(connected_) return true;
+        ethernet.init();
+        
+#ifdef _DEBUG_
+        printf("[NETWORK] Getting DHCP IP Address...\r\n");
+#endif
+        while(ethernet.connect()!=0) {
+            wait(5);
+            ethernet.disconnect();
+            ethernet.init();
+        }
+#ifdef _DEBUG_
+        printf("[NETWORK] Got Ip Address: %s\r\n", ethernet.getIPAddress());
+#endif
+        connected_ = true;
+        return connected_;
+    }
+
+    virtual bool network_connected() {
+        return connected_;
+    }
+
+private:
+    bool connected_;
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WIZnetInterface.lib	Thu Dec 24 18:42:10 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/WIZnet/code/WIZnetInterface/#c91884bd2713