IEEE1888 GateWay sample that handles multiple sensors.

Dependencies:   EthernetInterface Fiap HTTPClientForFIAP NTPClient mbed-rtos mbed spxml

Fork of IEEE1888_TEMP_NODE by Satoru Yoshida

This program sends data to FIAP storage with IEEE1888 format.

Note: You should locate storage.txt into mbed memory at least before using this program. The storage.txt contains storage url, see example at main.h

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 FiapStorage2 Sample", registered at Tokyo region (ap-northeast-1) .

If You need more information about the AMI, see http://d.hatena.ne.jp/satoruyoshida/20130611/1370961807 .

/media/uploads/strysd/fiap_ami.jpg

This image shows sample data of IEEE1888 format.

Note: this image is shown if FIAP_DEBUG_MODE is set to true.

/media/uploads/strysd/fiap_protocol.jpg

You can define COUNT_OF_POINTS constant as number of analog sensors and digital inputs. In this program, I use P19 and P20 as analog inputs from 2 sensors. So I define the COUNT_OF_POINTS as 2.

/media/uploads/strysd/fiap_gw.jpg

P19 is connected to illuminance sensor, S9648 (HAMAMATSU PHOTONICS K.K.). And P20 is connected to temperature sensor, LM35 (National Semiconductor Corporation) .

You can also use another analog sensors and digital inputs, for example LM61BIZ instead of LM35.

/media/uploads/strysd/server_room.png

/media/uploads/strysd/mymbed_multi_censor_initial.png

from here, in Japanese. このプログラムは IEEE1888 形式で FIAP Storage にデータ送信する例です。 このプログラムを使用する前に、少なくとも FIAP Storage の url を記載した sotrage.txt をメモリに格納しておく必要があります。 url の例は、 main.h ファイルにあります。

Amazon Web Service に用意した AMI を利用して FIAP Storage を起動することができます。IEEE1888 FiapStorage2 Sample という名前の公開 AMI です。

この AMI について詳しくは、http://d.hatena.ne.jp/satoruyoshida/20130611/1370961807 をご覧ください。

なお、main.h にはほかにも定数があります。例えば、IEEE1888 (FIAP) の通信内容をコンソールで確認したい場合は、FIAP_DEBUG_MODE を true にします。 また、アナログ・センサーやデジタル入力の個数に沿って、COUNT_OF_POINTS を定義します。

このプログラム例では、P19 および P20 をセンサーからのアナログ入力として使用しています。そのため、COUNT_OF_POINTS を 2 と定義しています。 P19 には浜松ホトニクス社製の照度センサー S9648、P20 にはナショナル・セミコンダクターの温度センサー LM35 を接続しています。 参考までに LM35 をより安価な LM61BIZ に置き換えた場合の設定値もコメントアウト状態で入れてあります

(ここから日本語文のみの内容) トランジスタ技術 2012年 2月号 の P189 - P195 に、Arduino、Ethernet シールド、温度センサー(LM35)、照度センサー(S9648-100)、DIP スイッチおよびトグルスイッチを用いたネットワーク温度&照度計の記事が掲載されています(落合 秀也 様/井上 博之 様)。 このプログラムでは、照度センサーは S9648-100 ではなく、より安価な S9648 で代用し、スイッチ 2 種類は省略していますのでご注意ください。 S9648 の負荷抵抗 1KΩ に並列に入れたコンデンサーは、手元に余っていた 0.1μF です。この容量が妥当かどうかは未検証です。

LM35 の出力をアンプで6倍に増幅してみたときのメモがここにあります。

https://mbed.org/users/strysd/notebook/memo_analog_input_from_lm35dz_via_nju7032d/

照度センサーを S9648-100 に変えて、抵抗値も検討したときのメモはこちら。

https://mbed.org/users/strysd/notebook/difference_s9648_and_s9648_100/

