###前提・実現したいこと
[日本語が下手]
Mosquitto の sub.py を php で実行させ、その retain のデータをブラウザで表示させたいです。
###発生している問題・エラーメッセージ
おそらく、mqttc.loop_forever() で処理が終わらずphpで表示出来ていないのだと思います、
よろしくお願いします!!
###ソースコード
sub.py
python
1 2import sys 3try: 4 import paho.mqtt.client as mqtt 5except ImportError: 6 # This part is only required to run the example from within the examples 7 # directory when the module itself is not installed. 8 # If you have the module installed, just use "import paho.mqtt.client" 9 import os 10 import inspect 11 cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"../src"))) 12 if cmd_subfolder not in sys.path: 13 sys.path.insert(0, cmd_subfolder) 14 import paho.mqtt.client as mqtt 15 16def on_connect(mqttc, obj, rc): 17 print("rc: "+str(rc)) 18 19def on_message(mqttc, obj, msg): 20 print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) 21 22def on_publish(mqttc, obj, mid): 23 print("mid: "+str(mid)) 24 25def on_subscribe(mqttc, obj, mid, granted_qos): 26 print("Subscribed: "+str(mid)+" "+str(granted_qos)) 27 28def on_log(mqttc, obj, level, string): 29 print(string) 30 31# If you want to use a specific client id, use 32# mqttc = mqtt.Client("client-id") 33# but note that the client id must be unique on the broker. Leaving the client 34# id parameter empty will generate a random id for you. 35mqttc = mqtt.Client() 36mqttc.on_message = on_message 37mqttc.on_connect = on_connect 38mqttc.on_publish = on_publish 39mqttc.on_subscribe = on_subscribe 40# Uncomment to enable debug messages 41# mqttc.on_log = on_log 42mqttc.connect("192.168.33.20", 1883, 60) 43mqttc.subscribe("kut", 0) 44 45mqttc.loop_forever() 46
call.php
php
1<?php 2echo "test"; 3 $fullPath = 'python sub.py'; 4 passthru($fullPath,$outpara); 5 var_dump($fullPath); 6 var_dump($outpara); 7?> 8 9 10
###補足情報(言語/FW/ツール等のバージョンなど)
環境
Mac OS X El Capitan 10.11.2
ブローカサーバ : Ubuntu 14.04
サブスクサーバ : Ubuntu 14.04
vagrant apache2
mqttクライアント : paho
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。