SNS을 이용한 개인용 화재 경보 시스템 만들기
본 포스팅에서는 집 안 온도가 임계치 이상으로 올라가면 구조 요청 메시지를 Facebook으로 올리는 개인용 화재 경보 시스템을 만드는 방법을 설명한다.
시스템 구성
본 포스팅의 화재 경보 시스템의 구성요소는 아래와 같다.
Sensor Device
- 집 안 온도를 측정 하여 Cloud Server에 송신
- KL-25Z ( MCU Board, mbed enabled )+WIZ550io(Ethernet) + DS18B20(온도센서)로 구성
Cloud Server ( Xively )
- Sensor Device로 부터 수집된 정보를 수집하고, 측정 값이 임계치 이상이면 Trigger를 발생하여 Proxy Server에게 전달
Proxy Server ( Zapier )
- Cloud Server로 부터 Trigger 정보를 받으면, 등록된 Service로 Message를 Publish 함.
User Service
- 본 포스팅에서는 Facebook을 이용하였지만, Zapier를 이용하면 gmail, twitter, evernote, tumblr, github등 다양한 Service를 이용 할 수 있음.
아래 그림은 위에서 설명한 요소들로 구성한 전체직인 시스템 Diagram이다.
![](https://t1.daumcdn.net/cfile/tistory/243B6333543DC82420)
Sensor Device
1. KL-25Z(mbed enabled MCU) + WIZ550io ( W5500 )
WIZ550io는 Arduino Board와 호환 되도록 설계 되어 있으며, KL-25Z 또한 Arduino Shield와 호환 되도록 설계 되어 있는 mbed Platform Board 이다.
이런 이유로, KL-25Z에서 WIZ550io를 이용하여 ethernet을 사용하기 위해서는 아래 그림과 같이 커넥터로 연결만 하면 된다.
커넥터 연결을 위한 자세한 설명은 [FRDM-KL25Z]WIZ550 ioShield-A Porting Guide를 참고 하기 바란다.
센서 보드의 연결을 위해 WIZ550io의 Shield 에 Female 커넥터를 아래 그림과 같이 부착 하였다.
![](https://t1.daumcdn.net/cfile/tistory/22448933543DC8501C)
2. DS18B20 ( Temperature Sensor )
온도 센서 DS18B20의 스펙은 아래와 같다.
위 사진은 DS18B20을 사용한 온도센서 모듈 사진이며, KL25Z + WIZ550io와는 아래 그림과 같이 연결 하면 된다.
- 붉은선 : 3.3V VCC
- 검은선 : GND
- 녹색선 : D3
Xively Server 설정
Xively Server를 설정하기 위한 방법은 [Arduino Uno WiFi Shield]WizFi250과 Xively를 이용하여 온도 센서 모니터링 하기 (2/2)
2014/02]를 참고 하기 바란다.
Sensor Device로 부터 수신 된 데이터 중 온도가 28ºC 이상이면, Facebook에 메시지를 전달하기 위해 Trigger를 아래와 같이 추가한다.
생성된 HTTP POST URL은 zapier 설정 시 사용해야 하므로, 잘 메모해 두길 바란다.
![](https://t1.daumcdn.net/cfile/tistory/245FA64C543DC94618)
zapier 설정
- Login to zapier
- Make a New Zap
- Choose a trigger and action
- When this Happens 카테고리에 Web Hook와 Catch Hook를 선택
- Do This 카테고리에 Facebook과 Post to Timeline 선택
- 다른 SNS를 사용하고 싶은 경우 Facebook 대신 다른 SNS Service를 선택하면 됨
- Select a Web Hook account
- Xively에서 발급 받은 HTTP POST URL을 기입
Facebook 계정 연결
![](https://t1.daumcdn.net/cfile/tistory/241CF33D543DCA0F35)
![](https://t1.daumcdn.net/cfile/tistory/2327243D543DCA0F27)
Trigger 발생 시, Facebook에 올릴 메시지 기입
![](https://t1.daumcdn.net/cfile/tistory/212E063E543DCA392E)
- Test this Zap은 무시해도 무관하다.
![](https://t1.daumcdn.net/cfile/tistory/216F6747543DCAEA32)
Name and turn this Zap on
생성한 zap의 이름을 지정하고, Turn Zap on 버튼틀 클릭하여 zap을 활성화 시킨다.
![](https://t1.daumcdn.net/cfile/tistory/25795539543DCB0A35)
위 과정이 성공적으로 끝나면, 아래 사진과 같은 화면을 볼 수 있다.
![](https://t1.daumcdn.net/cfile/tistory/25529C38543DCB782E)
Download Firmware
- Connect to mbed site and run mbed web compiler
Import WIZ550io_Xively_Demo Example to mbed web compiler
- WIZ550io_Xively_Demo Example 검색 후, Import program 버튼 클릭
![](https://t1.daumcdn.net/cfile/tistory/2652333A543DCBDE38)
- WIZ550io_Xively_Demo Example를 Compiler의 Program workspace에 추가
![](https://t1.daumcdn.net/cfile/tistory/2716F342543DCC1317)
Xively에서 발급 받은 FEED ID와 API Key를 Source Code에 입력
#define XI_FEED_ID xxxxxxxxxxxxxx
#define XI_API_KEY "xxxxxxxxxxx"
추가로, Xively Server에서 설정한 Channel ID의 값과 아래 코드에서 설정한 datastream_id 값은 동일 해야 한다.
(본 예제에서는 Channel ID를 “Channel_Test1”으로 설정 함.)
feed.datastreams[0].datapoint_count = 1;
xi_datastream_t* orientation_datastream = &feed.datastreams[0];
strcpy( orientation_datastream->datastream_id, "Channel_Test1" );
xi_datapoint_t* current_orientation = &orientation_datastream->datapoints[0];
Compile Source Code
web compiler에서 compile을 클릭하면, 해당 Example에 대한 바이너리 파일이 아래와 같이 생성 된다.
![](https://t1.daumcdn.net/cfile/tistory/2363573F543DCC652F)
Download binary file to KL25Z board
생성된 바이너리를 KL25Z Board의 Driver에 복사하면 Firmware Download가 완료 된다.
자세한 내용은 자세한 내용은 [mbed]2.NUCLEO Board 구동하기 2/2 참고
Run Application
Sensor Board에 LAN Cable을 연결하고 전원을 인가하면, 온도 센서를 이용하여 온도를 측정 한 후, Xively Server에 데이터를 송신하는 과정을 Serial Terminal로 확인 할 수 있다.
![](https://t1.daumcdn.net/cfile/tistory/27515840543DCC8320)
Xively Server에서 데이터를 수신하면 아래 사진과 같이 Request Log로 Feed 값이 갱신 되는 것을 볼 수 있다.
![](https://t1.daumcdn.net/cfile/tistory/22221E42543DCC9C0D)
또한 앞에 Trigger에서 설정한 것과 같이 온도가 28ºC 이상이 되면 zapier Server에 그 정보를 알리고, zapier는 등록된 서비스인 Facebook을 이용하여 메시지를 송신 한다.
![](https://t1.daumcdn.net/cfile/tistory/26538B3E543DCCBB0B)