MyLibrary12

Fork of WizFi310Interface_Legacy by WIZnet

Files at this revision

API Documentation at this revision

Comitter:
ajeet3004
Date:
Sun Sep 17 05:30:43 2017 +0000
Parent:
1:e08ea0ee2788
Commit message:
no change

Changed in this revision

Socket/Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/TCPSocketServer.h Show annotated file Show diff for this revision Revisions of this file
WizFi310/WizFi310.h Show annotated file Show diff for this revision Revisions of this file
WizFi310/WizFi310_at.cpp Show annotated file Show diff for this revision Revisions of this file
WizFi310/WizFi310_sock.cpp Show annotated file Show diff for this revision Revisions of this file
WizFi310Interface.cpp Show annotated file Show diff for this revision Revisions of this file
WizFi310Interface.h Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/Socket.cpp	Tue May 02 00:31:36 2017 +0000
+++ b/Socket/Socket.cpp	Sun Sep 17 05:30:43 2017 +0000
@@ -27,16 +27,18 @@
 #include <cstring>
 
 Socket::Socket() {
+    
     _wizfi310 = NULL;
     _wizfi310 = WizFi310::getInstance();
     if (_wizfi310 == NULL)
         error("Socket constructor error: no WizFi250 instance available!\r\n");
     _blocking = true;
-    _timeout = 1500;
+    _timeout = 2500;
 
     _server = false;
     _cid = -1;
     _port = 0;
+    printf("Socket done\n");
 }
 
 void Socket::set_blocking(bool blocking, unsigned int timeout) {
--- a/Socket/TCPSocketConnection.cpp	Tue May 02 00:31:36 2017 +0000
+++ b/Socket/TCPSocketConnection.cpp	Sun Sep 17 05:30:43 2017 +0000
@@ -34,16 +34,17 @@
 
     _server = false;
     _cid = _wizfi310->open(WizFi310::PROTO_TCP, get_address(), get_port());
+    printf("_cid : %d\n",_cid);
     if (_cid < 0 )  return -1;
 
     return 0;
 }
 
 bool TCPSocketConnection::is_connected(void)
-{
+{   printf("_cid: %d\n", _cid);
     bool _is_connected = _wizfi310->isConnected(_cid);
     if(!_is_connected)  _cid = -1;
-
+    printf(" is_connected: %d\n",_is_connected);
     return _is_connected;
 }
 
@@ -141,7 +142,7 @@
 
     if( _wizfi310->cmdSMGMT(cid) )  return;
     if( !_wizfi310->getRemote(_cid, &ip, &port))
-    {
+    { 
         set_address(ip, port);
     }
 }
--- a/Socket/TCPSocketServer.h	Tue May 02 00:31:36 2017 +0000
+++ b/Socket/TCPSocketServer.h	Sun Sep 17 05:30:43 2017 +0000
@@ -54,6 +54,7 @@
     \param connection A TCPSocketConnection instance that will handle the incoming connection.
     \return 0 on success, -1 on failure.
     */
+    
     int accept(TCPSocketConnection& connection);
 };
 
--- a/WizFi310/WizFi310.h	Tue May 02 00:31:36 2017 +0000
+++ b/WizFi310/WizFi310.h	Sun Sep 17 05:30:43 2017 +0000
@@ -106,6 +106,7 @@
         RES_FDNS,
         RES_SMGMT,
         RES_WSTATUS,
+        RES_SCON,
         
     };
 
@@ -143,6 +144,7 @@
     int cmdWJOIN    ();
     int cmdWLEAVE   ();
     int cmdWSTATUS  ();
+    int cmdSCON     ();
     int cmdSCON     ( const char *openType, const char *socketType, int localPort, const char *dataMode = "0");
     int cmdSCON     ( const char *openType, const char *socketType, const char *remoteIp, int remotePort, int localPort = 0, const char *dataMode = "0");
     int cmdSSEND    ( const char *data, int cid, int sendSize, const char *remoteIp = NULL, int remotePort = 0, int Timeout = 2000 );
@@ -327,6 +329,8 @@
     
     //daniel for mqtt
     char rcvd_mqtt_topic[128];
+    
+     bool test(void);
 
 };
 
