DirkS
Posts: 10088
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Getting Mosquitto to work on Raspberry Pi

Tue Feb 02, 2016 11:49 am

Johu wrote:Can I forbidden the broker launch after boot?
On Wheezy try

Code: Select all

sudo update-rc.d mosquitto disable

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Mon May 23, 2016 2:19 pm

I install PHP client for MQTT using Mosquitto-PHP
http://wingsquare.com/blog/developing-p ... p-library/

after that create pub.php in /var/www/html/mqtt when write in browser http://210.201.4.113/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 don't know where the problem is, can any one help me to running mosquitto in raspberry.

I need to try mqtt connected with localhost and check connection is OK or not also to subscribe and publish and reading the message

DirkS
Posts: 10088
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Getting Mosquitto to work on Raspberry Pi

Mon May 23, 2016 2:27 pm

hasan hadi wrote:I then tried

$mosquitto_pub -h localhost -t "/mqtt" -m "HelloWorld"

and the get

bash: -h: command not found
Did you install mosquitto-clients?

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 2:56 am

DirkS wrote:
hasan hadi wrote:I then tried

$mosquitto_pub -h localhost -t "/mqtt" -m "HelloWorld"

and the get

bash: -h: command not found
Did you install mosquitto-clients?
I only install this information

Code: Select all

sudo apt-get install php-pear

Code: Select all

sudo apt-get install php5-dev

Code: Select all

sudo apt-get install Mosquitto-alpha
after that display this
Please provide the prefix of the libmosquitto installation [autodetect] :
and press inter to continous

Code: Select all

sudo apt-get install libmosquitto

Code: Select all

sudo apt-get install libmosquitto-dev
and add the extension=mosquitto.so after Dynamic Extensions in file etc/php5/cli/php.ini

DirkS
Posts: 10088
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 4:31 am

The program 'mosquitto_pub' is part of the package 'mosquitto-clients'
So in order to use it you will have to install that package.

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 8:25 am

DirkS wrote:The program 'mosquitto_pub' is part of the package 'mosquitto-clients'
So in order to use it you will have to install that package.
please how install mosquitto-clients and how test it

Iam using php and server Apache and store my server in /var/www/html and need using mosquitto to connected with local host and publish and subscribe any message

I am using this code for testing
https://github.com/mgdm/Mosquitto-PHP/b ... es/pub.php

the problem now I don't know how can running the mosquitto because Iam new for using raspberry and mosquitto


DirkS
Posts: 10088
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 8:44 am

hasan hadi wrote:can be using this information

https://rasspberrypi.wordpress.com/2012 ... be-client/
That stuff is ancient.
If you want to install mosquitto daemon / mosquitto-clients use http://mosquitto.org/2013/01/mosquitto- ... epository/

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 1:41 pm

DirkS wrote:
hasan hadi wrote:can be using this information

https://rasspberrypi.wordpress.com/2012 ... be-client/
That stuff is ancient.
If you want to install mosquitto daemon / mosquitto-clients use http://mosquitto.org/2013/01/mosquitto- ... epository/
I install all commands in

http://mosquitto.org/2013/01/mosquitto- ... epository/

also install mosquitto-clients

Code: Select all

sudo apt-get install mosquitto-clients
and the same problem

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 1:53 pm

I write this command

Code: Select all

 sudo  apt-cache showpkg mosquitto
the result


[email protected]:~ $ sudo apt-cache showpkg mosquitto
Package: mosquitto
Versions:
1.4.8-0mosquitto2 (/var/lib/apt/lists/repo.mosquitto.org_debian_dists_jessie_main_binary-armhf_Packages) (/var/lib/dpkg/status)
Description Language:
File: /var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages
MD5: 307c8e6f529318d6f3294b62a053c404

1.3.4-2 (/var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages)
Description Language:
File: /var/lib/apt/lists/mirrordirector.raspbian.org_raspbian_dists_jessie_main_binary-armhf_Packages
MD5: 307c8e6f529318d6f3294b62a053c404


Reverse Depends:
mosquitto-dbg,mosquitto 1.4.8-0mosquitto2
mosquitto-dbg,mosquitto 1.3.4-2
Dependencies:
1.4.8-0mosquitto2 - adduser (2 3.10) libuuid1 (2 2.16) lsb-base (2 4.1+Debian3) libc6 (2 2.4) libssl1.0.0 (2 1.0.1) libwebsockets3 (2 1.2) libwrap0 (2 7.6-4~) apparmor (0 (null))
1.3.4-2 - libc6 (2 2.4) libssl1.0.0 (2 1.0.1) libwrap0 (2 7.6-4~) adduser (2 3.10) lsb-base (2 4.1+Debian3) libuuid1 (0 (null))
Provides:
1.4.8-0mosquitto2 -
1.3.4-2 -
Reverse Provides:

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 2:22 pm

