问题描述
HI
我使用Mosquitto-PHP为MQTT安装PHP客户端
[]
之后创建pub。在浏览器http://210.201.4.120/mqtt/pup.php中写入/ var / www / html / mqtt中的php并且没有看到任何数据
然后我试过
$ mosquitto_pub -h localhost -t/ mqtt-mHelloWorld
和得到
bash:-h:找不到命令
我不知道问题出在哪里是,信息写入命令
$ mosquitto -v
1464002857:mosquitto版本1.4.8(建造日期星期二,2016年5月17日11:26:59 +0100)开始
1464002857:使用默认配置。
1464002857:O在端口1883上输入ipv4监听套接字。
1464002857:错误:地址已在使用
我的窗口中也有同样的问题我安装mosquitto,请看这个链接
[]
我看到Mosquitto Broker(MQTT v3.1经纪人)的服务是runnng并检查示例pub.php进行测试
[]
结果是错误Mosquitto \Client( )找不到
我搜索并找到了mosquitto.php
[]
并把我把这段代码放在pub.php中>
需要mosquitto.php;
我不知道问题出在哪里,任何人都可以帮忙我在我的窗户和覆盆子里运行mosquitto。
我需要尝试使用php运行runnig mosquitto并且可以与localhost连接并检查连接是否可以订阅并发布和阅读消息
我尝试过:
require mosquitto.php;
$ client = new Mosquitto \Client();
$ client-> onConnect(' connect');
$ client-> onDisconnect(' disconnect');
$ client-> onSubscribe(' subscribe');
$ client-> onMessage(' message');
$ client-> connect( localhost,1883,5);
$ client-> subscribe(' /#',1);
while (true){
$ client-> loop();
$ mid = $ client-> publish(' / hello', 来自PHP的Hello .date(' Ymd H:i:s'),1,0);
echo 已发送的消息ID:{$中间} \\\
;
$ client-> loop();
sleep(2);
}
$ client-> disconnect();
unset($ client);
函数connect($ r){
echo 我得到了代码{$ r} \ n;
}
函数subscribe(){
echo 订阅主题\ n;
}
函数消息($ message){
printf( 收到消息带有效负载的主题%s上的ID%d:\ n%s \ n \ n,$ message-> mid,$ message-> topic,$ message-> payload);
}
function disconnect(){
echo 干净地断开连接;
}
HII install PHP client for MQTT using Mosquitto-PHP
Library in raspberry mosquitto php library/[^]
after that create pub.php in /var/www/html/mqtt when write in browser http://210.201.4.120/mqtt/pup.php and no see any data
I then tried
$mosquitto_pub -h localhost -t "/mqtt" -m "HelloWorld"
and the get
bash: -h: command not found
I don't know where the problem is, for information write in command
$mosquitto -v
1464002857: mosquitto version 1.4.8 (build date Tue, 17 May 2016 11:26:59 +0100) starting
1464002857: Using default config.
1464002857: Opening ipv4 listen socket on port 1883.
1464002857:Error: Address already in use
I also have the same problem in my windows I install mosquitto, see this link
Step by step installing and configuring Mosquitto with Windows 7 | Sharing of tech stuff[^]
I see the service for Mosquitto Broker(MQTT v3.1 broker) is runnng and check the example pub.php to testing
Mosquitto-PHP/pub.php at master · mgdm/Mosquitto-PHP · GitHub[^]
the result is error Mosquitto\Client() is not found
I searched and found mosquitto.php
mosquitto-stub/mosquitto.php at master · Nakard/mosquitto-stub · GitHub[^]
and put the I put this code in pub.php
require "mosquitto.php";
I don't know where the problem is, can any one help me to running mosquitto in my windows and raspberry.
I need to try runnig mosquitto with php and can be connected with localhost and check connection is OK or not also to subscribe and publish and reading the message
What I have tried:
require "mosquitto.php"; $client = new Mosquitto\Client(); $client->onConnect('connect'); $client->onDisconnect('disconnect'); $client->onSubscribe('subscribe'); $client->onMessage('message'); $client->connect("localhost", 1883, 5); $client->subscribe('/#', 1); while (true) { $client->loop(); $mid = $client->publish('/hello', "Hello from PHP at " . date('Y-m-d H:i:s'), 1, 0); echo "Sent message ID: {$mid}\n"; $client->loop(); sleep(2); } $client->disconnect(); unset($client); function connect($r) { echo "I got code {$r}\n"; } function subscribe() { echo "Subscribed to a topic\n"; } function message($message) { printf("Got a message ID %d on topic %s with payload:\n%s\n\n", $message->mid, $message->topic, $message->payload); } function disconnect() { echo "Disconnected cleanly\n"; }
这篇关于覆盆子和窗户中的Mosquitto-PHP库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!