Committer:
strysd
Date:
Sun May 11 05:02:15 2014 +0000
Revision:
30:8a0cdc3b583a
Parent:
26:54b10f53bf41
sync libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
strysd 6:cccef292257b 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 "NTPClient.h"
yueee_yt 0:27cf9683af17 5 #include "fiap.h"
yueee_yt 0:27cf9683af17 6
yueee_yt 0:27cf9683af17 7 EthernetInterface eth;
yueee_yt 0:27cf9683af17 8 time_t ctTime;
strysd 18:f277fbbcea4b 9 Serial pc(USBTX, USBRX);
strysd 18:f277fbbcea4b 10 FIAP fiap;
yueee_yt 0:27cf9683af17 11
strysd 25:929a72bcd8d2 12 #ifdef P15_POINT_ID
strysd 25:929a72bcd8d2 13 AnalogIn ain_p15(p15);
strysd 25:929a72bcd8d2 14 #endif
strysd 25:929a72bcd8d2 15 #ifdef P16_POINT_ID
strysd 25:929a72bcd8d2 16 AnalogIn ain_p16(p16);
strysd 25:929a72bcd8d2 17 #endif
strysd 25:929a72bcd8d2 18 #ifdef P17_POINT_ID
strysd 25:929a72bcd8d2 19 AnalogIn ain_p17(p17);
strysd 25:929a72bcd8d2 20 #endif
strysd 25:929a72bcd8d2 21 #ifdef P18_POINT_ID
strysd 25:929a72bcd8d2 22 AnalogIn ain_p18(p18);
strysd 25:929a72bcd8d2 23 #endif
strysd 25:929a72bcd8d2 24 #ifdef P19_POINT_ID
strysd 13:4e51ac520b33 25 AnalogIn ain_p19(p19);
strysd 25:929a72bcd8d2 26 #endif
strysd 25:929a72bcd8d2 27 #ifdef P20_POINT_ID
strysd 13:4e51ac520b33 28 AnalogIn ain_p20(p20);
strysd 25:929a72bcd8d2 29 #endif
strysd 4:f50c307c5eda 30
strysd 13:4e51ac520b33 31 DigitalOut led1(LED1);//error while connecting to NTP server or FIAPStorage
strysd 8:e482433c9593 32 DigitalOut led3(LED3);//LAN speed (1 = error)
strysd 8:e482433c9593 33 DigitalOut led4(LED4);//LAN link (1 = error)
strysd 4:f50c307c5eda 34
strysd 8:e482433c9593 35 DigitalIn lnk(P1_25);//LAN link
strysd 8:e482433c9593 36 DigitalIn spd(P1_26);//LAN speed
strysd 25:929a72bcd8d2 37
strysd 25:929a72bcd8d2 38 #if USE_RJ45_LAMP
strysd 9:0d34968a5de1 39 DigitalOut speed(p29);//LAN speed for RJ45 (1 = OK)
strysd 9:0d34968a5de1 40 DigitalOut link(p30); //LAN link for RJ45 (1 = OK)
strysd 25:929a72bcd8d2 41 #endif
strysd 8:e482433c9593 42
strysd 8:e482433c9593 43 int exitTimer;
strysd 17:868a61434584 44 int i;
strysd 22:07b3f2643582 45 int this_year, this_mon;
strysd 13:4e51ac520b33 46
strysd 20:44214878a602 47 //I define longer than actual length.
strysd 20:44214878a602 48 //because last characters are chopped when I define just length, 64.
strysd 20:44214878a602 49 #define STORAGE_URL_SIZE 100
strysd 20:44214878a602 50 char storage_url[STORAGE_URL_SIZE];
strysd 18:f277fbbcea4b 51 struct fiap_element element[]= {
strysd 18:f277fbbcea4b 52 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},
strysd 18:f277fbbcea4b 53 };
strysd 18:f277fbbcea4b 54 struct tm t;
strysd 18:f277fbbcea4b 55
strysd 25:929a72bcd8d2 56 #ifdef P15_POINT_ID
strysd 26:54b10f53bf41 57 char val_p15[8];
strysd 17:868a61434584 58 float float_p15_wrk;
strysd 25:929a72bcd8d2 59 float float_p15;
strysd 25:929a72bcd8d2 60 #endif
strysd 25:929a72bcd8d2 61 #ifdef P16_POINT_ID
strysd 26:54b10f53bf41 62 char val_p16[8];
strysd 17:868a61434584 63 float float_p16_wrk;
strysd 25:929a72bcd8d2 64 float float_p16;
strysd 25:929a72bcd8d2 65 #endif
strysd 25:929a72bcd8d2 66 #ifdef P17_POINT_ID
strysd 26:54b10f53bf41 67 char val_p17[8];
strysd 17:868a61434584 68 float float_p17_wrk;
strysd 17:868a61434584 69 float float_p17;
strysd 25:929a72bcd8d2 70 #endif
strysd 25:929a72bcd8d2 71 #ifdef P18_POINT_ID
strysd 26:54b10f53bf41 72 char val_p18[8];
strysd 25:929a72bcd8d2 73 float float_p18_wrk;
strysd 17:868a61434584 74 float float_p18;
strysd 25:929a72bcd8d2 75 #endif
strysd 25:929a72bcd8d2 76 #ifdef P19_POINT_ID
strysd 26:54b10f53bf41 77 char val_p19[8];
strysd 25:929a72bcd8d2 78 float float_p19_wrk;
strysd 13:4e51ac520b33 79 float float_p19;
strysd 25:929a72bcd8d2 80 #endif
strysd 25:929a72bcd8d2 81 #ifdef P20_POINT_ID
strysd 26:54b10f53bf41 82 char val_p20[8];
strysd 25:929a72bcd8d2 83 float float_p20_wrk;
strysd 13:4e51ac520b33 84 float float_p20;
strysd 25:929a72bcd8d2 85 #endif
strysd 9:0d34968a5de1 86
strysd 18:f277fbbcea4b 87 int syncNTP(void)
strysd 18:f277fbbcea4b 88 {
strysd 18:f277fbbcea4b 89 NTPClient ntp;
strysd 18:f277fbbcea4b 90 if (ntp.setTime(NTP_SERVER) != 0) {
strysd 18:f277fbbcea4b 91 return -1;
strysd 18:f277fbbcea4b 92 }
strysd 18:f277fbbcea4b 93 ctTime = time(NULL);
strysd 18:f277fbbcea4b 94 ctTime+= TIME_ZONE_SECONDS;
strysd 18:f277fbbcea4b 95 set_time(ctTime);
strysd 18:f277fbbcea4b 96 return 0;
strysd 18:f277fbbcea4b 97 }
strysd 18:f277fbbcea4b 98
strysd 18:f277fbbcea4b 99 int setFIAPStorage(void )
strysd 18:f277fbbcea4b 100 {
strysd 18:f277fbbcea4b 101 LocalFileSystem local("local");
strysd 18:f277fbbcea4b 102 FILE *fp;
strysd 18:f277fbbcea4b 103 fp = fopen("/local/storage.txt", "r");
strysd 18:f277fbbcea4b 104 if(fp == NULL){
strysd 18:f277fbbcea4b 105 return -1;
strysd 18:f277fbbcea4b 106 }
strysd 20:44214878a602 107 fgets(storage_url, STORAGE_URL_SIZE, fp);
strysd 18:f277fbbcea4b 108 fiap.setStorage(storage_url);
strysd 18:f277fbbcea4b 109 fclose(fp);
strysd 18:f277fbbcea4b 110
strysd 18:f277fbbcea4b 111 fiap.debug_mode=FIAP_DEBUG_MODE;
strysd 18:f277fbbcea4b 112 return 0;
strysd 18:f277fbbcea4b 113 }
strysd 18:f277fbbcea4b 114
strysd 13:4e51ac520b33 115 int sendFIAP(void )
yueee_yt 0:27cf9683af17 116 {
yueee_yt 0:27cf9683af17 117 ctTime = time(NULL);
strysd 4:f50c307c5eda 118 t = *localtime(&ctTime);
strysd 10:51ef659414a9 119
strysd 25:929a72bcd8d2 120 #ifdef P15_POINT_ID
strysd 25:929a72bcd8d2 121 float_p15_wrk = ain_p15;//dummy read
strysd 25:929a72bcd8d2 122 float_p15_wrk = ain_p15;
strysd 25:929a72bcd8d2 123 float_p15_wrk += ain_p15;
strysd 25:929a72bcd8d2 124 float_p15 = float_p15_wrk/2 * P15_COEFFICIENT + P15_CONSTANT;
strysd 25:929a72bcd8d2 125 #endif
strysd 25:929a72bcd8d2 126 #ifdef P16_POINT_ID
strysd 25:929a72bcd8d2 127 float_p16_wrk = ain_p16;//dummy read
strysd 25:929a72bcd8d2 128 float_p16_wrk = ain_p16;
strysd 25:929a72bcd8d2 129 float_p16_wrk += ain_p16;
strysd 25:929a72bcd8d2 130 float_p16 = float_p16_wrk/2 * P16_COEFFICIENT + P16_CONSTANT;
strysd 25:929a72bcd8d2 131 #endif
strysd 25:929a72bcd8d2 132 #ifdef P17_POINT_ID
strysd 25:929a72bcd8d2 133 float_p17_wrk = ain_p17;//dummy read
strysd 25:929a72bcd8d2 134 float_p17_wrk = ain_p17;
strysd 25:929a72bcd8d2 135 float_p17_wrk += ain_p17;
strysd 25:929a72bcd8d2 136 float_p17 = float_p17_wrk/2 * P17_COEFFICIENT + P17_CONSTANT;
strysd 25:929a72bcd8d2 137 #endif
strysd 25:929a72bcd8d2 138 #ifdef P18_POINT_ID
strysd 25:929a72bcd8d2 139 float_p18_wrk = ain_p18;//dummy read
strysd 25:929a72bcd8d2 140 float_p18_wrk = ain_p18;
strysd 25:929a72bcd8d2 141 float_p18_wrk += ain_p18;
strysd 25:929a72bcd8d2 142 float_p18 = float_p18_wrk/2 * P18_COEFFICIENT + P18_CONSTANT;
strysd 25:929a72bcd8d2 143 #endif
strysd 25:929a72bcd8d2 144 #ifdef P19_POINT_ID
strysd 25:929a72bcd8d2 145 float_p19_wrk = ain_p19;//dummy read
strysd 25:929a72bcd8d2 146 float_p19_wrk = ain_p19;
strysd 25:929a72bcd8d2 147 float_p19_wrk += ain_p19;
strysd 25:929a72bcd8d2 148 float_p19 = float_p19_wrk/2 * P19_COEFFICIENT + P19_CONSTANT;
strysd 25:929a72bcd8d2 149 #endif
strysd 25:929a72bcd8d2 150 #ifdef P20_POINT_ID
strysd 25:929a72bcd8d2 151 float_p20_wrk = ain_p20;//dummy read
strysd 25:929a72bcd8d2 152 float_p20_wrk = ain_p20;
strysd 25:929a72bcd8d2 153 float_p20_wrk += ain_p20;
strysd 25:929a72bcd8d2 154 float_p20 = float_p20_wrk/2 * P20_COEFFICIENT + P20_CONSTANT;
strysd 25:929a72bcd8d2 155 #endif
strysd 17:868a61434584 156
strysd 25:929a72bcd8d2 157 #ifdef P15_POINT_ID
strysd 26:54b10f53bf41 158 sprintf(val_p15, P15_PREC, float_p15);
strysd 25:929a72bcd8d2 159 #endif
strysd 25:929a72bcd8d2 160 #ifdef P16_POINT_ID
strysd 26:54b10f53bf41 161 sprintf(val_p16, P16_PREC, float_p16);
strysd 25:929a72bcd8d2 162 #endif
strysd 25:929a72bcd8d2 163 #ifdef P17_POINT_ID
strysd 26:54b10f53bf41 164 sprintf(val_p17, P17_PREC, float_p17);
strysd 25:929a72bcd8d2 165 #endif
strysd 25:929a72bcd8d2 166 #ifdef P18_POINT_ID
strysd 26:54b10f53bf41 167 sprintf(val_p18, P18_PREC, float_p18);
strysd 25:929a72bcd8d2 168 #endif
strysd 25:929a72bcd8d2 169 #ifdef P19_POINT_ID
strysd 26:54b10f53bf41 170 sprintf(val_p19, P19_PREC, float_p19);
strysd 25:929a72bcd8d2 171 #endif
strysd 25:929a72bcd8d2 172 #ifdef P20_POINT_ID
strysd 26:54b10f53bf41 173 sprintf(val_p20, P20_PREC, float_p20);
strysd 25:929a72bcd8d2 174 #endif
strysd 13:4e51ac520b33 175
strysd 22:07b3f2643582 176 this_year = t.tm_year + 1900;
strysd 22:07b3f2643582 177 this_mon = t.tm_mon + 1;
strysd 24:06545ba01cf4 178
strysd 25:929a72bcd8d2 179 #ifdef P15_POINT_ID
strysd 25:929a72bcd8d2 180 struct fiap_element P15_element = {
strysd 25:929a72bcd8d2 181 P15_POINT_ID, val_p15, this_year, this_mon, t.tm_mday,
strysd 25:929a72bcd8d2 182 t.tm_hour, t.tm_min, t.tm_sec, TIME_ZONE_CHAR};
strysd 25:929a72bcd8d2 183 #endif
strysd 25:929a72bcd8d2 184 #ifdef P16_POINT_ID
strysd 25:929a72bcd8d2 185 struct fiap_element P16_element = {
strysd 25:929a72bcd8d2 186 P16_POINT_ID, val_p16, this_year, this_mon, t.tm_mday,
strysd 25:929a72bcd8d2 187 t.tm_hour, t.tm_min, t.tm_sec, TIME_ZONE_CHAR};
strysd 25:929a72bcd8d2 188 #endif
strysd 25:929a72bcd8d2 189 #ifdef P17_POINT_ID
strysd 25:929a72bcd8d2 190 struct fiap_element P17_element = {
strysd 25:929a72bcd8d2 191 P17_POINT_ID, val_p17, this_year, this_mon, t.tm_mday,
strysd 25:929a72bcd8d2 192 t.tm_hour, t.tm_min, t.tm_sec, TIME_ZONE_CHAR};
strysd 25:929a72bcd8d2 193 #endif
strysd 25:929a72bcd8d2 194 #ifdef P18_POINT_ID
strysd 25:929a72bcd8d2 195 struct fiap_element P18_element = {
strysd 25:929a72bcd8d2 196 P18_POINT_ID, val_p18, this_year, this_mon, t.tm_mday,
strysd 25:929a72bcd8d2 197 t.tm_hour, t.tm_min, t.tm_sec, TIME_ZONE_CHAR};
strysd 25:929a72bcd8d2 198 #endif
strysd 25:929a72bcd8d2 199 #ifdef P19_POINT_ID
strysd 22:07b3f2643582 200 struct fiap_element P19_element = {
strysd 22:07b3f2643582 201 P19_POINT_ID, val_p19, this_year, this_mon, t.tm_mday,
strysd 22:07b3f2643582 202 t.tm_hour, t.tm_min, t.tm_sec, TIME_ZONE_CHAR};
strysd 25:929a72bcd8d2 203 #endif
strysd 25:929a72bcd8d2 204 #ifdef P20_POINT_ID
strysd 22:07b3f2643582 205 struct fiap_element P20_element = {
strysd 22:07b3f2643582 206 P20_POINT_ID, val_p20, this_year, this_mon, t.tm_mday,
strysd 22:07b3f2643582 207 t.tm_hour, t.tm_min, t.tm_sec, TIME_ZONE_CHAR};
strysd 25:929a72bcd8d2 208 #endif
strysd 17:868a61434584 209
strysd 25:929a72bcd8d2 210 i = 0;
strysd 25:929a72bcd8d2 211 #ifdef P15_POINT_ID
strysd 25:929a72bcd8d2 212 element[i++] = P15_element;
strysd 25:929a72bcd8d2 213 #endif
strysd 25:929a72bcd8d2 214 #ifdef P16_POINT_ID
strysd 25:929a72bcd8d2 215 element[i++] = P16_element;
strysd 25:929a72bcd8d2 216 #endif
strysd 25:929a72bcd8d2 217 #ifdef P17_POINT_ID
strysd 25:929a72bcd8d2 218 element[i++] = P17_element;
strysd 25:929a72bcd8d2 219 #endif
strysd 25:929a72bcd8d2 220 #ifdef P18_POINT_ID
strysd 25:929a72bcd8d2 221 element[i++] = P18_element;
strysd 25:929a72bcd8d2 222 #endif
strysd 25:929a72bcd8d2 223 #ifdef P19_POINT_ID
strysd 25:929a72bcd8d2 224 element[i++] = P19_element;
strysd 25:929a72bcd8d2 225 #endif
strysd 25:929a72bcd8d2 226 #ifdef P20_POINT_ID
strysd 25:929a72bcd8d2 227 element[i++] = P20_element;
strysd 25:929a72bcd8d2 228 #endif
strysd 25:929a72bcd8d2 229 return fiap.post(element, i);
yueee_yt 0:27cf9683af17 230 }
yueee_yt 0:27cf9683af17 231
strysd 25:929a72bcd8d2 232 #if FIAP_DEBUG_MODE
strysd 25:929a72bcd8d2 233 #else
strysd 17:868a61434584 234 /* stop USB Interface */
strysd 17:868a61434584 235 #define USR_POWERDOWN (0x104)
strysd 17:868a61434584 236 int semihost_powerdown() {
strysd 17:868a61434584 237 uint32_t arg;
strysd 17:868a61434584 238 return __semihost(USR_POWERDOWN, &arg);
strysd 17:868a61434584 239 }
strysd 25:929a72bcd8d2 240 #endif
strysd 17:868a61434584 241
strysd 20:44214878a602 242 /** Frequency Control
strysd 20:44214878a602 243 * @see ClockControl/ClockControl.cpp by Michael Wei
strysd 20:44214878a602 244 */
strysd 18:f277fbbcea4b 245 void setPLL0Frequency(unsigned char clkSrc, unsigned short M, unsigned char N)
strysd 18:f277fbbcea4b 246 {
strysd 18:f277fbbcea4b 247 LPC_SC->CLKSRCSEL = clkSrc;
strysd 18:f277fbbcea4b 248 LPC_SC->PLL0CFG = (((unsigned int)N-1) << 16) | M-1;
strysd 18:f277fbbcea4b 249 LPC_SC->PLL0CON = 0x01;
strysd 18:f277fbbcea4b 250 LPC_SC->PLL0FEED = 0xAA;
strysd 18:f277fbbcea4b 251 LPC_SC->PLL0FEED = 0x55;
strysd 18:f277fbbcea4b 252 while (!(LPC_SC->PLL0STAT & (1<<26)));
strysd 18:f277fbbcea4b 253
strysd 18:f277fbbcea4b 254 LPC_SC->PLL0CON = 0x03;
strysd 18:f277fbbcea4b 255 LPC_SC->PLL0FEED = 0xAA;
strysd 18:f277fbbcea4b 256 LPC_SC->PLL0FEED = 0x55;
strysd 18:f277fbbcea4b 257 }
strysd 18:f277fbbcea4b 258
strysd 18:f277fbbcea4b 259 unsigned int setSystemFrequency(unsigned char clkDivider, unsigned char clkSrc, unsigned short M, unsigned char N)
strysd 18:f277fbbcea4b 260 {
strysd 18:f277fbbcea4b 261 setPLL0Frequency(clkSrc, M, N);
strysd 18:f277fbbcea4b 262 LPC_SC->CCLKCFG = clkDivider - 1;
strysd 18:f277fbbcea4b 263 SystemCoreClockUpdate();
strysd 18:f277fbbcea4b 264 return SystemCoreClock;
strysd 18:f277fbbcea4b 265 }
strysd 18:f277fbbcea4b 266
yueee_yt 0:27cf9683af17 267 int main()
yueee_yt 0:27cf9683af17 268 {
strysd 20:44214878a602 269 setSystemFrequency(0x3, 0x1, 6, 1);//clock down from 96MHz to 48MHz
strysd 25:929a72bcd8d2 270 led1 = led3 = led4 = 0;
strysd 9:0d34968a5de1 271
strysd 25:929a72bcd8d2 272 #if USE_RJ45_LAMP
strysd 25:929a72bcd8d2 273 speed = link = 0;
strysd 25:929a72bcd8d2 274 #endif
strysd 25:929a72bcd8d2 275
strysd 25:929a72bcd8d2 276 pc.baud(USB_PAUD_RATE);
strysd 4:f50c307c5eda 277
yueee_yt 0:27cf9683af17 278 eth.init(); //Use DHCP
yueee_yt 0:27cf9683af17 279 eth.connect();
strysd 10:51ef659414a9 280 printf("IP: %s\r\n", eth.getIPAddress());
strysd 18:f277fbbcea4b 281
strysd 10:51ef659414a9 282 led1 = 1;
strysd 18:f277fbbcea4b 283 if(syncNTP() != 0) {
strysd 18:f277fbbcea4b 284 printf("NTP Sync Error\r\n");
strysd 18:f277fbbcea4b 285 return -1;
strysd 18:f277fbbcea4b 286 }
strysd 18:f277fbbcea4b 287 ctTime = time(NULL);
strysd 18:f277fbbcea4b 288 printf("Time: %s\r\n", ctime(&ctTime));
strysd 18:f277fbbcea4b 289
strysd 18:f277fbbcea4b 290 if(setFIAPStorage() != 0) {
strysd 18:f277fbbcea4b 291 printf("Check if storage.txt exists in mbed memory.\r\n");
yueee_yt 0:27cf9683af17 292 return -1;
yueee_yt 0:27cf9683af17 293 }
strysd 10:51ef659414a9 294 led1 = 0;
strysd 18:f277fbbcea4b 295
strysd 25:929a72bcd8d2 296 #if FIAP_DEBUG_MODE
strysd 25:929a72bcd8d2 297 #else
strysd 18:f277fbbcea4b 298 semihost_powerdown();//Stop also USB Interface
strysd 25:929a72bcd8d2 299 #endif
strysd 13:4e51ac520b33 300
strysd 13:4e51ac520b33 301 exitTimer = RETRY_TIMES_ON_ERROR;
strysd 8:e482433c9593 302 while(exitTimer > 0) {
strysd 8:e482433c9593 303 led3 = spd;
strysd 8:e482433c9593 304 led4 = lnk;
strysd 25:929a72bcd8d2 305
strysd 25:929a72bcd8d2 306 #if USE_RJ45_LAMP
strysd 25:929a72bcd8d2 307 speed = !spd;
strysd 25:929a72bcd8d2 308 link = !lnk;
strysd 25:929a72bcd8d2 309 #endif
strysd 25:929a72bcd8d2 310
strysd 8:e482433c9593 311 if (led4 == 1 || led3 == 1) {
strysd 8:e482433c9593 312 exitTimer--;
strysd 13:4e51ac520b33 313 wait(WAIT_NEXT_SEND);
strysd 13:4e51ac520b33 314 continue;
strysd 13:4e51ac520b33 315 }
strysd 13:4e51ac520b33 316
strysd 18:f277fbbcea4b 317 if(sendFIAP() != 0){
strysd 13:4e51ac520b33 318 led1 = 1;
strysd 13:4e51ac520b33 319 exitTimer--;
strysd 8:e482433c9593 320 } else {
strysd 13:4e51ac520b33 321 led1 = 0;
strysd 13:4e51ac520b33 322 exitTimer = RETRY_TIMES_ON_ERROR;//initialize
strysd 8:e482433c9593 323 }
strysd 13:4e51ac520b33 324 wait(WAIT_NEXT_SEND);
yueee_yt 0:27cf9683af17 325 }
strysd 8:e482433c9593 326 eth.disconnect();
strysd 25:929a72bcd8d2 327 #if FIAP_DEBUG_MODE
strysd 25:929a72bcd8d2 328 printf("Disconnected because of error\r\n");
strysd 25:929a72bcd8d2 329 #endif
strysd 13:4e51ac520b33 330
strysd 8:e482433c9593 331 return -1;
strysd 5:720a29128f41 332 }