FIAP (IEEE1888) library
Dependents: Fetch_IEEE1888_Storage IEEE1888_MULTI_SENSOR_GW
Fork of FiapV2 by
fiap.cpp@11:db42339d6cce, 2013-02-22 (annotated)
- Committer:
- strysd
- Date:
- Fri Feb 22 05:00:50 2013 +0000
- Revision:
- 11:db42339d6cce
- Parent:
- 10:b355957e01f4
- Child:
- 12:f4e59ab2bab0
refactoring xml generation and other functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:d34a9148b19e | 1 | #include "fiap.h" |
yueee_yt | 0:d34a9148b19e | 2 | #include "mbed.h" |
yueee_yt | 0:d34a9148b19e | 3 | #include "stdio.h" |
yueee_yt | 0:d34a9148b19e | 4 | #include "spdomparser.hpp" |
yueee_yt | 0:d34a9148b19e | 5 | #include "spxmlnode.hpp" |
yueee_yt | 0:d34a9148b19e | 6 | #include "spxmlhandle.hpp" |
yueee_yt | 0:d34a9148b19e | 7 | |
strysd | 11:db42339d6cce | 8 | void FIAP::xml_initialize(void) |
yueee_yt | 2:2ba00be13585 | 9 | { |
yueee_yt | 0:d34a9148b19e | 10 | strcpy(_soap_header,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
yueee_yt | 2:2ba00be13585 | 11 | strcat(_soap_header,"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"); |
strysd | 11:db42339d6cce | 12 | strcat(_soap_header,"<soapenv:Body><ns2:"); |
strysd | 11:db42339d6cce | 13 | strcpy(_soap_action,"http://soap.fiap.org/"); |
strysd | 11:db42339d6cce | 14 | |
strysd | 11:db42339d6cce | 15 | if (USE_FETCH_PROCEDURE) { |
strysd | 11:db42339d6cce | 16 | strcat(_soap_header,"queryRQ"); |
strysd | 11:db42339d6cce | 17 | strcat(_soap_action,"query"); |
strysd | 11:db42339d6cce | 18 | } else { |
strysd | 11:db42339d6cce | 19 | strcat(_soap_header,"dataRQ"); |
strysd | 11:db42339d6cce | 20 | strcat(_soap_action,"data"); |
strysd | 11:db42339d6cce | 21 | } |
strysd | 11:db42339d6cce | 22 | |
strysd | 11:db42339d6cce | 23 | strcat(_soap_header," xmlns:ns2=\"http://soap.fiap.org/\">"); |
yueee_yt | 2:2ba00be13585 | 24 | strcat(_soap_header,"<transport xmlns=\"http://gutp.jp/fiap/2009/11/\">"); |
strysd | 11:db42339d6cce | 25 | |
strysd | 11:db42339d6cce | 26 | if (USE_FETCH_PROCEDURE) { |
strysd | 11:db42339d6cce | 27 | strcat(_soap_header,"<header>"); |
strysd | 11:db42339d6cce | 28 | strcpy(_soap_footer,"</header>"); |
strysd | 11:db42339d6cce | 29 | } else { |
strysd | 11:db42339d6cce | 30 | strcat(_soap_header,"<body>"); |
strysd | 11:db42339d6cce | 31 | strcpy(_soap_footer,"</body>"); |
strysd | 11:db42339d6cce | 32 | } |
strysd | 11:db42339d6cce | 33 | |
strysd | 11:db42339d6cce | 34 | strcat(_soap_footer,"</transport></ns2:"); |
strysd | 11:db42339d6cce | 35 | |
strysd | 11:db42339d6cce | 36 | if (USE_FETCH_PROCEDURE) { |
strysd | 11:db42339d6cce | 37 | strcat(_soap_footer,"queryRQ>"); |
strysd | 11:db42339d6cce | 38 | } else { |
strysd | 11:db42339d6cce | 39 | strcat(_soap_footer,"dataRQ>"); |
strysd | 11:db42339d6cce | 40 | } |
strysd | 11:db42339d6cce | 41 | |
yueee_yt | 0:d34a9148b19e | 42 | strcat(_soap_footer,"</soapenv:Body>"); |
yueee_yt | 0:d34a9148b19e | 43 | strcat(_soap_footer,"</soapenv:Envelope>"); |
yueee_yt | 0:d34a9148b19e | 44 | strcat(_soap_footer,"\r\n\r\n"); |
yueee_yt | 0:d34a9148b19e | 45 | } |
strysd | 11:db42339d6cce | 46 | |
strysd | 11:db42339d6cce | 47 | void FIAP::generateUUID() |
yueee_yt | 2:2ba00be13585 | 48 | { |
strysd | 11:db42339d6cce | 49 | sprintf(_uuid,"%04x%04x-%04x-%04x-%04x-%04x%04x%04x",rand()%0x10000,rand()%0x10000,rand()%0x10000,rand()%1000|0x4000,rand()%0x1000|0x8000,rand()%0x10000,rand()%10000,(rand()+1)%0x10000); |
yueee_yt | 0:d34a9148b19e | 50 | } |
yueee_yt | 0:d34a9148b19e | 51 | |
strysd | 10:b355957e01f4 | 52 | char* FIAP::HTTPStatusText(HTTPResult r) |
strysd | 10:b355957e01f4 | 53 | { |
strysd | 10:b355957e01f4 | 54 | if (r==HTTP_OK) { |
strysd | 10:b355957e01f4 | 55 | return "Success \n"; |
strysd | 10:b355957e01f4 | 56 | } |
strysd | 10:b355957e01f4 | 57 | if (r==HTTP_PROCESSING) { |
strysd | 10:b355957e01f4 | 58 | return "Processing \n"; |
strysd | 10:b355957e01f4 | 59 | } |
strysd | 10:b355957e01f4 | 60 | if (r==HTTP_PARSE) { |
strysd | 10:b355957e01f4 | 61 | return "URI Parse error \n"; |
strysd | 10:b355957e01f4 | 62 | } |
strysd | 10:b355957e01f4 | 63 | if (r==HTTP_DNS) { |
strysd | 10:b355957e01f4 | 64 | return "Could not resolve name\n"; |
strysd | 10:b355957e01f4 | 65 | } |
strysd | 10:b355957e01f4 | 66 | if (r==HTTP_PRTCL) { |
strysd | 10:b355957e01f4 | 67 | return "Protocol error\n"; |
strysd | 10:b355957e01f4 | 68 | } |
strysd | 10:b355957e01f4 | 69 | if (r==HTTP_NOTFOUND) { |
strysd | 10:b355957e01f4 | 70 | return "HTTP 404 Error\n"; |
strysd | 10:b355957e01f4 | 71 | } |
strysd | 10:b355957e01f4 | 72 | if (r==HTTP_REFUSED) { |
strysd | 10:b355957e01f4 | 73 | return "HTTP 403 Error \n"; |
strysd | 10:b355957e01f4 | 74 | } |
strysd | 10:b355957e01f4 | 75 | if (r==HTTP_ERROR) { |
strysd | 10:b355957e01f4 | 76 | return "HTTP xxx error \n "; |
strysd | 10:b355957e01f4 | 77 | } |
strysd | 10:b355957e01f4 | 78 | if (r==HTTP_TIMEOUT) { |
strysd | 10:b355957e01f4 | 79 | return "Connection timeout\n"; |
strysd | 10:b355957e01f4 | 80 | } |
strysd | 10:b355957e01f4 | 81 | if (r==HTTP_CONN) { |
strysd | 10:b355957e01f4 | 82 | return "Connection error\n"; |
strysd | 10:b355957e01f4 | 83 | } |
strysd | 10:b355957e01f4 | 84 | if (r==HTTP_CLOSED) { |
strysd | 10:b355957e01f4 | 85 | return "Connection error\n"; |
strysd | 10:b355957e01f4 | 86 | } |
strysd | 10:b355957e01f4 | 87 | |
strysd | 10:b355957e01f4 | 88 | return "Unknown Network Error\n"; |
strysd | 10:b355957e01f4 | 89 | } |
strysd | 10:b355957e01f4 | 90 | |
strysd | 11:db42339d6cce | 91 | void FIAP::myprintf(char text[2000]) |
strysd | 11:db42339d6cce | 92 | { |
strysd | 11:db42339d6cce | 93 | if (debug_mode)printf(text); |
strysd | 11:db42339d6cce | 94 | } |
strysd | 11:db42339d6cce | 95 | |
strysd | 9:02ae92c06e52 | 96 | FIAP::FIAP() |
yueee_yt | 2:2ba00be13585 | 97 | { |
yueee_yt | 2:2ba00be13585 | 98 | debug_mode=false; |
strysd | 11:db42339d6cce | 99 | |
strysd | 11:db42339d6cce | 100 | xml_initialize(); |
strysd | 9:02ae92c06e52 | 101 | } |
strysd | 9:02ae92c06e52 | 102 | |
strysd | 9:02ae92c06e52 | 103 | void FIAP::setStorage(char Storage[]) |
strysd | 9:02ae92c06e52 | 104 | { |
yueee_yt | 2:2ba00be13585 | 105 | strcpy(_fiap_storage,Storage); |
strysd | 9:02ae92c06e52 | 106 | return; |
yueee_yt | 2:2ba00be13585 | 107 | } |
yueee_yt | 2:2ba00be13585 | 108 | |
strysd | 11:db42339d6cce | 109 | #if USE_FETCH_PROCEDURE |
strysd | 11:db42339d6cce | 110 | |
yueee_yt | 2:2ba00be13585 | 111 | int FIAP::fetch_last_data(struct fiap_element* v,unsigned int esize) |
yueee_yt | 2:2ba00be13585 | 112 | { |
yueee_yt | 0:d34a9148b19e | 113 | HTTPClient http; |
yueee_yt | 6:52e95ea60ec1 | 114 | int i,ii,ll,k1,k2; |
yueee_yt | 0:d34a9148b19e | 115 | strcpy( _soap_text, _soap_header); |
yueee_yt | 0:d34a9148b19e | 116 | strcat( _soap_text , "<query id=\""); |
strysd | 11:db42339d6cce | 117 | generateUUID(); |
strysd | 11:db42339d6cce | 118 | strcat( _soap_text , _uuid); |
yueee_yt | 0:d34a9148b19e | 119 | strcat( _soap_text , "\" type=\"storage\">"); |
strysd | 11:db42339d6cce | 120 | for (i=0; i < esize; i++) { |
yueee_yt | 0:d34a9148b19e | 121 | strcat(_soap_text , "<key id=\""); |
yueee_yt | 0:d34a9148b19e | 122 | strcat(_soap_text , v[i].cid); |
yueee_yt | 0:d34a9148b19e | 123 | strcat(_soap_text , "\" attrName=\"time\" select=\"maximum\"/>"); |
yueee_yt | 0:d34a9148b19e | 124 | } |
yueee_yt | 0:d34a9148b19e | 125 | strcat(_soap_text , "</query>"); |
yueee_yt | 0:d34a9148b19e | 126 | strcat(_soap_text , _soap_footer); |
yueee_yt | 0:d34a9148b19e | 127 | if (debug_mode) { |
yueee_yt | 0:d34a9148b19e | 128 | printf(_fiap_storage); |
yueee_yt | 0:d34a9148b19e | 129 | printf("\r\n"); |
yueee_yt | 0:d34a9148b19e | 130 | printf(_soap_text); |
yueee_yt | 0:d34a9148b19e | 131 | printf("<<< Request(end)\n"); |
yueee_yt | 0:d34a9148b19e | 132 | } |
yueee_yt | 2:2ba00be13585 | 133 | //HTTPText InData("text/html", 800); |
yueee_yt | 2:2ba00be13585 | 134 | //InData.set(_soap_text); |
yueee_yt | 2:2ba00be13585 | 135 | HTTPText InData(_soap_text); |
yueee_yt | 3:7b144e1a52db | 136 | char rstr[800]; |
yueee_yt | 3:7b144e1a52db | 137 | HTTPText stream(rstr,800); |
yueee_yt | 2:2ba00be13585 | 138 | //stream.readNext((byte*)outBuffer,1500); |
strysd | 11:db42339d6cce | 139 | myprintf("post.start \n\r"); |
strysd | 11:db42339d6cce | 140 | HTTPResult r = http.postXML(_fiap_storage,_soap_action,InData,&stream); |
strysd | 11:db42339d6cce | 141 | myprintf("post.end \n\r"); |
yueee_yt | 6:52e95ea60ec1 | 142 | if (debug_mode) { |
yueee_yt | 6:52e95ea60ec1 | 143 | printf("****\n\r"); |
yueee_yt | 6:52e95ea60ec1 | 144 | printf(rstr); |
yueee_yt | 6:52e95ea60ec1 | 145 | printf("\n\r****\n\r"); |
yueee_yt | 6:52e95ea60ec1 | 146 | } |
strysd | 10:b355957e01f4 | 147 | |
strysd | 11:db42339d6cce | 148 | myprintf(HTTPStatusText(r)); |
strysd | 10:b355957e01f4 | 149 | if (r != HTTP_OK) { |
yueee_yt | 6:52e95ea60ec1 | 150 | return -1; |
yueee_yt | 0:d34a9148b19e | 151 | } |
strysd | 10:b355957e01f4 | 152 | |
yueee_yt | 0:d34a9148b19e | 153 | SP_XmlNodeList * points; |
yueee_yt | 6:52e95ea60ec1 | 154 | SP_XmlNodeList * trans_point; |
yueee_yt | 3:7b144e1a52db | 155 | if (strlen(rstr)>0) { |
strysd | 11:db42339d6cce | 156 | myprintf("\n\r data Get Ok\n\r"); |
yueee_yt | 0:d34a9148b19e | 157 | SP_XmlDomParser parser; |
yueee_yt | 3:7b144e1a52db | 158 | parser.append(rstr,strlen(rstr)); |
yueee_yt | 0:d34a9148b19e | 159 | //stream.readNext((byte*)outBuffer,4096); |
yueee_yt | 0:d34a9148b19e | 160 | SP_XmlHandle rootHandle(parser.getDocument()->getRootElement()); |
yueee_yt | 0:d34a9148b19e | 161 | SP_XmlHandle transport = rootHandle.getChild(0).getChild(0).getChild(0); |
yueee_yt | 0:d34a9148b19e | 162 | SP_XmlElementNode * fiapError = transport.getChild("header").getChild("error").toElement(); |
yueee_yt | 2:2ba00be13585 | 163 | int yy,mo,dd,hh,mm,ss; |
yueee_yt | 2:2ba00be13585 | 164 | char str[50]; |
strysd | 11:db42339d6cce | 165 | if(debug_mode)printf ("%s \n",transport.toElement()->getName()); |
yueee_yt | 2:2ba00be13585 | 166 | if (fiapError==NULL) { |
yueee_yt | 6:52e95ea60ec1 | 167 | SP_XmlElementNode * trans_element = transport.toElement(); |
yueee_yt | 6:52e95ea60ec1 | 168 | trans_point=(SP_XmlNodeList *)trans_element->getChildren() ; |
yueee_yt | 6:52e95ea60ec1 | 169 | k1=trans_point->getLength(); |
yueee_yt | 6:52e95ea60ec1 | 170 | if(debug_mode)printf("Trans Child has Element of No %d \n\r",k1); |
yueee_yt | 6:52e95ea60ec1 | 171 | SP_XmlElementNode * values; |
yueee_yt | 6:52e95ea60ec1 | 172 | for(k2=0; k2<k1; k2++) { |
yueee_yt | 6:52e95ea60ec1 | 173 | values =transport.getChild(k2).toElement(); |
strysd | 11:db42339d6cce | 174 | if(debug_mode){ |
strysd | 11:db42339d6cce | 175 | printf(values->getName()); |
strysd | 11:db42339d6cce | 176 | printf("\n\r"); |
strysd | 11:db42339d6cce | 177 | } |
yueee_yt | 6:52e95ea60ec1 | 178 | if(strstr((values->getName()),"body") !=NULL) { |
strysd | 11:db42339d6cce | 179 | myprintf("find body \n\r"); |
yueee_yt | 6:52e95ea60ec1 | 180 | points=(SP_XmlNodeList *)values->getChildren() ; |
yueee_yt | 6:52e95ea60ec1 | 181 | int j=points->getLength(); |
strysd | 11:db42339d6cce | 182 | if(debug_mode)printf("GetValues of No %d \n\r",j); |
yueee_yt | 6:52e95ea60ec1 | 183 | SP_XmlElementNode *data_point_node,*data_value_node; |
yueee_yt | 6:52e95ea60ec1 | 184 | SP_XmlCDataNode *data_value_cnode; |
yueee_yt | 6:52e95ea60ec1 | 185 | for (i=0; i<j; i++) { |
yueee_yt | 6:52e95ea60ec1 | 186 | SP_XmlHandle data_handle(points->get(i));//Point |
yueee_yt | 6:52e95ea60ec1 | 187 | data_point_node=data_handle.toElement(); |
yueee_yt | 6:52e95ea60ec1 | 188 | //data_value_node=data_handle.getChild("value").toElement(); |
yueee_yt | 6:52e95ea60ec1 | 189 | //data_value_cnode=data_handle.getChild("value").getChild(0).toCData(); |
yueee_yt | 6:52e95ea60ec1 | 190 | data_value_node=data_handle.getChild(0).toElement(); |
yueee_yt | 6:52e95ea60ec1 | 191 | data_value_cnode=data_handle.getChild(0).getChild(0).toCData(); |
strysd | 11:db42339d6cce | 192 | if(debug_mode){ |
strysd | 11:db42339d6cce | 193 | printf("PointID=%s \r\n",data_point_node->getAttrValue("id")); |
strysd | 11:db42339d6cce | 194 | printf("date=%s \r\n",data_value_node->getAttrValue("time")); |
strysd | 11:db42339d6cce | 195 | printf("data=%s \r\n",data_value_cnode->getText()); |
strysd | 11:db42339d6cce | 196 | } |
yueee_yt | 6:52e95ea60ec1 | 197 | for (ii=0; ii<esize; ii++) { |
yueee_yt | 6:52e95ea60ec1 | 198 | if (strcmp(v[ii].cid,data_point_node->getAttrValue("id"))==0) { |
yueee_yt | 6:52e95ea60ec1 | 199 | sprintf(str,"%s",data_value_node->getAttrValue("time")); |
yueee_yt | 6:52e95ea60ec1 | 200 | ll=sscanf(str,"%d-%d-%dT%d:%d:%d.",&yy,&mo,&dd,&hh,&mm,&ss); |
strysd | 11:db42339d6cce | 201 | if(debug_mode)printf("date convert no %d (%d/%d/%d %d:%d:%d) \r\n",ll,yy,mo,dd,hh,mm,ss); |
yueee_yt | 6:52e95ea60ec1 | 202 | v[ii].year=yy; |
yueee_yt | 6:52e95ea60ec1 | 203 | v[ii].month=mo; |
yueee_yt | 6:52e95ea60ec1 | 204 | v[ii].day=dd; |
yueee_yt | 6:52e95ea60ec1 | 205 | v[ii].hour=hh; |
yueee_yt | 6:52e95ea60ec1 | 206 | v[ii].minute=mm; |
yueee_yt | 6:52e95ea60ec1 | 207 | v[ii].second=ss; |
yueee_yt | 6:52e95ea60ec1 | 208 | sprintf(v[ii].value,"%s",data_value_cnode->getText()); |
yueee_yt | 6:52e95ea60ec1 | 209 | } |
yueee_yt | 6:52e95ea60ec1 | 210 | } |
yueee_yt | 2:2ba00be13585 | 211 | } |
yueee_yt | 6:52e95ea60ec1 | 212 | |
yueee_yt | 2:2ba00be13585 | 213 | } |
yueee_yt | 6:52e95ea60ec1 | 214 | |
yueee_yt | 6:52e95ea60ec1 | 215 | |
yueee_yt | 2:2ba00be13585 | 216 | } |
yueee_yt | 6:52e95ea60ec1 | 217 | |
yueee_yt | 2:2ba00be13585 | 218 | } else { |
strysd | 11:db42339d6cce | 219 | myprintf("ERROR\n\r"); |
yueee_yt | 2:2ba00be13585 | 220 | } |
yueee_yt | 2:2ba00be13585 | 221 | } else { |
strysd | 11:db42339d6cce | 222 | myprintf("error\n\r"); |
yueee_yt | 2:2ba00be13585 | 223 | } |
yueee_yt | 2:2ba00be13585 | 224 | return 0; |
yueee_yt | 2:2ba00be13585 | 225 | } |
yueee_yt | 0:d34a9148b19e | 226 | |
yueee_yt | 2:2ba00be13585 | 227 | int FIAP::fetch_last_data(struct fiap_element *v) |
yueee_yt | 2:2ba00be13585 | 228 | { |
yueee_yt | 2:2ba00be13585 | 229 | HTTPClient http; |
yueee_yt | 2:2ba00be13585 | 230 | int ll; |
yueee_yt | 3:7b144e1a52db | 231 | char rstr[800]; |
yueee_yt | 2:2ba00be13585 | 232 | strcpy(_soap_text, _soap_header); |
yueee_yt | 2:2ba00be13585 | 233 | strcat(_soap_text , "<query id=\""); |
strysd | 11:db42339d6cce | 234 | generateUUID(); |
strysd | 11:db42339d6cce | 235 | strcat(_soap_text , _uuid); |
yueee_yt | 2:2ba00be13585 | 236 | strcat(_soap_text , "\" type=\"storage\">"); |
yueee_yt | 2:2ba00be13585 | 237 | strcat(_soap_text , "<key id=\""); |
yueee_yt | 2:2ba00be13585 | 238 | strcat(_soap_text , v->cid); |
yueee_yt | 2:2ba00be13585 | 239 | strcat(_soap_text , "\" attrName=\"time\" select=\"maximum\"/>"); |
yueee_yt | 2:2ba00be13585 | 240 | strcat(_soap_text , "</query>"); |
yueee_yt | 2:2ba00be13585 | 241 | strcat(_soap_text , _soap_footer); |
yueee_yt | 2:2ba00be13585 | 242 | if (debug_mode) { |
yueee_yt | 2:2ba00be13585 | 243 | printf("\r\n"); |
yueee_yt | 2:2ba00be13585 | 244 | printf(_fiap_storage); |
yueee_yt | 2:2ba00be13585 | 245 | printf("\r\n"); |
yueee_yt | 2:2ba00be13585 | 246 | printf(_soap_text); |
yueee_yt | 2:2ba00be13585 | 247 | printf("<<< Request(end)\n"); |
yueee_yt | 2:2ba00be13585 | 248 | } |
yueee_yt | 2:2ba00be13585 | 249 | // http.setRequestHeader("Content-Type","text/xml; charset=UTF-8"); |
yueee_yt | 2:2ba00be13585 | 250 | // http.setRequestHeader("SOAPAction","\"http://soap.fiap.org/query\""); |
yueee_yt | 2:2ba00be13585 | 251 | HTTPText InData(_soap_text); |
yueee_yt | 3:7b144e1a52db | 252 | HTTPText stream(rstr,800); |
yueee_yt | 2:2ba00be13585 | 253 | // stream.readNext((byte*)outBuffer,strlen(outBuffer)); |
strysd | 11:db42339d6cce | 254 | myprintf("post.start \n\r"); |
strysd | 11:db42339d6cce | 255 | HTTPResult r = http.postXML(_fiap_storage,_soap_action,InData,&stream); |
strysd | 11:db42339d6cce | 256 | myprintf("post.end \n\r"); |
strysd | 10:b355957e01f4 | 257 | |
strysd | 11:db42339d6cce | 258 | myprintf(HTTPStatusText(r)); |
strysd | 10:b355957e01f4 | 259 | if (r != HTTP_OK) { |
yueee_yt | 6:52e95ea60ec1 | 260 | return -1; |
yueee_yt | 2:2ba00be13585 | 261 | } |
strysd | 10:b355957e01f4 | 262 | |
yueee_yt | 2:2ba00be13585 | 263 | SP_XmlNodeList * points; |
yueee_yt | 3:7b144e1a52db | 264 | if (strlen(rstr)>0) { |
strysd | 11:db42339d6cce | 265 | myprintf("\n\r data Get Ok\n\r"); |
yueee_yt | 6:52e95ea60ec1 | 266 | |
yueee_yt | 2:2ba00be13585 | 267 | SP_XmlDomParser parser; |
yueee_yt | 6:52e95ea60ec1 | 268 | |
strysd | 11:db42339d6cce | 269 | // myprintf("stream readlen = %d \n\r",stream.readLen()); |
yueee_yt | 3:7b144e1a52db | 270 | // outBuffer[stream.readLen()]=0; |
strysd | 11:db42339d6cce | 271 | myprintf("check0\n\r"); |
yueee_yt | 3:7b144e1a52db | 272 | parser.append(rstr,strlen(rstr)); |
strysd | 11:db42339d6cce | 273 | myprintf("check1\n\r"); |
yueee_yt | 2:2ba00be13585 | 274 | SP_XmlHandle rootHandle(parser.getDocument()->getRootElement()); |
yueee_yt | 2:2ba00be13585 | 275 | SP_XmlHandle transport = rootHandle.getChild(0).getChild(0).getChild(0); |
yueee_yt | 2:2ba00be13585 | 276 | SP_XmlElementNode * fiapError = transport.getChild("header").getChild("error").toElement(); |
yueee_yt | 2:2ba00be13585 | 277 | int yy,mo,dd,hh,mm,ss; |
yueee_yt | 0:d34a9148b19e | 278 | char str[50]; |
strysd | 11:db42339d6cce | 279 | if(debug_mode)printf ("%s \n\r",transport.toElement()->getName()); |
yueee_yt | 0:d34a9148b19e | 280 | if (fiapError==NULL) { |
yueee_yt | 0:d34a9148b19e | 281 | SP_XmlElementNode * values =transport.getChild("body").toElement(); |
yueee_yt | 0:d34a9148b19e | 282 | points=(SP_XmlNodeList *)values->getChildren() ; |
yueee_yt | 0:d34a9148b19e | 283 | // points=values->getChildren(); |
yueee_yt | 0:d34a9148b19e | 284 | int j=points->getLength(); |
strysd | 11:db42339d6cce | 285 | if(debug_mode)printf("GetValues of No %d \n\r",j); |
yueee_yt | 0:d34a9148b19e | 286 | SP_XmlElementNode *data_point_node,*data_value_node; |
yueee_yt | 0:d34a9148b19e | 287 | SP_XmlCDataNode *data_value_cnode; |
yueee_yt | 0:d34a9148b19e | 288 | SP_XmlHandle data_handle(points->get(0));//Point |
yueee_yt | 0:d34a9148b19e | 289 | data_point_node=data_handle.toElement(); |
yueee_yt | 0:d34a9148b19e | 290 | data_value_node=data_handle.getChild("value").toElement(); |
yueee_yt | 0:d34a9148b19e | 291 | data_value_cnode=data_handle.getChild("value").getChild(0).toCData(); |
strysd | 11:db42339d6cce | 292 | if(debug_mode){ |
strysd | 11:db42339d6cce | 293 | printf("PointID=%s \r\n",data_point_node->getAttrValue("id")); |
strysd | 11:db42339d6cce | 294 | printf("date=%s \r\n",data_value_node->getAttrValue("time")); |
strysd | 11:db42339d6cce | 295 | printf("data=%s \r\n",data_value_cnode->getText()); |
strysd | 11:db42339d6cce | 296 | } |
yueee_yt | 0:d34a9148b19e | 297 | sprintf(str,"%s",data_value_node->getAttrValue("time")); |
yueee_yt | 0:d34a9148b19e | 298 | ll=sscanf(str,"%d-%d-%dT%d:%d:%d.",&yy,&mo,&dd,&hh,&mm,&ss); |
strysd | 11:db42339d6cce | 299 | if(debug_mode)printf("date convert no %d (%d/%d/%d %d:%d:%d) \r\n",ll,yy,mo,dd,hh,mm,ss); |
yueee_yt | 0:d34a9148b19e | 300 | v->year=yy; |
yueee_yt | 0:d34a9148b19e | 301 | v->month=mo; |
yueee_yt | 0:d34a9148b19e | 302 | v->day=dd; |
yueee_yt | 0:d34a9148b19e | 303 | v->hour=hh; |
yueee_yt | 0:d34a9148b19e | 304 | v->minute=mm; |
yueee_yt | 0:d34a9148b19e | 305 | v->second=ss; |
yueee_yt | 0:d34a9148b19e | 306 | sprintf(v->value,"%s", data_value_cnode->getText()); |
yueee_yt | 0:d34a9148b19e | 307 | } else { |
strysd | 11:db42339d6cce | 308 | myprintf("ERROR\n\r"); |
yueee_yt | 0:d34a9148b19e | 309 | } |
yueee_yt | 0:d34a9148b19e | 310 | } else { |
strysd | 11:db42339d6cce | 311 | myprintf("error\n\r"); |
yueee_yt | 0:d34a9148b19e | 312 | } |
yueee_yt | 0:d34a9148b19e | 313 | return 0; |
yueee_yt | 0:d34a9148b19e | 314 | } |
yueee_yt | 0:d34a9148b19e | 315 | |
strysd | 11:db42339d6cce | 316 | #endif //USE_FETCH_PROCEDURE |
yueee_yt | 2:2ba00be13585 | 317 | |
yueee_yt | 2:2ba00be13585 | 318 | int FIAP::post(struct fiap_element* v, unsigned int esize) |
yueee_yt | 2:2ba00be13585 | 319 | { |
yueee_yt | 0:d34a9148b19e | 320 | HTTPClient http; |
yueee_yt | 0:d34a9148b19e | 321 | int i; |
yueee_yt | 7:cc924e783dff | 322 | char rstr[1200]; |
yueee_yt | 0:d34a9148b19e | 323 | char requestBuffer[50]; |
yueee_yt | 2:2ba00be13585 | 324 | strcpy(_soap_text,_soap_header); |
strysd | 11:db42339d6cce | 325 | for (i=0; i < esize; i++) { |
yueee_yt | 0:d34a9148b19e | 326 | sprintf(requestBuffer,"%04d-%02d-%02dT%02d:%02d:%02d.0000000",v[i].year,v[i].month,v[i].day,v[i].hour,v[i].minute,v[i].second); |
yueee_yt | 0:d34a9148b19e | 327 | strcat(_soap_text , "<point id=\""); |
strysd | 11:db42339d6cce | 328 | //!!strcat(_soap_text , _fiap_id_prefix); |
yueee_yt | 2:2ba00be13585 | 329 | strcat(_soap_text , v[i].cid); |
strysd | 11:db42339d6cce | 330 | strcat(_soap_text , "\">"); |
yueee_yt | 2:2ba00be13585 | 331 | strcat(_soap_text , "<value time=\""); |
yueee_yt | 2:2ba00be13585 | 332 | strcat(_soap_text , requestBuffer); |
yueee_yt | 2:2ba00be13585 | 333 | strcat(_soap_text , v[i].timezone); |
yueee_yt | 2:2ba00be13585 | 334 | strcat(_soap_text , "\">"); |
yueee_yt | 2:2ba00be13585 | 335 | strcat(_soap_text , v[i].value); |
yueee_yt | 2:2ba00be13585 | 336 | strcat(_soap_text , "</value>"); |
yueee_yt | 2:2ba00be13585 | 337 | strcat(_soap_text , "</point>"); |
yueee_yt | 0:d34a9148b19e | 338 | } |
yueee_yt | 2:2ba00be13585 | 339 | strcat(_soap_text , _soap_footer); |
strysd | 11:db42339d6cce | 340 | |
strysd | 11:db42339d6cce | 341 | if(debug_mode){ |
yueee_yt | 0:d34a9148b19e | 342 | printf(_soap_text); |
yueee_yt | 0:d34a9148b19e | 343 | printf("<<< Request(end)\n"); |
yueee_yt | 0:d34a9148b19e | 344 | } |
yueee_yt | 2:2ba00be13585 | 345 | // http.setRequestHeader("Content-Type","text/xml; charset=UTF-8"); |
yueee_yt | 2:2ba00be13585 | 346 | // http.setRequestHeader("SOAPAction","\"http://soap.fiap.org/data\""); |
yueee_yt | 0:d34a9148b19e | 347 | // InData=new HTTPText(); |
yueee_yt | 2:2ba00be13585 | 348 | HTTPText InData(_soap_text); |
yueee_yt | 7:cc924e783dff | 349 | HTTPText OutData(rstr,1200); |
strysd | 11:db42339d6cce | 350 | HTTPResult r = http.postXML(_fiap_storage,_soap_action,InData,&OutData); |
strysd | 10:b355957e01f4 | 351 | |
strysd | 11:db42339d6cce | 352 | myprintf(HTTPStatusText(r)); |
strysd | 10:b355957e01f4 | 353 | if (r != HTTP_OK) { |
yueee_yt | 6:52e95ea60ec1 | 354 | return -1; |
yueee_yt | 0:d34a9148b19e | 355 | } |
strysd | 11:db42339d6cce | 356 | |
strysd | 11:db42339d6cce | 357 | if(debug_mode){ |
strysd | 10:b355957e01f4 | 358 | printf("****\n\r"); |
strysd | 10:b355957e01f4 | 359 | printf(rstr); |
strysd | 10:b355957e01f4 | 360 | printf("\n\r****\n\r"); |
strysd | 10:b355957e01f4 | 361 | } |
yueee_yt | 0:d34a9148b19e | 362 | return 0; |
strysd | 11:db42339d6cce | 363 | } |