Thinger.io Client Library for the WIZnet platform

Dependencies:   ThingerClient WIZnetInterface

Fork of ThingerWIZnetClient by Alvaro Luis Bustamante

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ThingerEthernetClient.h Source File

ThingerEthernetClient.h

00001 #include "ThingerClient.h"
00002 #include "EthernetInterface.h"
00003 #include "TCPSocket.h"
00004 
00005 class ThingerEthernetClient : public ThingerClient
00006 {
00007 private:
00008     EthernetInterface ethernet;
00009     TCPSocket socket;
00010 
00011 public:
00012     ThingerEthernetClient(const char* user, const char* device, const char* device_credential) :
00013         ThingerClient(user, device, device_credential), connected_(false)
00014     {}
00015 
00016     virtual ~ThingerEthernetClient() {
00017     }
00018 
00019 protected:
00020 
00021     virtual bool socket_start(const char* host, int port) {
00022         return socket.connect(host, port)==0;
00023     }
00024 
00025     virtual bool socket_stop() {
00026         return socket.close()==0;
00027     }
00028 
00029     virtual bool socket_connected() {
00030         return socket.is_connected();
00031     }
00032 
00033     virtual size_t socket_read(char* buffer, size_t size) {
00034         return socket.receive_all(buffer, size);
00035     }
00036 
00037     virtual size_t socket_write(char* buffer, size_t size) {
00038         return socket.send_all(buffer, size);
00039     }
00040 
00041     virtual size_t socket_available() {
00042         return socket.available();
00043     }
00044 
00045     virtual bool connect_network() {
00046         if(connected_) return true;
00047         ethernet.init();
00048         
00049 #ifdef _DEBUG_
00050         printf("[NETWORK] Getting DHCP IP Address...\r\n");
00051 #endif
00052         while(ethernet.connect()!=0) {
00053             wait(5);
00054             ethernet.disconnect();
00055             ethernet.init();
00056         }
00057 #ifdef _DEBUG_
00058         printf("[NETWORK] Got Ip Address: %s\r\n", ethernet.getIPAddress());
00059 #endif
00060         connected_ = true;
00061         return connected_;
00062     }
00063 
00064     virtual bool network_connected() {
00065         return connected_;
00066     }
00067 
00068 private:
00069     bool connected_;
00070 };
00071