MBED_DEMOS / Mbed 2 deprecated mbed_mqtt_endpoint_ublox_ethernet

Dependencies:   C027 C12832 EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Sat Mar 01 05:58:00 2014 +0000
Parent:
35:27484c1273f9
Child:
37:c6c94f1b3e5d
Commit message:
updates

Changed in this revision

EmulatedResourceFactory.cpp Show annotated file Show diff for this revision Revisions of this file
IOCHTTPTransport.cpp Show annotated file Show diff for this revision Revisions of this file
IOCHTTPTransport.h Show annotated file Show diff for this revision Revisions of this file
LM75B.lib Show annotated file Show diff for this revision Revisions of this file
MBEDEndpoint.cpp Show annotated file Show diff for this revision Revisions of this file
MBEDEndpoint.h Show annotated file Show diff for this revision Revisions of this file
MQTTTransport.cpp Show annotated file Show diff for this revision Revisions of this file
endpoint_core.lib Show annotated file Show diff for this revision Revisions of this file
--- a/EmulatedResourceFactory.cpp	Fri Feb 28 23:45:13 2014 +0000
+++ b/EmulatedResourceFactory.cpp	Sat Mar 01 05:58:00 2014 +0000
@@ -53,7 +53,7 @@
     this->createResource("/gps/fix","1");
     this->createResource("/nw/pipaddr","N/A");
     this->createResource("/nw/prssi","N/A");
-    this->createResource("/sen/temp","0.0");
+    this->createResource("/sen/temp","0C");
     this->createResource("/sen/V","5.0");
     this->createResource("/gps/loc",ENDPOINT_GPS_COORDS);
  } 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IOCHTTPTransport.cpp	Sat Mar 01 05:58:00 2014 +0000
