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 // IEEE1888 / FIAP Uploader Library for Arduino
yueee_yt 0:0c7f2ea60a75 2 //
yueee_yt 0:0c7f2ea60a75 3 // 2011/09/19 ver.1 H.Inoue & H.Ochiai
yueee_yt 0:0c7f2ea60a75 4 // 2011/12/31 Ver.1 for mbed Y.Tauchi
yueee_yt 0:0c7f2ea60a75 5
yueee_yt 0:0c7f2ea60a75 6 // --------- FIAP.h ---------
yueee_yt 0:0c7f2ea60a75 7 #ifndef MBED_FIAP_H
yueee_yt 0:0c7f2ea60a75 8 #define MBED_FIAP_H
yueee_yt 0:0c7f2ea60a75 9
yueee_yt 0:0c7f2ea60a75 10 #include "mbed.h"
yueee_yt 0:0c7f2ea60a75 11 #include "HTTPClient.h"
yueee_yt 0:0c7f2ea60a75 12
yueee_yt 0:0c7f2ea60a75 13 // return code of post method
yueee_yt 0:0c7f2ea60a75 14 #define FIAP_UPLOAD_OK 0 // Succeeded
yueee_yt 0:0c7f2ea60a75 15 #define FIAP_UPLOAD_CONNFAIL 1 // Connection faild (Socket I/O error)
yueee_yt 0:0c7f2ea60a75 16 #define FIAP_UPLOAD_DNSERR 2 // DNS error
yueee_yt 0:0c7f2ea60a75 17 #define FIAP_UPLOAD_HTTPERR 3 // HTTP Server error (The response was not "200 OK")
yueee_yt 0:0c7f2ea60a75 18 #define FIAP_UPLOAD_FIAPERR 4 // FIAP Server error
yueee_yt 0:0c7f2ea60a75 19
yueee_yt 0:0c7f2ea60a75 20 // point element
yueee_yt 0:0c7f2ea60a75 21
yueee_yt 0:0c7f2ea60a75 22 /** fiap_element
yueee_yt 0:0c7f2ea60a75 23 *
yueee_yt 0:0c7f2ea60a75 24 *@param cid Point ID
yueee_yt 0:0c7f2ea60a75 25 *@param value Data
yueee_yt 0:0c7f2ea60a75 26 *@param t DateTime
yueee_yt 0:0c7f2ea60a75 27 *@param timezone Timezone ie JST="+09:00"
yueee_yt 0:0c7f2ea60a75 28 */
yueee_yt 0:0c7f2ea60a75 29 struct fiap_element {
yueee_yt 0:0c7f2ea60a75 30 const char* cid; // Set PointID
yueee_yt 0:0c7f2ea60a75 31 string value; // Set Value
yueee_yt 0:0c7f2ea60a75 32 struct tm *t; // Set DateTime
yueee_yt 0:0c7f2ea60a75 33 char* timezone; // Set Timezon JST="+09:00"
yueee_yt 0:0c7f2ea60a75 34 };
yueee_yt 0:0c7f2ea60a75 35
yueee_yt 0:0c7f2ea60a75 36 /** FIAP Class
yueee_yt 0:0c7f2ea60a75 37 *
yueee_yt 0:0c7f2ea60a75 38 * for mbed
yueee_yt 0:0c7f2ea60a75 39 *
yueee_yt 0:0c7f2ea60a75 40 *Example:
yueee_yt 0:0c7f2ea60a75 41 *@code
yueee_yt 0:0c7f2ea60a75 42 * #include "mbed.h"
yueee_yt 0:0c7f2ea60a75 43 * #include "EthernetNetIf.h"
yueee_yt 0:0c7f2ea60a75 44 * #include "NTPClient.h"
yueee_yt 0:0c7f2ea60a75 45 * #include "fiap.h"
yueee_yt 0:0c7f2ea60a75 46 *
yueee_yt 0:0c7f2ea60a75 47 * #define ntp_server "ntp server address"
yueee_yt 0:0c7f2ea60a75 48 *
yueee_yt 0:0c7f2ea60a75 49 * DigitalOut led1(LED1);
yueee_yt 0:0c7f2ea60a75 50 * DigitalOut led2(LED2);
yueee_yt 0:0c7f2ea60a75 51 * DigitalOut led3(LED3);
yueee_yt 0:0c7f2ea60a75 52 * DigitalOut led4(LED4);
yueee_yt 0:0c7f2ea60a75 53 *
yueee_yt 0:0c7f2ea60a75 54 * EthernetNetIf eth;
yueee_yt 0:0c7f2ea60a75 55 * NTPClient ntp;
yueee_yt 0:0c7f2ea60a75 56 * FIAP ieee1888("http://192.168.1.5/axis2/services/FIAPStorage","http://test.fiap.org/mbed_hello/");
yueee_yt 0:0c7f2ea60a75 57 *
yueee_yt 0:0c7f2ea60a75 58 * char timezone[] = "+09:00"; // JST
yueee_yt 0:0c7f2ea60a75 59 *
yueee_yt 0:0c7f2ea60a75 60 * struct fiap_element element[]={
yueee_yt 0:0c7f2ea60a75 61 * {"P1",NULL,NULL,timezone},
yueee_yt 0:0c7f2ea60a75 62 * {"P2",NULL,NULL,timezone},
yueee_yt 0:0c7f2ea60a75 63 * };
yueee_yt 0:0c7f2ea60a75 64 *
yueee_yt 0:0c7f2ea60a75 65 * int main() {
yueee_yt 0:0c7f2ea60a75 66 * led1=led2=led3=led4=0;
yueee_yt 0:0c7f2ea60a75 67 * ieee1888.debug_mode=true;
yueee_yt 0:0c7f2ea60a75 68 * //EthernetNetIf initialize
yueee_yt 0:0c7f2ea60a75 69 * EthernetErr ethErr = eth.setup();
yueee_yt 0:0c7f2ea60a75 70 * if (ethErr) {
yueee_yt 0:0c7f2ea60a75 71 * // lcd.locate(0,1);
yueee_yt 0:0c7f2ea60a75 72 * // lcd.printf("Error %d in setup.\n", ethErr);
yueee_yt 0:0c7f2ea60a75 73 * return -1;
yueee_yt 0:0c7f2ea60a75 74 * }
yueee_yt 0:0c7f2ea60a75 75 * led1=1;
yueee_yt 0:0c7f2ea60a75 76 * //NTPClient initia,lize
yueee_yt 0:0c7f2ea60a75 77 * Host server(IpAddr(), 123, ntp_server);
yueee_yt 0:0c7f2ea60a75 78 * NTPResult Ntpr=ntp.setTime(server);
yueee_yt 0:0c7f2ea60a75 79 * //UTC-->JST +9Hour(32400Sec)
yueee_yt 0:0c7f2ea60a75 80 * time_t ctTime;
yueee_yt 0:0c7f2ea60a75 81 * ctTime = time(NULL);
yueee_yt 0:0c7f2ea60a75 82 * ctTime+=32400;
yueee_yt 0:0c7f2ea60a75 83 * set_time(ctTime);
yueee_yt 0:0c7f2ea60a75 84 * led2=1;
yueee_yt 0:0c7f2ea60a75 85 *
yueee_yt 0:0c7f2ea60a75 86 * //post
yueee_yt 0:0c7f2ea60a75 87 * int i,j;
yueee_yt 0:0c7f2ea60a75 88 * for (j=0; j<10; j++) {
yueee_yt 0:0c7f2ea60a75 89 * //data initialize
yueee_yt 0:0c7f2ea60a75 90 * time_t seconds = time(NULL);
yueee_yt 0:0c7f2ea60a75 91 * for (i=0; i<2; i++) {
yueee_yt 0:0c7f2ea60a75 92 * char data[5];
yueee_yt 0:0c7f2ea60a75 93 * int s=j*pow((double)10,i);
yueee_yt 0:0c7f2ea60a75 94 * sprintf(data,"%03d",s);
yueee_yt 0:0c7f2ea60a75 95 * element[i].value=data;
yueee_yt 0:0c7f2ea60a75 96 * element[i].t=localtime(&seconds);
yueee_yt 0:0c7f2ea60a75 97 * }
yueee_yt 0:0c7f2ea60a75 98 * //do post
yueee_yt 0:0c7f2ea60a75 99 * int ret=ieee1888.post(element,2);
yueee_yt 0:0c7f2ea60a75 100 * if(ret!=0){
yueee_yt 0:0c7f2ea60a75 101 * while (1) {
yueee_yt 0:0c7f2ea60a75 102 * led3=!led3;
yueee_yt 0:0c7f2ea60a75 103 * wait(0.5);
yueee_yt 0:0c7f2ea60a75 104 * }
yueee_yt 0:0c7f2ea60a75 105 * return 0;
yueee_yt 0:0c7f2ea60a75 106 * }
yueee_yt 0:0c7f2ea60a75 107 * wait(1);
yueee_yt 0:0c7f2ea60a75 108 * }
yueee_yt 0:0c7f2ea60a75 109 * //finish
yueee_yt 0:0c7f2ea60a75 110 * while (1) {
yueee_yt 0:0c7f2ea60a75 111 * led4=!led4;
yueee_yt 0:0c7f2ea60a75 112 * wait(0.5);
yueee_yt 0:0c7f2ea60a75 113 * }
yueee_yt 0:0c7f2ea60a75 114 * }
yueee_yt 0:0c7f2ea60a75 115 *@endcode
yueee_yt 0:0c7f2ea60a75 116 */
yueee_yt 0:0c7f2ea60a75 117 class FIAP {
yueee_yt 0:0c7f2ea60a75 118 public:
yueee_yt 0:0c7f2ea60a75 119 /** Create fiap object
yueee_yt 0:0c7f2ea60a75 120 * @param Storage FIAP Storage Addrees (ie. "http://fiap.org/axis2/services/FIAPStorage")
yueee_yt 0:0c7f2ea60a75 121 * @param PointSetId Point Set ID(ie. http://test.fiap.jp/bldg_1/3F/)
yueee_yt 0:0c7f2ea60a75 122 */
yueee_yt 0:0c7f2ea60a75 123 FIAP(string Storage,string PointSetId);
yueee_yt 0:0c7f2ea60a75 124
yueee_yt 0:0c7f2ea60a75 125 /** post
yueee_yt 0:0c7f2ea60a75 126 * @param v data vaule
yueee_yt 0:0c7f2ea60a75 127 * @param esize number of data
yueee_yt 0:0c7f2ea60a75 128 */
yueee_yt 0:0c7f2ea60a75 129 int post(struct fiap_element* v, unsigned int esize);
yueee_yt 0:0c7f2ea60a75 130
yueee_yt 0:0c7f2ea60a75 131 /** debug_mode
yueee_yt 0:0c7f2ea60a75 132 * Output XML and Error
yueee_yt 0:0c7f2ea60a75 133 */
yueee_yt 0:0c7f2ea60a75 134 bool debug_mode;
yueee_yt 0:0c7f2ea60a75 135
yueee_yt 0:0c7f2ea60a75 136 private:
yueee_yt 0:0c7f2ea60a75 137 string _fiap_storage;
yueee_yt 0:0c7f2ea60a75 138 string _fiap_id_prefix;
yueee_yt 0:0c7f2ea60a75 139 string _soap_header;
yueee_yt 0:0c7f2ea60a75 140 string _soap_footer;
yueee_yt 0:0c7f2ea60a75 141 };
yueee_yt 0:0c7f2ea60a75 142
yueee_yt 0:0c7f2ea60a75 143 #endif