Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027 C12832 EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
Diff: HTTPTransport.cpp
- Revision:
- 10:748fc7052e61
- Parent:
- 9:ff877db53cfd
- Child:
- 11:59ee476fda24
diff -r ff877db53cfd -r 748fc7052e61 HTTPTransport.cpp
--- a/HTTPTransport.cpp Wed Feb 26 21:48:57 2014 +0000
+++ b/HTTPTransport.cpp Wed Feb 26 22:27:04 2014 +0000
@@ -37,10 +37,46 @@
HTTPTransport::~HTTPTransport() {
}
+ // build out the Payload
+ char *HTTPTransport::buildIOCPayload() {
+ MBEDEndpoint *endpoint = (MBEDEndpoint *)this->getEndpoint();
+ memset(this->m_payload_buffer,0,IOC_PAYLOAD_LEN+1);
+
+ // construct the payload for Load/Updates
+
+ // return the payload
+ return this->m_payload_buffer;
+ }
+
+ // save the IOC ID
+ void HTTPTransport::saveIOCID(char *data) {
+ MBEDEndpoint *endpoint = (MBEDEndpoint *)this->getEndpoint();
+ int ioc_id = -1;
+
+ // parse the IOC ID from the data result
+
+ // save the IOC ID
+ if (ioc_id > 0) endpoint->setIOCID(ioc_id);
+ }
+
// Load up our endpoint into the IOC
bool HTTPTransport::loadEndpoint() {
bool success = false;
+ // create the URL
+ char *url = this->createIOCLoadURL();
+
+ // build the payload
+ char *data = this->buildIOCPayload();
+
+ // issue the POST
+ memset(this->m_result_buffer,0,IOC_RESULT_LEN+1);
+ success = this->httpPost(url,data,strlen(data),(char *)this->m_result_buffer,IOC_RESULT_LEN);
+
+ // update the IOC ID if found
+ if (success) this->saveIOCID(this->m_result_buffer);
+
+ // return our status
return success;
}
@@ -48,8 +84,32 @@
bool HTTPTransport::updateEndpoint() {
bool success = false;
+ // create the URL
+ char *url = this->createIOCUpdateURL(endpoint->getIOCID());
+
+ // build the payload
+ char *data = this->buildIOCPayload();
+
+ // issue the PUT
+ memset(this->m_result_buffer,0,IOC_RESULT_LEN+1);
+ success = this->httpPut(url,data,strlen(data),(char *)this->m_result_buffer,IOC_RESULT_LEN);
+
+ // return our status
return success;
- }
+ }
+
+ // create the IOC load URL
+ char *HTTPTransport::createIOCLoadURL() { return this->createIOCUpdateURL(0); }
+
+ // create the IOC update URL
+ char *HTTPTransport::createIOCUpdateURL(int ioc_id) {
+ char ioc_id_str[16];
+ memset(ioc_id_str,0,16);
+ 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);
+ return this->m_url_buffer;
+ }
// connect up HTTP
bool HTTPTransport::connect() { return this->m_connected; }