@@ -0,0 +1,104 @@
+/* Copyright C2013 Doug Anson, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files the "Software", to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+ #include "IOCHTTPTransport.h"
+   
+ // default constructor
+ IOCHTTPTransport::IOCHTTPTransport(ErrorHandler *error_handler,void *endpoint) : HTTPTransport(error_handler,endpoint) {
+     memset(this->m_url_buffer,0,IOC_REST_URL_LEN+1);
+ }
+ 
+ // default destructor
+ IOCHTTPTransport::~IOCHTTPTransport() {
+ }
+ 
+ // package up data
+ char *IOCHTTPTransport::packageData(char *verb,char *data,int ioc_id) {
+     char buffer[IOC_PAYLOAD_LEN+1];
+     memset(buffer,0,IOC_PAYLOAD_LEN+1);
+     if (USE_GW_HTTP_REDIRECTOR == false) {
+         // just use the data
+         return data;
+     }
+     else {
+         // repackage into format: VERB;USER;PASS;AUTHDOMAIN;CONTENTTYPE;JSON;URL
+         sprintf(buffer,"%s;%s;%s;_none_;%s;%s;%s ",verb,IOC_USERNAME,IOC_PASSWORD,"application/json",data,this->createIOCUpdateURL(ioc_id,false));
+         memcpy(data,buffer,strlen(buffer));
+         return data;
+     }
+ }
+ 
+ // Load up our endpoint into the IOC
+ bool IOCHTTPTransport::loadEndpoint(char *data,int data_length,char *result,int result_length) {
+    //this->logger()->log("loadEndpoint: %s",data); 
+    data = this->packageData("POST",data,0);
+    return this->httpPost(this->createIOCLoadURL(),data,strlen(data),result,result_length); 
+ }
+ 
+ // update our endpoint with the IOC
+ bool IOCHTTPTransport::updateEndpoint(int ioc_id,char *data,int data_length,char *result,int result_length) { 
+    //this->logger()->log("updateEndpoint: %s",data);
+    data = this->packageData("PUT",data,ioc_id);
+    return this->httpPut(this->createIOCUpdateURL(ioc_id),data,strlen(data),result,result_length); 
+ }
+ 
+ // create the IOC load URL
+ char *IOCHTTPTransport::createIOCLoadURL() { return this->createIOCUpdateURL(0); }
+ 
+ // create the IOC update URL
+ char *IOCHTTPTransport::createIOCUpdateURL(int ioc_id) { return this->createIOCUpdateURL(ioc_id,USE_GW_HTTP_REDIRECTOR); }
+ char *IOCHTTPTransport::createIOCUpdateURL(int ioc_id,bool useRedirector) {
+     if (useRedirector == false) {
+         // make HTTP calls directly
+         char ioc_id_str[IOC_IOC_ID_LEN+1];
+         memset(ioc_id_str,0,IOC_IOC_ID_LEN+1);
+         if (ioc_id > 0) sprintf(ioc_id_str,"/%d",ioc_id);
+         memset(this->m_url_buffer,0,IOC_REST_URL_LEN+1);
+         sprintf(this->m_url_buffer,IOC_REST_URL,IOC_HOST_NAME,IOC_DATASOURCE_ID,ioc_id_str);
+     }
+     else {
+         // use the GW HTTP redirector
+         memset(this->m_url_buffer,0,IOC_REST_URL_LEN+1);
+         sprintf(this->m_url_buffer,GW_REDIRECT_URL,GW_IPADDRESS);
+     }
+     return this->m_url_buffer;
+ }    
+ 
+ // HTTP Get
+ bool IOCHTTPTransport::httpGet(char *url,char *result,int result_length) {
+    this->m_http->basicAuth(IOC_USERNAME,IOC_PASSWORD);
+    return HTTPTransport::httpGet(url,result,result_length);
+ }
+ 
+ // HTTP Put
+ bool IOCHTTPTransport::httpPut(char *url,char *data,int data_length,char *result,int result_length) {
+     this->m_http->basicAuth(IOC_USERNAME,IOC_PASSWORD);
+     return HTTPTransport::httpPut(url,data,data_length,result,result_length);
+ }
+ 
+ // HTTP Post
+ bool IOCHTTPTransport::httpPost(char *url,char *data,int data_length,char *result,int result_length) {
+     this->m_http->basicAuth(IOC_USERNAME,IOC_PASSWORD);
+     return HTTPTransport::httpPost(url,data,data_length,result,result_length);
+ }
+ 
+ // HTTP Delete
+  bool IOCHTTPTransport::httpDelete(char *url,char *data,int data_length) {
+    this->m_http->basicAuth(IOC_USERNAME,IOC_PASSWORD);
+    return HTTPTransport::httpDelete(url,data,data_length);
+ }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IOCHTTPTransport.h	Sat Mar 01 05:58:00 2014 +0000
@@ -0,0 +1,48 @@
+/* Copyright C2013 Doug Anson, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files the "Software", to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+#ifndef _IOC_HTTP_TRANSPORT_H_
+#define _IOC_HTTP_TRANSPORT_H_
+
+// Base Class
+#include "HTTPTransport.h"
+
+class IOCHTTPTransport : public HTTPTransport {
+    private:
+        char        m_url_buffer[IOC_REST_URL_LEN+1];
+
+    public:
+        IOCHTTPTransport(ErrorHandler *error_handler,void *endpoint);
+        virtual ~IOCHTTPTransport();
+        
+        virtual bool httpGet(char *url,char *result,int result_length);
+        virtual bool httpPut(char *url,char *data,int data_length,char *result,int result_length);
+        virtual bool httpPost(char *url,char *data,int data_length,char *result,int result_length);
+        virtual bool httpDelete(char *url,char *data,int data_length);
+        
+        virtual bool loadEndpoint(char *data,int data_length,char *result,int result_length);
+        virtual bool updateEndpoint(int ioc_id,char *data,int data_length,char *result,int result_length); 
+                
+    private:
+        char *createIOCLoadURL();
+        char *packageData(char *verb,char *data,int ioc_id);
+        char *createIOCUpdateURL(int ioc_id);
+        char *createIOCUpdateURL(int ioc_id,bool useRedirector);
+ };
+
+#endif // _IOC_HTTP_TRANSPORT_H_
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.lib	Sat Mar 01 05:58:00 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
--- a/MBEDEndpoint.cpp	Fri Feb 28 23:45:13 2014 +0000
+++ b/MBEDEndpoint.cpp	Sat Mar 01 05:58:00 2014 +0000
@@ -133,7 +133,7 @@
       
       if (success == true) {
           // HTTP Initialization
-          success = this->initializeTransport(HTTP_TRANSPORT,"HTTP",new HTTPTransport(this->m_error_handler,this));
+          success = this->initializeTransport(HTTP_TRANSPORT,"HTTP",new IOCHTTPTransport(this->m_error_handler,this));
       }
       return success;
  }
--- a/MBEDEndpoint.h	Fri Feb 28 23:45:13 2014 +0000
+++ b/MBEDEndpoint.h	Sat Mar 01 05:58:00 2014 +0000
@@ -30,7 +30,7 @@
 
 // Transport support
 #include "MQTTTransport.h"
-#include "HTTPTransport.h"
+#include "IOCHTTPTransport.h"
 
 // Light Support
 #include "Light.h"
--- a/MQTTTransport.cpp	Fri Feb 28 23:45:13 2014 +0000
+++ b/MQTTTransport.cpp	Sat Mar 01 05:58:00 2014 +0000
@@ -214,7 +214,7 @@
          bool sent = this->m_mqtt->publish(this->getTopic(),message,strlen(message));
          if (sent) {
              this->logger()->log("Result sent successfully");
-             this->logger()->blinkMQTTTransportTxLED();
+             this->logger()->blinkTransportTxLED();
          }
          else {
              this->logger()->log("Result send FAILED");
@@ -302,6 +302,6 @@
  void MQTTTransport::checkAndProcess() {
      if (this->m_mqtt != NULL && this->m_connected == true) {
          this->m_mqtt->loop();
-         this->logger()->blinkMQTTTransportRxLED();
+         this->logger()->blinkTransportRxLED();
      }
  }
\ No newline at end of file
--- a/endpoint_core.lib	Fri Feb 28 23:45:13 2014 +0000
+++ b/endpoint_core.lib	Sat Mar 01 05:58:00 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/ansond/code/endpoint_core/#e1680bf9606d
+http://mbed.org/users/ansond/code/endpoint_core/#1588ba3af6d1