porting to FRDM-K64F

Dependencies:   EthernetInterface FiapV2 HTTPClientForSOAP NTPClient mbed-rtos mbed spxml

Fork of FIAPHelloWorld by Yasushi TAUCHI

Committer:
yueee_yt
Date:
Sun Jan 01 14:46:02 2012 +0000
Revision:
0:0c7f2ea60a75

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yueee_yt 0:0c7f2ea60a75 1 #include "fiap.h"
yueee_yt 0:0c7f2ea60a75 2 #include "mbed.h"
yueee_yt 0:0c7f2ea60a75 3 FIAP::FIAP(string Storage,string PointSetId) {
yueee_yt 0:0c7f2ea60a75 4 debug_mode=false;
yueee_yt 0:0c7f2ea60a75 5 _fiap_storage=Storage;
yueee_yt 0:0c7f2ea60a75 6 _fiap_id_prefix=PointSetId;
yueee_yt 0:0c7f2ea60a75 7
yueee_yt 0:0c7f2ea60a75 8 _soap_header ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
yueee_yt 0:0c7f2ea60a75 9 _soap_header += "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">";
yueee_yt 0:0c7f2ea60a75 10 _soap_header += "<soapenv:Body>";
yueee_yt 0:0c7f2ea60a75 11 _soap_header += "<ns2:dataRQ xmlns:ns2=\"http://soap.fiap.org/\">";
yueee_yt 0:0c7f2ea60a75 12 _soap_header += "<transport xmlns=\"http://gutp.jp/fiap/2009/11/\">";
yueee_yt 0:0c7f2ea60a75 13 _soap_header += "<body>";
yueee_yt 0:0c7f2ea60a75 14 _soap_header += "<pointSet id=\"" + _fiap_id_prefix +"\">";
yueee_yt 0:0c7f2ea60a75 15
yueee_yt 0:0c7f2ea60a75 16 _soap_footer ="</pointSet>";
yueee_yt 0:0c7f2ea60a75 17 _soap_footer+="</body>";
yueee_yt 0:0c7f2ea60a75 18 _soap_footer+="</transport>";
yueee_yt 0:0c7f2ea60a75 19 _soap_footer+="</ns2:dataRQ>";
yueee_yt 0:0c7f2ea60a75 20 _soap_footer+="</soapenv:Body>";
yueee_yt 0:0c7f2ea60a75 21 _soap_footer+="</soapenv:Envelope>";
yueee_yt 0:0c7f2ea60a75 22 _soap_footer+="\r\n\r\n";
yueee_yt 0:0c7f2ea60a75 23 }
yueee_yt 0:0c7f2ea60a75 24
yueee_yt 0:0c7f2ea60a75 25 int FIAP::post(struct fiap_element* v, unsigned int esize) {
yueee_yt 0:0c7f2ea60a75 26 HTTPClient http;
yueee_yt 0:0c7f2ea60a75 27 int i;
yueee_yt 0:0c7f2ea60a75 28 char requestBuffer[50];
yueee_yt 0:0c7f2ea60a75 29 string _date_time;
yueee_yt 0:0c7f2ea60a75 30 string _soap_text=_soap_header;
yueee_yt 0:0c7f2ea60a75 31 for (i=0; i<esize; i++) {
yueee_yt 0:0c7f2ea60a75 32 strftime(&requestBuffer[0],50,"%Y-%m-%dT%H:%M:%S.0000000",v[i].t);
yueee_yt 0:0c7f2ea60a75 33 _soap_text += "<point id=\"";
yueee_yt 0:0c7f2ea60a75 34 _soap_text += _fiap_id_prefix;
yueee_yt 0:0c7f2ea60a75 35 _soap_text += v[i].cid;
yueee_yt 0:0c7f2ea60a75 36 _soap_text += "\">";
yueee_yt 0:0c7f2ea60a75 37 _soap_text += "<value time=\"";
yueee_yt 0:0c7f2ea60a75 38 _soap_text += requestBuffer;
yueee_yt 0:0c7f2ea60a75 39 _soap_text += v[i].timezone;
yueee_yt 0:0c7f2ea60a75 40 _soap_text += "\">";
yueee_yt 0:0c7f2ea60a75 41 _soap_text += v[i].value;
yueee_yt 0:0c7f2ea60a75 42 _soap_text += "</value>";
yueee_yt 0:0c7f2ea60a75 43 _soap_text += "</point>";
yueee_yt 0:0c7f2ea60a75 44 }
yueee_yt 0:0c7f2ea60a75 45 _soap_text += _soap_footer;
yueee_yt 0:0c7f2ea60a75 46 if(debug_mode){
yueee_yt 0:0c7f2ea60a75 47 printf(_soap_text.c_str());
yueee_yt 0:0c7f2ea60a75 48 printf("<<< Request(end)\n");
yueee_yt 0:0c7f2ea60a75 49 }
yueee_yt 0:0c7f2ea60a75 50 http.setRequestHeader("Content-Type","text/xml; charset=UTF-8");
yueee_yt 0:0c7f2ea60a75 51 http.setRequestHeader("SOAPAction","\"http://soap.fiap.org/data\"");
yueee_yt 0:0c7f2ea60a75 52 HTTPText InData;
yueee_yt 0:0c7f2ea60a75 53 InData.set(_soap_text.c_str());
yueee_yt 0:0c7f2ea60a75 54 HTTPText OutData;
yueee_yt 0:0c7f2ea60a75 55 HTTPResult r = http.post(_fiap_storage.c_str(),InData,&OutData);
yueee_yt 0:0c7f2ea60a75 56 if (r==HTTP_PROCESSING) {
yueee_yt 0:0c7f2ea60a75 57 if (debug_mode)printf("Processing \n");
yueee_yt 0:0c7f2ea60a75 58 return -1;
yueee_yt 0:0c7f2ea60a75 59 }
yueee_yt 0:0c7f2ea60a75 60 if (r==HTTP_PARSE) {
yueee_yt 0:0c7f2ea60a75 61 if (debug_mode) printf("URI Parse error \n");
yueee_yt 0:0c7f2ea60a75 62 return -1;
yueee_yt 0:0c7f2ea60a75 63 }
yueee_yt 0:0c7f2ea60a75 64 if (r==HTTP_DNS) {
yueee_yt 0:0c7f2ea60a75 65 if (debug_mode) printf("Could not resolve name\n");
yueee_yt 0:0c7f2ea60a75 66 return -1;
yueee_yt 0:0c7f2ea60a75 67 }
yueee_yt 0:0c7f2ea60a75 68 if (r==HTTP_PRTCL) {
yueee_yt 0:0c7f2ea60a75 69 if (debug_mode)printf("Protocol error\n");
yueee_yt 0:0c7f2ea60a75 70 return -1;
yueee_yt 0:0c7f2ea60a75 71 }
yueee_yt 0:0c7f2ea60a75 72 if (r==HTTP_NOTFOUND) {
yueee_yt 0:0c7f2ea60a75 73 if (debug_mode)printf("HTTP 404 Error\n");
yueee_yt 0:0c7f2ea60a75 74 return -1;
yueee_yt 0:0c7f2ea60a75 75 }
yueee_yt 0:0c7f2ea60a75 76 if (r==HTTP_REFUSED) {
yueee_yt 0:0c7f2ea60a75 77 if (debug_mode) printf("HTTP 403 Error \n");
yueee_yt 0:0c7f2ea60a75 78 return -1;
yueee_yt 0:0c7f2ea60a75 79 }
yueee_yt 0:0c7f2ea60a75 80 if (r==HTTP_ERROR) {
yueee_yt 0:0c7f2ea60a75 81 if (debug_mode)printf("HTTP xxx error \n");
yueee_yt 0:0c7f2ea60a75 82 return -1;
yueee_yt 0:0c7f2ea60a75 83 }
yueee_yt 0:0c7f2ea60a75 84 if (r==HTTP_TIMEOUT) {
yueee_yt 0:0c7f2ea60a75 85 if (debug_mode)printf("Connection timeout\n");
yueee_yt 0:0c7f2ea60a75 86 return -1;
yueee_yt 0:0c7f2ea60a75 87 }
yueee_yt 0:0c7f2ea60a75 88 if (r==HTTP_CONN) {
yueee_yt 0:0c7f2ea60a75 89 if (debug_mode)printf("Connection error\n");
yueee_yt 0:0c7f2ea60a75 90 return -1;
yueee_yt 0:0c7f2ea60a75 91 }
yueee_yt 0:0c7f2ea60a75 92
yueee_yt 0:0c7f2ea60a75 93 return 0;
yueee_yt 0:0c7f2ea60a75 94 }