HTTP/HTTPS Client Library for the X-NUCLEO-IDW01M1v2 wifi board.

Dependents:   HTTPClient_HelloWorld_IDW01M1 wifigianluigi HTTPClient_HelloWorld_IDW01M1_Fabio_Ricezione

Fork of HTTPClient by ST Expansion SW Team

Files at this revision

API Documentation at this revision

Comitter:
mapellil
Date:
Fri Nov 11 16:13:48 2016 +0000
Parent:
20:bbbfaf4cc055
Child:
22:ae30428dc030
Commit message:
Changed constructor, removed HTTP sock wrapper

Changed in this revision

HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPClient.h Show annotated file Show diff for this revision Revisions of this file
HTTPSocket.h Show diff for this revision Revisions of this file
HTTPWifi.h Show diff for this revision Revisions of this file
--- a/HTTPClient.cpp	Tue Nov 08 17:21:42 2016 +0000
+++ b/HTTPClient.cpp	Fri Nov 11 16:13:48 2016 +0000
@@ -45,11 +45,10 @@
 #define MAX_VALUE   64
 
 #include <cstring>
-
 #include "HTTPClient.h"
 
-HTTPClient::HTTPClient(HTTPWiFi & _m_sock) : m_sock(_m_sock) 
-{
+HTTPClient::HTTPClient(NetworkStack  & _m_intf) : m_intf(_m_intf)
+{    
 }
 
 HTTPClient::~HTTPClient()
@@ -147,8 +146,7 @@
   DBG("Port: %d", port);
   DBG("Path: %s", path);
 // Open
-  m_sock.open(&m_sock.getWiFi());
-
+  m_sock.open(&m_intf);
   //Connect
   DBG("Connecting socket to server");
   int ret = m_sock.connect(host, port);
@@ -172,7 +170,6 @@
     ERR("Could not write request");
     return HTTP_CONN;
   }
-
   //Send all headers
  
   //Send default headers
--- a/HTTPClient.h	Tue Nov 08 17:21:42 2016 +0000
+++ b/HTTPClient.h	Fri Nov 11 16:13:48 2016 +0000
@@ -24,8 +24,11 @@
 #ifndef HTTP_CLIENT_H
 #define HTTP_CLIENT_H
 
+//#include "TCPSocket.h"
+//#include "HTTPWifi.h"
+#include "NetworkStack.h"
 #include "TCPSocket.h"
-#include "HTTPWifi.h"
+#include "SpwfInterface.h"
 
 #define LICIO
 #define HTTP_CLIENT_DEFAULT_TIMEOUT 15000
@@ -62,7 +65,8 @@
 {
 public:
   ///Instantiate the HTTP client
-  HTTPClient(HTTPWiFi & _m_sock);  
+  HTTPClient(NetworkStack & _m_intf);      
+
   ~HTTPClient();
   
 #if 0 //TODO add header handlers
@@ -146,15 +150,15 @@
   HTTPResult parseURL(const char* url, char* scheme, size_t maxSchemeLen, char* host, size_t maxHostLen, uint16_t* port, char* path, size_t maxPathLen); //Parse URL
 
   //Parameters 
-  HTTPWiFi m_sock;
-  
+  NetworkStack & m_intf;  // WiFi interface
+  TCPSocket  m_sock;         // TCP socket
+
   int m_timeout;
 
   const char* m_basicAuthUser;
   const char* m_basicAuthPassword;
   int m_httpResponseCode;
   char buf[CHUNK_SIZE];
-
 };
 
 //Including data containers here for more convenience
--- a/HTTPSocket.h	Tue Nov 08 17:21:42 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,70 +0,0 @@
-#if !defined(HTTPSOCKET_H)
-#define HTTPSOCKET_H
-
-#include "mbed.h"
-#include "TCPSocket.h"
-
-class HTTPSocket
-{
-public:
-
-    int open(NetworkStack *ipstack)
-    {
-        return mysock.open(ipstack);        
-    }
-  
-    int connect(char* hostname, int port, int timeout=1000)
-    {
-        int err;
-        mysock.set_timeout(timeout);
-//SocketAddress addr(&spwf, hostname);   
-//    pc.printf("\r\nst.com resolved to: %s\r\n", addr.get_ip_address());         
-        
-//        printf ("TCP hostaname: %s, port: %d\n\r", hostname, port);
-        err = mysock.connect(hostname, port);  
-//    t.start();             
-        return err; 
-    }
-
-//    int read(unsigned char* buffer, int len, int timeout)
-    int recv(char* buffer, int len)
-    {
-//        mysock.set_timeout(timeout);        
-//t.reset();
-// int start = t.read_ms();
-        int rc = mysock.recv((char*)buffer, len);
-// int stop = t.read_ms();       
-//        if (rc>0) printf ("recv File: %s, Line: %d Read nB: %d rc: %d timeout: %d elaps: %d\n\r",__FILE__,__LINE__, len, rc, timeout, stop-start);        
-        return rc;
-    }
-    
-//    int write(unsigned char* buffer, int len, int timeout)
-    int send(char* buffer, int len)    
-    {
-//        mysock.set_timeout(timeout);                
-//        mysock.set_blocking(false, timeout);  
-//        mysock.set_blocking(false);  
-        int rc = mysock.send((char*)buffer, len);
-//         printf ("send File: %s, Line: %d Write nB: %d rc: %d\n\r",__FILE__,__LINE__, len, rc);
-        return rc;
-    }
-    
-    int set_blocking(bool mode) 
-    {
-        mysock.set_blocking (mode);     
-    }
-
-    
-//    int disconnect()
-    int close()
-    {
-//        t.stop();
-        return mysock.close();
-    }
-     
-private:
-    TCPSocket mysock; 
- //   Timer t;
-    
-};
-#endif
--- a/HTTPWifi.h	Tue Nov 08 17:21:42 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-
-#if !defined(HTTPWIFI_H)
-#define HTTPWIFI_H
-
-#include "mbed.h"
-#include "SpwfInterface.h"
-#include "WiFiInterface.h"
-#include "HTTPSocket.h"
-
-class HTTPWiFi : public HTTPSocket
-{
-public:    
-    HTTPWiFi(SpwfSAInterface &WiFiIntf, const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE) : WiFi(WiFiIntf)
-    {
-//        eth.init();                          // Use DHCP
-        WiFi.connect(ssid, pass,  security);
-        printf ("WIFI ssid: %s connected\n\r", ssid);
-    }
-    
-    SpwfSAInterface& getWiFi()
-    {
-        return WiFi;
-    }
-    
-/*    void reconnect()
-    {
-        WiFi.connect();  // nothing I've tried actually works to reconnect 
-    }
-*/   
-
-private:
-
-SpwfSAInterface& WiFi;
-    
-};
-#endif