HI
I 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";
}