in this link
https://rasspberrypi.wordpress.com/2012 ... be-client/
I see this commands

Code: Select all

$ mosquitto_sub -d -t hello/world
and

Code: Select all

$ mosquitto_pub -d -t hello/world -m "Message To Send"
this is work with me
also this commands

Code: Select all

$ mosquitto_sub -h 192.168.1.2 -d -t hello/world

Code: Select all

$ mosquitto_pub -h 192.168.1.2 -d -t hello/world -m "Message To Send"
is work
see result

[email protected]:~ $ mosquitto_pub -h 210.201.4.114 -d -t hello/world -m "Message To Send"
Client mosqpub/1800-raspberryp sending CONNECT
Client mosqpub/1800-raspberryp received CONNACK
Client mosqpub/1800-raspberryp sending PUBLISH (d0, q0, r0, m1, 'hello/world', ... (15 bytes))
Client mosqpub/1800-raspberryp sending DISCONNECT

================================================
[email protected]:~ $ mosquitto_sub -h 210.201.4.114 -d -t hello/world
Client mosqsub/1796-raspberryp sending CONNECT
Client mosqsub/1796-raspberryp received CONNACK
Client mosqsub/1796-raspberryp sending SUBSCRIBE (Mid: 1, Topic: hello/world, QoS: 0)
Client mosqsub/1796-raspberryp received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/1796-raspberryp sending PINGREQ
Client mosqsub/1796-raspberryp received PINGRESP
Client mosqsub/1796-raspberryp sending PINGREQ
Client mosqsub/1796-raspberryp received PINGRESP
Client mosqsub/1796-raspberryp received PUBLISH (d0, q0, r0, m0, 'hello/world', ... (15 bytes))
Message To Send
Client mosqsub/1796-raspberryp sending PINGREQ
Client mosqsub/1796-raspberryp received PINGRESP
=======================================================================

hasan hadi
Posts: 22
Joined: Thu May 19, 2016 7:18 am

Re: Getting Mosquitto to work on Raspberry Pi

Tue May 24, 2016 2:40 pm

Now I need test this code how can doing it
I put sub.php & pub.php in /var/www/html
sub.php

Code: Select all

<?php
 
$client = new Mosquitto\Client();
$client->onConnect('connect');
$client->onDisconnect('disconnect');
$client->onSubscribe('subscribe');
$client->onMessage('message');
$client->connect("localhost", 1883, 60);
$client->subscribe('/#', 1);
 
 
while (true) {
        $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("\nGot a message on topic %s with payload:%s", 
                $message->topic, $message->payload);
}
 
function disconnect() {
        echo "Disconnected cleanly\n";
}
pub.php

Code: Select all

<?php
 
$client = new Mosquitto\Client();
$client->onConnect('connect');
$client->onDisconnect('disconnect');
$client->onPublish('publish');
$client->connect("localhost", 1883, 5);
 
while (true) {
        try{
                $client->loop();
                $mid = $client->publish('/mqtt', "Hello from PHP");
                $client->loop();
        }catch(Mosquitto\Exception $e){
                return;
        }
        sleep(2);
}
 
$client->disconnect();
unset($client);
 
function connect($r) {
        echo "I got code {$r}\n";
}
 
function publish() {
        global $client;
        echo "Mesage published\n";
        $client->disconnect();
}
 
function disconnect() {
        echo "Disconnected cleanly\n";
}

I write this command
[email protected]:/var/www/html/t $ php pub.php

the result
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20131226/mosquitto.so' - /usr/lib/php5/20131226/mosquitto.so: cannot open shared object file: No such file or directory in Unknown on line 0 PHP Fatal error: Class 'Mosquitto\Client' not found in /var/www/html/t/pub.php on line 3

jsaldivias
Posts: 13
Joined: Mon Mar 06, 2017 8:49 pm

Re: Getting Mosquitto to work on Raspberry Pi

Tue Jan 02, 2018 1:15 pm

DougieLawson wrote:
Fri Jan 23, 2015 8:06 am
Ignore Fruity, ....
Dear Dougie Lawson.
I pigtail on this answering of yours to ask a question.
I have installed mosquitto as a broker in my RPi. It is working fine. I am reading and writing on in from 2 different places. From my desktop using windows. And from my RPi using Raspbian.
The only thing is that I have to start manually every time. And I would like to do it at startup automatically. Presently I am using
sudo /etc/init.d/mosquitto start
And when I do it, everything is ok. Please point me in the direction to solve this.
Thanks for your help.


User avatar
DougieLawson
Posts: 36850
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Getting Mosquitto to work on Raspberry Pi

Tue Jan 02, 2018 4:32 pm

When I installed mosquitto it added a sysvinit file /etc/init.d/mosquitto

To get that running at boot use sudo update-rc.d mosquitto defaults; sudo update-rc.d mosquitto enable that will generate the systemd compatibilty files to get it running at boot time.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Troubleshooting”