--- a/WizFi310/WizFi310_at.cpp	Tue May 02 00:31:36 2017 +0000
+++ b/WizFi310/WizFi310_at.cpp	Sun Sep 17 05:30:43 2017 +0000
@@ -166,7 +166,7 @@
 int WizFi310::cmdWANT(AntennaMode mode)
 {
     char cmd[CFG_CMD_SIZE];
-    sprintf(cmd, "AT+WANT=%d",mode);
+    sprintf(cmd, "AT+WANT=%d",mode); 
     
     return sendCommand(cmd);
 }
@@ -215,7 +215,7 @@
     if( cmdWSTATUS() )
         return -1;
 
-    WIZ_INFO("WizFi310 is successfully join to AP");
+    //WIZ_INFO("WizFi310 is successfully join to AP");
 
     return 0;
 }
@@ -347,3 +347,14 @@
     resp = sendCommand("AT+SMGMT=?", RES_SMGMT);
     return resp;
 }
+
+
+int WizFi310::cmdSCON()
+{
+    int resp;
+
+    resp = sendCommand("AT+SCON=?", RES_SCON,1500);
+    printf("Response: %d \n", resp);
+    return resp;
+}
+
--- a/WizFi310/WizFi310_sock.cpp	Tue May 02 00:31:36 2017 +0000
+++ b/WizFi310/WizFi310_sock.cpp	Sun Sep 17 05:30:43 2017 +0000
@@ -77,6 +77,8 @@
     _con[cid].protocol = proto;
     _con[cid].type = TYPE_CLIENT;
     _con[cid].func = func;
+    printf("TYPE : %d\n",_con[cid].type);
+
     return cid;
 }
 
--- a/WizFi310Interface.cpp	Tue May 02 00:31:36 2017 +0000
+++ b/WizFi310Interface.cpp	Sun Sep 17 05:30:43 2017 +0000
@@ -64,6 +64,8 @@
 	return cmdWLEAVE();
 }
 
+
+
 char* WizFi310Interface::getMACAddress()
 {
     return _state.mac;
@@ -83,5 +85,45 @@
 {
 	return cmdWANT(mode);
 }
+//int WizFi310Interface::test()
+//{
+//	return cmdWSTATUS();
+//}
 
+
+int WizFi310Interface::test_weathermap()
+{   
+	// TCPSocketConnection();
+   int errConnect;
+    char http_cmd1[1000] = "";
+    char buffer[2048] = "";
+	TCPSocketConnection TCPconnection;
+
+   char *p="api.openweathermap.org";
+   int a=TCPconnection.connect(p,80);
+  while (true) {
+        if(a!=0) {
+            printf("\r\ncould not connect to socket : error = %d\r\n", p);
+            a = TCPconnection.connect(p, 80);
+        } else {
+            printf("socket connected\r\n");
+            break;
+        }
+    }    
+     char http_cmd[] = "GET /data/2.5/weather?q=Seoul,kr&appid=a0ca47dd7f6066404629b3e1ad728981 HTTP/1.0\n\n";
+          //char http_cmd[] = "GET /data/2.5/weather?q=London,us&appid=a0ca47dd7f6066404629b3e1ad728981 HTTP/1.0\n\n";
+        //char http_cmd[] = "GET /data/2.5/weather?q=Berlin,de&appid=a0ca47dd7f6066404629b3e1ad728981 HTTP/1.0\n\n";
+     
+    sprintf((char *)http_cmd1,http_cmd);
+
+    TCPconnection.send_all(http_cmd, sizeof(http_cmd));
+    
+    TCPconnection.receive_all(buffer, sizeof(buffer));
+    printf("%s",buffer);
+  
+	
+		return 0;
+	}
 //char* getNetworkMask();
+
+
--- a/WizFi310Interface.h	Tue May 02 00:31:36 2017 +0000
+++ b/WizFi310Interface.h	Sun Sep 17 05:30:43 2017 +0000
@@ -27,8 +27,10 @@
 #define WIZFI310INTERFACE_H_
 
 #include "WizFi310.h"
+#include "TCPSocketConnection.h"
 
-class WizFi310Interface : public WizFi310{
+
+class WizFi310Interface : public WizFi310,public TCPSocketConnection{
 public:
 
     WizFi310Interface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200);
@@ -37,6 +39,7 @@
     int init(const char* ip, const char* mask, const char* gateway, const char* name = NULL);
     int connect(Security sec, const char* ssid, const char* phrase, WiFiMode mode = WM_STATION);
     int disconnect();
+    int test_weathermap();
     char* getMACAddress();
     char* getIPAddress();
     char* getGateway();
@@ -44,7 +47,6 @@
     
     int setAntMode(AntennaMode mode);
 
-
 };