Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
97:d631edbc157b
Parent:
96:686ec39400dc
Child:
104:7a96a9a7cafb
diff -r 686ec39400dc -r d631edbc157b PhilipsLight.cpp
--- a/PhilipsLight.cpp	Fri Mar 14 20:20:32 2014 +0000
+++ b/PhilipsLight.cpp	Fri Mar 14 21:25:46 2014 +0000
@@ -18,10 +18,7 @@
  
  #include "PhilipsLight.h"
  #include "HTTPTransport.h"
- 
- // HTTP Client
- HTTPClient _philips_http;
- 
+  
  // default constructor
  PhilipsLight::PhilipsLight(int id,void *transport,ErrorHandler *error_handler) {
      this->m_id = id;
@@ -31,21 +28,11 @@
      memset(this->m_url,0,PL_URL_BUFFER_LEN+1);
      memset(this->m_payload,0,PL_PAYLOAD_BUFFER_LEN+1);
      memset(this->m_response,0,PL_RESPONSE_BUFFER_LEN+1);
-     this->initHttpTransport(transport);
+     this->m_transport = transport;
  }
  
  // destructor
  PhilipsLight::~PhilipsLight() {
-     HTTPTransport *transport = (HTTPTransport *)this->m_transport;
-     if (transport != NULL) delete transport;
- }
- 
- // initialize the transport
- void PhilipsLight::initHttpTransport(void *transport) {
-     if (transport != NULL && this->m_transport == NULL) {
-         HTTPTransport *http = (HTTPTransport *)transport;
-         this->m_transport = new HTTPTransport(&_philips_http,this->m_error_handler,http->getEndpoint());
-     }
  }
  
  // turn the light on
@@ -72,18 +59,21 @@
      // get the transport
      HTTPTransport *transport = (HTTPTransport *)this->m_transport;
      
+     // initialize the respones
+     memset(this->m_response,0,PL_RESPONSE_BUFFER_LEN+1);
+     
      // DEBUG
-     this->logger()->log("Setting Philips light: %d payload: %s",this->m_id,this->m_payload);
-     this->logger()->log("Setting Philips light: url: %s",this->m_url);
+     //this->logger()->log("Setting Philips light: %d payload: %s",this->m_id,this->m_payload);
+     //this->logger()->log("Setting Philips light: url: %s",this->m_url);
      
      // issue the PUT
      bool success = false;
      if (transport != NULL) success = transport->httpPut(this->m_url,this->m_payload,strlen(this->m_payload),this->m_response,PL_RESPONSE_BUFFER_LEN);
      
      // DEBUG
-     if (success) this->logger()->log("Philips Light: %d updated successfully",this->m_id);
-     else this->logger()->log("Philips Light: %d update FAILED.",this->m_id);
-     this->logger()->log("Philips Light: Response: %s",this->m_response);
+     //if (success) this->logger()->log("Philips Light: %d updated successfully",this->m_id);
+     //else this->logger()->log("Philips Light: %d update FAILED.",this->m_id);
+     //this->logger()->log("Philips Light: Response: %s",this->m_response);
  }
  
  // get the error handler