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 Feb 17 00:50:55 2013 +0000
Revision:
13:4e51ac520b33
Parent:
12:96ad8d612f6e
Child:
14:676fc0c95f2b
first release

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 NTPClient ntp;
yueee_yt 0:27cf9683af17 9 time_t ctTime;
yueee_yt 0:27cf9683af17 10
strysd 13:4e51ac520b33 11 AnalogIn ain_p19(p19);
strysd 13:4e51ac520b33 12 AnalogIn ain_p20(p20);
strysd 4:f50c307c5eda 13
strysd 13:4e51ac520b33 14 DigitalOut led1(LED1);//error while connecting to NTP server or FIAPStorage
strysd 8:e482433c9593 15 DigitalOut led2(LED2);//sendFIAP
strysd 8:e482433c9593 16 DigitalOut led3(LED3);//LAN speed (1 = error)
strysd 8:e482433c9593 17 DigitalOut led4(LED4);//LAN link (1 = error)
strysd 4:f50c307c5eda 18
strysd 8:e482433c9593 19 DigitalIn lnk(P1_25);//LAN link
strysd 8:e482433c9593 20 DigitalIn spd(P1_26);//LAN speed
strysd 9:0d34968a5de1 21 DigitalOut speed(p29);//LAN speed for RJ45 (1 = OK)
strysd 9:0d34968a5de1 22 DigitalOut link(p30); //LAN link for RJ45 (1 = OK)
strysd 8:e482433c9593 23
strysd 8:e482433c9593 24 int exitTimer;
strysd 13:4e51ac520b33 25 int sendResult;
strysd 13:4e51ac520b33 26
strysd 13:4e51ac520b33 27 char val_p19[6];
strysd 13:4e51ac520b33 28 char val_p20[6];
strysd 13:4e51ac520b33 29
strysd 13:4e51ac520b33 30 float float_p19;
strysd 13:4e51ac520b33 31 float float_p20;
strysd 13:4e51ac520b33 32
yueee_yt 0:27cf9683af17 33 struct fiap_element element[]= {
strysd 13:4e51ac520b33 34 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,TIME_ZONE_CHAR},
yueee_yt 0:27cf9683af17 35 };
strysd 4:f50c307c5eda 36 struct tm t;
strysd 8:e482433c9593 37 FIAP fiap(FIAP_STORAGE);
yueee_yt 0:27cf9683af17 38
strysd 9:0d34968a5de1 39 //if you set LEDs for LAN indicator in real time.
strysd 9:0d34968a5de1 40 /*
strysd 9:0d34968a5de1 41 Ticker flipper;
strysd 9:0d34968a5de1 42
strysd 9:0d34968a5de1 43 void myflip() {
strysd 9:0d34968a5de1 44 led3 = spd;
strysd 9:0d34968a5de1 45 led4 = lnk;
strysd 9:0d34968a5de1 46 speed = !spd;
strysd 9:0d34968a5de1 47 link = !lnk;
strysd 9:0d34968a5de1 48 }
strysd 9:0d34968a5de1 49 */
strysd 9:0d34968a5de1 50
strysd 13:4e51ac520b33 51 int sendFIAP(void )
yueee_yt 0:27cf9683af17 52 {
yueee_yt 0:27cf9683af17 53 ctTime = time(NULL);
strysd 13:4e51ac520b33 54
strysd 13:4e51ac520b33 55 float_p19 = ain_p19 * P19_COEFFICIENT + P19_CONSTANT;
strysd 13:4e51ac520b33 56 float_p20 = ain_p20 * P20_COEFFICIENT + P20_CONSTANT;
strysd 13:4e51ac520b33 57
strysd 4:f50c307c5eda 58 t = *localtime(&ctTime);
strysd 10:51ef659414a9 59
strysd 13:4e51ac520b33 60 sprintf(val_p19,"%4.1f",float_p19);
strysd 13:4e51ac520b33 61 sprintf(val_p20,"%4.1f",float_p20);
strysd 13:4e51ac520b33 62
strysd 13:4e51ac520b33 63 if (FIAP_DEBUG_MODE == false){
strysd 13:4e51ac520b33 64 //instead of displaying FIAP protocol if you like
strysd 13:4e51ac520b33 65 printf("Time: %s ,", ctime(&ctTime));
strysd 13:4e51ac520b33 66 printf("Illuminance: %s ,", val_p19);
strysd 13:4e51ac520b33 67 printf("Temperature: %s \n\r", val_p20);
strysd 10:51ef659414a9 68 }
strysd 13:4e51ac520b33 69
strysd 13:4e51ac520b33 70 //P19
strysd 13:4e51ac520b33 71 element[0].cid=P19_POINT_ID;
strysd 13:4e51ac520b33 72 element[0].value=val_p19;
strysd 13:4e51ac520b33 73
strysd 13:4e51ac520b33 74 //P20
strysd 13:4e51ac520b33 75 element[1].cid=P20_POINT_ID;
strysd 13:4e51ac520b33 76 element[1].value=val_p20;
strysd 13:4e51ac520b33 77
strysd 13:4e51ac520b33 78 element[0].year = element[1].year =t.tm_year+1900;
strysd 13:4e51ac520b33 79 element[0].month = element[1].month =t.tm_mon+1;
strysd 13:4e51ac520b33 80 element[0].day = element[1].day =t.tm_mday;
strysd 13:4e51ac520b33 81 element[0].hour = element[1].hour =t.tm_hour;
strysd 13:4e51ac520b33 82 element[0].minute= element[1].minute=t.tm_min;
strysd 13:4e51ac520b33 83 element[0].second= element[1].second=t.tm_sec;
strysd 13:4e51ac520b33 84
strysd 13:4e51ac520b33 85 return fiap.post(element,COUNT_OF_POINTS);
yueee_yt 0:27cf9683af17 86 }
yueee_yt 0:27cf9683af17 87
yueee_yt 0:27cf9683af17 88 int main()
yueee_yt 0:27cf9683af17 89 {
strysd 9:0d34968a5de1 90 led1 = led2 = led3 = led4 = speed = link = 0;
strysd 9:0d34968a5de1 91
strysd 9:0d34968a5de1 92 //if you set LEDs for LAN indicator in real time.
strysd 9:0d34968a5de1 93 //interval : 0.1 = 100ms
strysd 9:0d34968a5de1 94 //flipper.attach(&myflip, 0.1);
strysd 4:f50c307c5eda 95
yueee_yt 0:27cf9683af17 96 eth.init(); //Use DHCP
yueee_yt 0:27cf9683af17 97 eth.connect();
strysd 10:51ef659414a9 98 printf("IP: %s\r\n", eth.getIPAddress());
strysd 10:51ef659414a9 99 led1 = 1;
strysd 8:e482433c9593 100 if (ntp.setTime(NTP_SERVER) != 0) {
strysd 8:e482433c9593 101 printf("NTP Error\r\n");
yueee_yt 0:27cf9683af17 102 return -1;
yueee_yt 0:27cf9683af17 103 }
strysd 10:51ef659414a9 104 led1 = 0;
strysd 8:e482433c9593 105 time_t ctTime;
strysd 8:e482433c9593 106 ctTime = time(NULL);
strysd 8:e482433c9593 107 ctTime+= TIME_ZONE_SECONDS;
strysd 8:e482433c9593 108 set_time(ctTime);
strysd 8:e482433c9593 109 ctTime = time(NULL);
strysd 10:51ef659414a9 110 printf("Time: %s\r\n", ctime(&ctTime));
strysd 8:e482433c9593 111
strysd 13:4e51ac520b33 112 fiap.debug_mode=FIAP_DEBUG_MODE;
strysd 13:4e51ac520b33 113
strysd 13:4e51ac520b33 114 exitTimer = RETRY_TIMES_ON_ERROR;
strysd 8:e482433c9593 115 while(exitTimer > 0) {
strysd 8:e482433c9593 116 led3 = spd;
strysd 8:e482433c9593 117 led4 = lnk;
strysd 13:4e51ac520b33 118 speed = !spd;
strysd 13:4e51ac520b33 119 link = !lnk;
strysd 8:e482433c9593 120 if (led4 == 1 || led3 == 1) {
strysd 8:e482433c9593 121 exitTimer--;
strysd 13:4e51ac520b33 122 wait(WAIT_NEXT_SEND);
strysd 13:4e51ac520b33 123 continue;
strysd 13:4e51ac520b33 124 }
strysd 13:4e51ac520b33 125
strysd 13:4e51ac520b33 126 led2 = 1;
strysd 13:4e51ac520b33 127 sendResult = sendFIAP();
strysd 13:4e51ac520b33 128 led2 = 0;
strysd 13:4e51ac520b33 129 if(sendResult == -1){
strysd 13:4e51ac520b33 130 led1 = 1;
strysd 13:4e51ac520b33 131 exitTimer--;
strysd 8:e482433c9593 132 } else {
strysd 13:4e51ac520b33 133 led1 = 0;
strysd 13:4e51ac520b33 134 exitTimer = RETRY_TIMES_ON_ERROR;//initialize
strysd 8:e482433c9593 135 }
strysd 13:4e51ac520b33 136 wait(WAIT_NEXT_SEND);
yueee_yt 0:27cf9683af17 137 }
strysd 8:e482433c9593 138 eth.disconnect();
strysd 8:e482433c9593 139 printf("Disconnected\r\n");
strysd 13:4e51ac520b33 140
strysd 10:51ef659414a9 141 led1 = led2 = led3 = led4 = speed = link = 0;
strysd 8:e482433c9593 142 return -1;
strysd 5:720a29128f41 143 }