2014년 11월 21일 금요일

Raspberry Pi + MQTT 설치와 실행 테스트


$ cd /home/pi 
$ sudo mkdir Mosquitto 

//의존성 라이브러리 설치
$ sudo apt-get -y install libwrap0-dev libssl-dev

//mosquitto 다운로드
$ sudo wget http://mosquitto.org/files/source/mosquitto-1.0.2.tar.gz
$ sudo tar zxf mosquitto-1.0.2.tar.gz
$ cd mosquitto-1.0.2
$ make
$ sudo make install
$ sudo ldconfig
$ sudo make clean

// iptables의 1883 포트 허용
$ sudo iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT
$ mosquitto

//환경파일
/etc/mosquitto/mosquitto.conf

//신규 터미널 생성 후 raspberry pi의 ssh 접속과 mosquitto subcribe
$ mosquitto_sub -d -t hello/world
Client mosqsub/6977-raspberryp sending CONNECT
Client mosqsub/6977-raspberryp received CONNACK
Client mosqsub/6977-raspberryp sending SUBSCRIBE (Mid: 1, Topic: hello/world, QoS: 0)
Client mosqsub/6977-raspberryp received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/6977-raspberryp sending PINGREQ
Client mosqsub/6977-raspberryp received PINGRESP

//신규 터미널 생성 후 raspberry pi의 ssh 접속과 mosquitto publish
$mosquitto_pub -d -t hello/world -m "안녕 안녕" 
Client mosqpub/7002-raspberryp sending CONNECT
Client mosqpub/7002-raspberryp received CONNACK
Client mosqpub/7002-raspberryp sending PUBLISH (d0, q0, r0, m1, 'hello/world', ... (12 bytes))

Client mosqpub/7002-raspberryp sending DISCONNECT

//subscribe했던 클라이언트에서 패킷 수신 확인 
Client mosqsub/6977-raspberryp received PUBLISH (d0, q0, r0, m0, 'hello/world', ... (12 bytes))

안녕안녕

댓글 없음:

댓글 쓰기