fetch last data from IEEE1888 (FIAP) Storage.
Dependencies: EthernetInterface Fiap HTTPClientForFIAP mbed-rtos mbed spxml
Fork of temp_FIAP_fetch by
This program fetches last data from FIAP storage with IEEE1888 format.
Currently, You can confirm the data in console when FIAP_DEBUG_MODE is set to true.
Note: You should locate storage.txt into mbed memory at least before using this program. The storage.txt contains storage url, see example at IEEE1888_MULTI_SENSOR_GW/main.h .
And you should define FIAP_DEBUG_MODE and other constants in Fetch_IEEE1888_Storage/main.h file.
You can launch an AMI ( Amazon Machine Image ) on Amazon Web Service ( http://aws.amazon.com/ ) as the FIAP storage. The AMI is named as "IEEE1888 Storage", registered at Tokyo region.
If You need more information about the AMI, see http://d.hatena.ne.jp/satoruyoshida/20130210/1360508112 .
from here, in Japanese. このプログラムは IEEE1888 形式で FIAP Storage からデータを取得する例です。 現在、その値は FIAP_DEBUG_MODE を true に設定するとコンソールで確認できます。
このプログラムを使用する前に、少なくとも FIAP Storage の url を記載した sotrage.txt をメモリに格納しておく必要があります。 url の例は、 IEEE1888_MULTI_SENSOR_GW の main.h ファイルにあります。
FIAP_DEBUG_MODE およびその他の定数は Fetch_IEEE1888_Storage/main.h に存在します。
Amazon Web Service に用意した AMI を利用して FIAP Storage を起動することができます。IEEE1888 Storage という名前の公開 AMI です。
この AMI について詳しくは、http://d.hatena.ne.jp/satoruyoshida/20130210/1360508112 をご覧ください。
main.cpp@3:9a1a6ebcdaa7, 2013-03-02 (annotated)
- Committer:
- strysd
- Date:
- Sat Mar 02 03:18:19 2013 +0000
- Revision:
- 3:9a1a6ebcdaa7
- Parent:
- 1:d62d57f9a180
add USB and Clock control.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
strysd | 3:9a1a6ebcdaa7 | 1 | #include "main.h" |
yueee_yt | 0:27cf9683af17 | 2 | #include "mbed.h" |
yueee_yt | 0:27cf9683af17 | 3 | #include "EthernetInterface.h" |
yueee_yt | 0:27cf9683af17 | 4 | #include "fiap.h" |
yueee_yt | 0:27cf9683af17 | 5 | |
yueee_yt | 0:27cf9683af17 | 6 | EthernetInterface eth; |
strysd | 3:9a1a6ebcdaa7 | 7 | Serial pc(USBTX, USBRX); |
strysd | 3:9a1a6ebcdaa7 | 8 | FIAP fiap; |
yueee_yt | 0:27cf9683af17 | 9 | |
strysd | 3:9a1a6ebcdaa7 | 10 | DigitalOut led1(LED1);//error while connecting to FIAPStorage |
strysd | 3:9a1a6ebcdaa7 | 11 | DigitalOut led3(LED3);//LAN speed (1 = error) |
strysd | 3:9a1a6ebcdaa7 | 12 | DigitalOut led4(LED4);//LAN link (1 = error) |
strysd | 3:9a1a6ebcdaa7 | 13 | |
strysd | 3:9a1a6ebcdaa7 | 14 | DigitalIn lnk(P1_25);//LAN link |
strysd | 3:9a1a6ebcdaa7 | 15 | DigitalIn spd(P1_26);//LAN speed |
strysd | 3:9a1a6ebcdaa7 | 16 | DigitalOut speed(p29);//LAN speed for RJ45 (1 = OK) |
strysd | 3:9a1a6ebcdaa7 | 17 | DigitalOut link(p30); //LAN link for RJ45 (1 = OK) |
strysd | 3:9a1a6ebcdaa7 | 18 | |
strysd | 3:9a1a6ebcdaa7 | 19 | int exitTimer; |
strysd | 3:9a1a6ebcdaa7 | 20 | int i; |
strysd | 3:9a1a6ebcdaa7 | 21 | |
strysd | 3:9a1a6ebcdaa7 | 22 | #define STORAGE_URL_SIZE 100 |
strysd | 3:9a1a6ebcdaa7 | 23 | char storage_url[STORAGE_URL_SIZE]; |
strysd | 3:9a1a6ebcdaa7 | 24 | struct fiap_element element[] = { |
strysd | 3:9a1a6ebcdaa7 | 25 | {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, |
yueee_yt | 0:27cf9683af17 | 26 | }; |
yueee_yt | 0:27cf9683af17 | 27 | |
strysd | 3:9a1a6ebcdaa7 | 28 | //if you set LEDs for LAN indicator in real time. |
strysd | 3:9a1a6ebcdaa7 | 29 | /* |
strysd | 3:9a1a6ebcdaa7 | 30 | Ticker flipper; |
yueee_yt | 0:27cf9683af17 | 31 | |
strysd | 3:9a1a6ebcdaa7 | 32 | void myflip() { |
strysd | 3:9a1a6ebcdaa7 | 33 | led3 = spd; |
strysd | 3:9a1a6ebcdaa7 | 34 | led4 = lnk; |
strysd | 3:9a1a6ebcdaa7 | 35 | if(USE_RJ45_LAMP == true){ |
strysd | 3:9a1a6ebcdaa7 | 36 | speed = !spd; |
strysd | 3:9a1a6ebcdaa7 | 37 | link = !lnk; |
strysd | 3:9a1a6ebcdaa7 | 38 | } |
strysd | 3:9a1a6ebcdaa7 | 39 | } |
strysd | 3:9a1a6ebcdaa7 | 40 | */ |
strysd | 3:9a1a6ebcdaa7 | 41 | |
strysd | 3:9a1a6ebcdaa7 | 42 | int setFIAPStorage(void ) |
strysd | 3:9a1a6ebcdaa7 | 43 | { |
strysd | 3:9a1a6ebcdaa7 | 44 | LocalFileSystem local("local"); |
strysd | 3:9a1a6ebcdaa7 | 45 | FILE *fp; |
strysd | 3:9a1a6ebcdaa7 | 46 | fp = fopen("/local/storage.txt", "r"); |
strysd | 3:9a1a6ebcdaa7 | 47 | if(fp == NULL){ |
strysd | 3:9a1a6ebcdaa7 | 48 | return -1; |
strysd | 3:9a1a6ebcdaa7 | 49 | } |
strysd | 3:9a1a6ebcdaa7 | 50 | fgets(storage_url, STORAGE_URL_SIZE, fp); |
strysd | 3:9a1a6ebcdaa7 | 51 | fiap.setStorage(storage_url); |
strysd | 3:9a1a6ebcdaa7 | 52 | fiap.setMode(true); |
strysd | 3:9a1a6ebcdaa7 | 53 | fclose(fp); |
strysd | 3:9a1a6ebcdaa7 | 54 | |
strysd | 3:9a1a6ebcdaa7 | 55 | fiap.debug_mode=FIAP_DEBUG_MODE; |
strysd | 3:9a1a6ebcdaa7 | 56 | return 0; |
strysd | 3:9a1a6ebcdaa7 | 57 | } |
strysd | 3:9a1a6ebcdaa7 | 58 | |
strysd | 3:9a1a6ebcdaa7 | 59 | int fetchFIAP(void ) |
yueee_yt | 0:27cf9683af17 | 60 | { |
strysd | 3:9a1a6ebcdaa7 | 61 | element[0].cid = POINT_ID_0; |
strysd | 3:9a1a6ebcdaa7 | 62 | |
strysd | 3:9a1a6ebcdaa7 | 63 | if(fiap.fetch_last_data(element) != 0){ |
strysd | 3:9a1a6ebcdaa7 | 64 | return -1; |
strysd | 3:9a1a6ebcdaa7 | 65 | } |
strysd | 3:9a1a6ebcdaa7 | 66 | |
strysd | 3:9a1a6ebcdaa7 | 67 | i = 0;//now fixed value |
strysd | 3:9a1a6ebcdaa7 | 68 | printf("%s, %s, %2d-%2d-%2d %2d:%2d:%2d %s\n", |
strysd | 3:9a1a6ebcdaa7 | 69 | element[i].cid, element[i].value, |
strysd | 3:9a1a6ebcdaa7 | 70 | element[i].year, element[i].month, element[i].day, |
strysd | 3:9a1a6ebcdaa7 | 71 | element[i].hour, element[i].minute, element[i].second, |
strysd | 3:9a1a6ebcdaa7 | 72 | element[i].timezone); |
strysd | 3:9a1a6ebcdaa7 | 73 | |
strysd | 3:9a1a6ebcdaa7 | 74 | return 0; |
strysd | 3:9a1a6ebcdaa7 | 75 | } |
strysd | 3:9a1a6ebcdaa7 | 76 | |
strysd | 3:9a1a6ebcdaa7 | 77 | /* stop USB Interface */ |
strysd | 3:9a1a6ebcdaa7 | 78 | #define USR_POWERDOWN (0x104) |
strysd | 3:9a1a6ebcdaa7 | 79 | int semihost_powerdown() { |
strysd | 3:9a1a6ebcdaa7 | 80 | uint32_t arg; |
strysd | 3:9a1a6ebcdaa7 | 81 | return __semihost(USR_POWERDOWN, &arg); |
strysd | 3:9a1a6ebcdaa7 | 82 | } |
strysd | 3:9a1a6ebcdaa7 | 83 | |
strysd | 3:9a1a6ebcdaa7 | 84 | /** Frequency Control |
strysd | 3:9a1a6ebcdaa7 | 85 | * @see ClockControl/ClockControl.cpp by Michael Wei |
strysd | 3:9a1a6ebcdaa7 | 86 | */ |
strysd | 3:9a1a6ebcdaa7 | 87 | void setPLL0Frequency(unsigned char clkSrc, unsigned short M, unsigned char N) |
strysd | 3:9a1a6ebcdaa7 | 88 | { |
strysd | 3:9a1a6ebcdaa7 | 89 | LPC_SC->CLKSRCSEL = clkSrc; |
strysd | 3:9a1a6ebcdaa7 | 90 | LPC_SC->PLL0CFG = (((unsigned int)N-1) << 16) | M-1; |
strysd | 3:9a1a6ebcdaa7 | 91 | LPC_SC->PLL0CON = 0x01; |
strysd | 3:9a1a6ebcdaa7 | 92 | LPC_SC->PLL0FEED = 0xAA; |
strysd | 3:9a1a6ebcdaa7 | 93 | LPC_SC->PLL0FEED = 0x55; |
strysd | 3:9a1a6ebcdaa7 | 94 | while (!(LPC_SC->PLL0STAT & (1<<26))); |
strysd | 3:9a1a6ebcdaa7 | 95 | |
strysd | 3:9a1a6ebcdaa7 | 96 | LPC_SC->PLL0CON = 0x03; |
strysd | 3:9a1a6ebcdaa7 | 97 | LPC_SC->PLL0FEED = 0xAA; |
strysd | 3:9a1a6ebcdaa7 | 98 | LPC_SC->PLL0FEED = 0x55; |
strysd | 3:9a1a6ebcdaa7 | 99 | } |
strysd | 3:9a1a6ebcdaa7 | 100 | |
strysd | 3:9a1a6ebcdaa7 | 101 | unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short M, unsigned char N) |
strysd | 3:9a1a6ebcdaa7 | 102 | { |
strysd | 3:9a1a6ebcdaa7 | 103 | setPLL0Frequency(clkSrc, M, N); |
strysd | 3:9a1a6ebcdaa7 | 104 | LPC_SC->CCLKCFG = clkDivider - 1; |
strysd | 3:9a1a6ebcdaa7 | 105 | SystemCoreClockUpdate(); |
strysd | 3:9a1a6ebcdaa7 | 106 | return SystemCoreClock; |
strysd | 3:9a1a6ebcdaa7 | 107 | } |
yueee_yt | 0:27cf9683af17 | 108 | |
yueee_yt | 0:27cf9683af17 | 109 | int main() |
yueee_yt | 0:27cf9683af17 | 110 | { |
strysd | 3:9a1a6ebcdaa7 | 111 | setSystemFrequency(0x3, 0x1, 6, 1);//clock down from 96MHz to 48MHz |
strysd | 3:9a1a6ebcdaa7 | 112 | led1 = led3 = led4 = speed = link = 0; |
strysd | 3:9a1a6ebcdaa7 | 113 | pc.baud(USB_PAUD_RATE); |
strysd | 3:9a1a6ebcdaa7 | 114 | |
strysd | 3:9a1a6ebcdaa7 | 115 | //if you set LEDs for LAN indicator in real time. |
strysd | 3:9a1a6ebcdaa7 | 116 | //interval : 0.1 = 100ms |
strysd | 3:9a1a6ebcdaa7 | 117 | //flipper.attach(&myflip, 0.1); |
strysd | 3:9a1a6ebcdaa7 | 118 | |
yueee_yt | 0:27cf9683af17 | 119 | eth.init(); //Use DHCP |
yueee_yt | 0:27cf9683af17 | 120 | eth.connect(); |
strysd | 3:9a1a6ebcdaa7 | 121 | printf("IP: %s\r\n", eth.getIPAddress()); |
strysd | 3:9a1a6ebcdaa7 | 122 | |
strysd | 3:9a1a6ebcdaa7 | 123 | led1 = 1; |
strysd | 3:9a1a6ebcdaa7 | 124 | if(setFIAPStorage() != 0) { |
strysd | 3:9a1a6ebcdaa7 | 125 | printf("Check if storage.txt exists in mbed memory.\r\n"); |
strysd | 3:9a1a6ebcdaa7 | 126 | return -1; |
yueee_yt | 0:27cf9683af17 | 127 | } |
strysd | 3:9a1a6ebcdaa7 | 128 | led1 = 0; |
strysd | 3:9a1a6ebcdaa7 | 129 | |
strysd | 3:9a1a6ebcdaa7 | 130 | exitTimer = RETRY_TIMES_ON_ERROR; |
strysd | 3:9a1a6ebcdaa7 | 131 | while(exitTimer > 0) { |
strysd | 3:9a1a6ebcdaa7 | 132 | led3 = spd; |
strysd | 3:9a1a6ebcdaa7 | 133 | led4 = lnk; |
strysd | 3:9a1a6ebcdaa7 | 134 | if(USE_RJ45_LAMP == true){ |
strysd | 3:9a1a6ebcdaa7 | 135 | speed = !spd; |
strysd | 3:9a1a6ebcdaa7 | 136 | link = !lnk; |
strysd | 3:9a1a6ebcdaa7 | 137 | } |
strysd | 3:9a1a6ebcdaa7 | 138 | if (led4 == 1 || led3 == 1) { |
strysd | 3:9a1a6ebcdaa7 | 139 | exitTimer--; |
strysd | 3:9a1a6ebcdaa7 | 140 | wait(WAIT_NEXT_FETCH); |
strysd | 3:9a1a6ebcdaa7 | 141 | continue; |
strysd | 3:9a1a6ebcdaa7 | 142 | } |
strysd | 3:9a1a6ebcdaa7 | 143 | |
strysd | 3:9a1a6ebcdaa7 | 144 | if(fetchFIAP() != 0){ |
strysd | 3:9a1a6ebcdaa7 | 145 | led1 = 1; |
strysd | 3:9a1a6ebcdaa7 | 146 | exitTimer--; |
strysd | 3:9a1a6ebcdaa7 | 147 | } else { |
strysd | 3:9a1a6ebcdaa7 | 148 | led1 = 0; |
strysd | 3:9a1a6ebcdaa7 | 149 | exitTimer = RETRY_TIMES_ON_ERROR;//initialize |
strysd | 3:9a1a6ebcdaa7 | 150 | } |
strysd | 3:9a1a6ebcdaa7 | 151 | wait(WAIT_NEXT_FETCH); |
strysd | 3:9a1a6ebcdaa7 | 152 | } |
strysd | 3:9a1a6ebcdaa7 | 153 | eth.disconnect(); |
strysd | 3:9a1a6ebcdaa7 | 154 | if(FIAP_DEBUG_MODE == true){ |
strysd | 3:9a1a6ebcdaa7 | 155 | printf("Disconnected because of error\r\n"); |
strysd | 3:9a1a6ebcdaa7 | 156 | } |
strysd | 3:9a1a6ebcdaa7 | 157 | |
strysd | 3:9a1a6ebcdaa7 | 158 | return -1; |
yueee_yt | 0:27cf9683af17 | 159 | } |