Skip to content

Instantly share code, notes, and snippets.

@53ningen
Last active August 29, 2015 14:03
Show Gist options
  • Save 53ningen/215bcd79b2a6ac9b347b to your computer and use it in GitHub Desktop.
Save 53ningen/215bcd79b2a6ac9b347b to your computer and use it in GitHub Desktop.
Mosquittoまわり

Mosquitto の導入

参考:http://tomowatanabe.hatenablog.com/entry/2014/04/21/095650

Mosquittoはデフォルトで1883ポートを使用するので,必要に応じてポートを開放する.

on CentOS6

Mosquittoのインストール

cd /etc/yum.repos.d/
sudo wget http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/home:oojah:mqtt.repo
yum install mosquitto

Mosquittoの起動

sudo /etc/rc.d/init.d/mosquitto start

Pahoクライアントの導入

# python, pipが入ってなければ入れる
sudo yum install python
wget https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
pip install mosquitto

# Pahoクライアントを導入
sudo pip install paho-mqtt

Pub/Sub

wget https://gist.githubusercontent.com/tomovwgti/11048251/raw/705036b16326871a58bf01a3fa9b765eea28ac44/pub.py
wget https://gist.githubusercontent.com/tomovwgti/11047563/raw/fd2dd031b7bb3533f1f4626967db9439b315ca2f/sub.py

vim pub.py
# ホスト名を書き換える

vim sub.py
# ホスト名を書き換える

python sub.py
python pub.py  # => message 0 Hello MQTT!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment