IEEE1888 GateWay sample that handles only 1 sensor. This is older repository, see IEEE1888_MULTI_SENSOR_GW. The newer version can handle multiple sensors.
Dependencies: EthernetInterface FiapV2 HTTPClientForSOAP NTPClient mbed-rtos mbed spxml
Fork of temp_FIAP by
This program sends only *1* data to FIAP storage with IEEE1888 format.
The data represents temperature degree Celsius taken from LM35 at P20. The LM35 is temperature sensor made by National Semiconductor.
Note 1: Newer repository is available. IEEE1888 (FIAP) multi sensor gateway can handle multiple sensors.
NOTE 2: You should define 2 constants at least before using this program. The constants are FIAP_STORAGE and POINT_ID, contained in main.h file. And You can also define other constants in main.h .
from here, in Japanese. これは、IEEE1888 形式でデータを *1種類だけ* 送信するプログラムです。 このプログラムは、P20 に接続した温度センサー LM35 の値を送信します。
注意: 下記のリポジトリーのプログラムは、複数のセンサーのデータをまとめて送信したい場合を考慮した、新しい Version です。 IEEE1888 (FIAP) multi sensor gateway
また、使用前に、main.h ファイルの定数を定義する必要があります。 (少なくとも FIAP_STORAGE および POINT_ID の2つ )
main.cpp@5:720a29128f41, 2013-02-12 (annotated)
- Committer:
- strysd
- Date:
- Tue Feb 12 01:02:15 2013 +0000
- Revision:
- 5:720a29128f41
- Parent:
- 4:f50c307c5eda
- Child:
- 6:cccef292257b
use define as debug_mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:27cf9683af17 | 1 | #include "mbed.h" |
yueee_yt | 0:27cf9683af17 | 2 | #include "EthernetInterface.h" |
yueee_yt | 0:27cf9683af17 | 3 | #include "NTPClient.h" |
yueee_yt | 0:27cf9683af17 | 4 | #include "fiap.h" |
yueee_yt | 0:27cf9683af17 | 5 | |
strysd | 4:f50c307c5eda | 6 | #define NTPServer "ntp.jst.mfeed.ad.jp" |
strysd | 5:720a29128f41 | 7 | #define CloudAddress "http://your.host.name/axis2/services/FIAPStorage" |
strysd | 5:720a29128f41 | 8 | #define DataIdentify "http://your.url/" |
strysd | 5:720a29128f41 | 9 | //Example: |
strysd | 5:720a29128f41 | 10 | //#define CloudAddress "http://ec2-999-999-999-999.ap-northeast-1.compute.amazonaws.com/axis2/services/FIAPStorage" |
strysd | 5:720a29128f41 | 11 | //#define DataIdentify "http://ramat.ram.ne.jp/" |
strysd | 5:720a29128f41 | 12 | #define DEBUG_MODE false |
yueee_yt | 0:27cf9683af17 | 13 | |
yueee_yt | 0:27cf9683af17 | 14 | EthernetInterface eth; |
yueee_yt | 0:27cf9683af17 | 15 | NTPClient ntp; |
yueee_yt | 0:27cf9683af17 | 16 | time_t ctTime; |
yueee_yt | 0:27cf9683af17 | 17 | |
strysd | 5:720a29128f41 | 18 | AnalogIn ain(p15);//censor |
strysd | 4:f50c307c5eda | 19 | |
strysd | 4:f50c307c5eda | 20 | DigitalOut led1(LED1);//error |
strysd | 5:720a29128f41 | 21 | DigitalOut led2(LED2);//tick running |
strysd | 4:f50c307c5eda | 22 | |
yueee_yt | 0:27cf9683af17 | 23 | char timezone[] = "+09:00"; // JST |
yueee_yt | 1:ddf5d6f68d58 | 24 | char atemp[6]; |
strysd | 4:f50c307c5eda | 25 | char TimeBuffer[9]; |
strysd | 4:f50c307c5eda | 26 | float ftemp; |
yueee_yt | 0:27cf9683af17 | 27 | struct fiap_element element[]= { |
strysd | 4:f50c307c5eda | 28 | {DataIdentify,atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 0:27cf9683af17 | 29 | }; |
strysd | 4:f50c307c5eda | 30 | struct tm t; |
strysd | 4:f50c307c5eda | 31 | FIAP fiap(CloudAddress); |
yueee_yt | 0:27cf9683af17 | 32 | |
yueee_yt | 0:27cf9683af17 | 33 | void tick(void ) |
yueee_yt | 0:27cf9683af17 | 34 | { |
strysd | 4:f50c307c5eda | 35 | led2=1; |
strysd | 5:720a29128f41 | 36 | ftemp=ain*330.0; //in case of LM35D |
yueee_yt | 0:27cf9683af17 | 37 | ctTime = time(NULL); |
strysd | 4:f50c307c5eda | 38 | strftime(TimeBuffer,9,"%X",localtime(&ctTime)); |
yueee_yt | 0:27cf9683af17 | 39 | // Save to FIAPStorage |
strysd | 4:f50c307c5eda | 40 | sprintf(atemp,"%4.1f",ftemp); |
strysd | 4:f50c307c5eda | 41 | t = *localtime(&ctTime); |
yueee_yt | 0:27cf9683af17 | 42 | element[0].value=atemp; |
yueee_yt | 0:27cf9683af17 | 43 | element[0].year=t.tm_year+1900; |
yueee_yt | 0:27cf9683af17 | 44 | element[0].month=t.tm_mon+1; |
yueee_yt | 0:27cf9683af17 | 45 | element[0].day=t.tm_mday; |
yueee_yt | 0:27cf9683af17 | 46 | element[0].hour=t.tm_hour; |
yueee_yt | 0:27cf9683af17 | 47 | element[0].minute=t.tm_min; |
yueee_yt | 0:27cf9683af17 | 48 | element[0].second=t.tm_sec; |
yueee_yt | 0:27cf9683af17 | 49 | fiap.post(element,1); |
strysd | 4:f50c307c5eda | 50 | led2=0; |
yueee_yt | 0:27cf9683af17 | 51 | } |
yueee_yt | 0:27cf9683af17 | 52 | |
yueee_yt | 0:27cf9683af17 | 53 | int main() |
yueee_yt | 0:27cf9683af17 | 54 | { |
strysd | 4:f50c307c5eda | 55 | led1 = led2 = 0; |
strysd | 4:f50c307c5eda | 56 | |
yueee_yt | 0:27cf9683af17 | 57 | //Ethernet Initialize |
yueee_yt | 0:27cf9683af17 | 58 | eth.init(); //Use DHCP |
yueee_yt | 0:27cf9683af17 | 59 | eth.connect(); |
strysd | 4:f50c307c5eda | 60 | printf("%s\r\n", eth.getIPAddress()); |
yueee_yt | 0:27cf9683af17 | 61 | printf("Trying to update time...\r\n"); |
yueee_yt | 0:27cf9683af17 | 62 | if (ntp.setTime(NTPServer) == 0) { |
yueee_yt | 0:27cf9683af17 | 63 | printf("Set time successfully\r\n"); |
yueee_yt | 0:27cf9683af17 | 64 | time_t ctTime; |
yueee_yt | 0:27cf9683af17 | 65 | ctTime = time(NULL); |
yueee_yt | 0:27cf9683af17 | 66 | ctTime+=32400; |
yueee_yt | 0:27cf9683af17 | 67 | set_time(ctTime); |
yueee_yt | 0:27cf9683af17 | 68 | ctTime = time(NULL); |
yueee_yt | 0:27cf9683af17 | 69 | printf("Time is set to (JST): %s\r\n", ctime(&ctTime)); |
yueee_yt | 0:27cf9683af17 | 70 | } else { |
strysd | 4:f50c307c5eda | 71 | printf("Error"); |
strysd | 4:f50c307c5eda | 72 | led1 = 1; |
yueee_yt | 0:27cf9683af17 | 73 | return -1; |
yueee_yt | 0:27cf9683af17 | 74 | } |
strysd | 5:720a29128f41 | 75 | fiap.debug_mode=DEBUG_MODE; |
yueee_yt | 0:27cf9683af17 | 76 | while(true) { |
yueee_yt | 0:27cf9683af17 | 77 | tick(); |
strysd | 4:f50c307c5eda | 78 | wait(5); |
yueee_yt | 0:27cf9683af17 | 79 | } |
strysd | 5:720a29128f41 | 80 | } |