pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

MQTT PUB AND SUB

Mon Aug 14, 2017 6:47 am

hello all,
i am using raspbian and installed mosquitto broker and client in it. it publishes and subscribes message through local network only. if i try to connect to other network it shows error like no route to host. how to send data to other network from my pi 3.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Mon Aug 14, 2017 12:08 pm

You need to ensure you have normal connectivity. Can you ssh from one Raspberry to the other (assuming they are on the same LAN). If the remote Raspberry is on a seperate network you'll need to use SSL communication for Mosquitto (port 8883) and open that through your firewall.

To test networking use
ifconfig -a
ip route
ping -c3 $(ip route | awk '/default/ {print $3}')
ping -c3 8.8.8.8
ping -c3 google.com
cat /etc/resolv.conf
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Wed Aug 16, 2017 7:46 am

thanks for the help. i try to send some data from my pi3 to other network , all network connection are ok. but in that ip it is not connecting at all. how to connect and send data to other network.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Wed Aug 16, 2017 12:58 pm

On the connect use the hostname, FQDN or fixed IPaddress of the remote server.

mosquitto_pub -h test.mosquitto.org -t "foo/bar" -m "message payload"
mosquitto_pub -h 192.168.3.14 -t "raspberry/pi" -m "LAN based machine"
mosquitto_pub -h raspberry.local -t "fully/qualified/local/domain" -m "works with names to"



http://www.steves-internet-guide.com/cl ... thon-mqtt/
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Thu Aug 17, 2017 7:39 am

thanks dougie for ur information, data is sent to the server successfully. but i opened the server but not able to see my data.

sometimes it fires some error not connecting to the server properly . this is the type of error i faced
1.mosquitto_sub -h 192.168.3.14 -t "raspberry/pi"
Error: Connection timed out

2.mosquitto_sub -h raspberry.local -t "fully/qualified/local/domain"
Unable to connect (Lookup error.).

how to solve the issue, all network connections are ok i check.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Thu Aug 17, 2017 12:56 pm

Is your mosquitto at 192.168.3.14 running and listening on port 1883 (or ssl port 8883)?

Take a look with sudo netstat -tlnp | grep mosq

To get addressing with a domain name working you either need to run bind9, dnsmasq or avahi-daemon.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Thu Aug 17, 2017 1:17 pm

yes i ping with that ip but it not responding.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Fri Aug 18, 2017 3:01 am

Ping is an ICMP packet, that simply proves the hardware and ICMP/IP works. You need to prove that TCP/IP to port 1883 works. So the first test is that your Mosquitto server is listening for inbound connections.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Fri Aug 18, 2017 8:00 am

got the response like this

tcp 0 0 0.0.0.0:1883 0.0.0.0:* LISTEN 566/mosquitto
tcp6 0 0 :::1883 :::* LISTEN 566/mosquitto

looks like it working.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Fri Aug 18, 2017 2:19 pm

So try this:

mosquitto_sub -v -t "#" -h "127.0.0.1" &
mosquitto_pub -h 192.168.3.14 -t "test/me" -m "$(date)"
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Sat Aug 19, 2017 6:27 am

Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.
Connection Refused: not authorised.

no connection to the other network failures.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Sun Aug 20, 2017 2:11 am

What's in /etc/mosquitto/mosquitto.conf and in /etc/mosquitto/conf.d/*.conf?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Mon Aug 21, 2017 6:25 am

it saved total configuration log, error, connection details of mosquitto.
dougie just tell me i have one pi3 raspbian os and mosquitto as broker installed . so i try to send data from my pi to other system . what r the procedure should i follow. i have write some c code in geany. if u have some reference of c examples code then u can share with me. because previous all the steps working but somehow network connection failures. so please suggest what is best for this project.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Mon Aug 21, 2017 2:23 pm

I don't use Geany.

Here's my mosquitto.conf

Code: Select all

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d
and /etc/mosquitto/conf.d/ws.conf

Code: Select all

listener 1883
protocol mqtt

listener 9001
protocol websockets
That works with every pub/sub client I've tried in python or C.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Tue Aug 22, 2017 11:18 am

my mosquitto.conf file looks like this:
almost same as urs,

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

persistence_file mosquitto.db
log_dest syslog
log_dest stdout

log_dest topic

log_type error
log_type warning
log_type notice
log_type information

connection_messages true
log_timestamp true

include_dir /etc/mosquitto/conf.d
allow_anonymous false
password_file /etc/mosquitto/pwfile


i just typed ur portion of file but same result time out and no connection.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Tue Aug 22, 2017 12:42 pm

Mine are not a portion, that's it everything. All other configurable options are left to default.

What version of Mosquitto are you running?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Tue Aug 22, 2017 12:44 pm

so what is the main problem for connection. version 1.14.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Tue Aug 22, 2017 12:57 pm

Is networking working? Can you ping the pi from other machines on your network? Can you ssh into it?

Is mosquitto listening?
sudo netstat -tlnp | grep mosq
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Tue Aug 22, 2017 1:20 pm

local network its working not on other network. command also not working. do u have any c code example for this.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Wed Aug 23, 2017 1:27 am

pieuser wrote:
Tue Aug 22, 2017 1:20 pm
local network its working not on other network. command also not working.
What does that mean?
pieuser wrote:
Tue Aug 22, 2017 1:20 pm
do u have any c code example for this.
Nothing I've written is shareable (because I can't remember if it works or still needs some hacking).

There's lots of stuff here: https://github.com/mqtt/mqtt.github.io/wiki/libraries
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Wed Aug 23, 2017 10:27 am

but program i got that running in local network only , but for other network or ip when i gave it not responds at all.
another problem is my my ip and my etho ip what i have saved in /etc/network/interface not same . what ever i saved or changed in that file no effect on pi ip address. its not saved . i think that may be a problem ,is this ?

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Thu Aug 24, 2017 11:05 am

is there any solution for /etc/network/interface file and /etc/dhcpcd/dhcpcd.conf file , how to save the info in the file.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: MQTT PUB AND SUB

Thu Aug 24, 2017 11:18 am

Use sudo vi ... or sudo nano ... or open a root shell with sudo -s
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Thu Aug 24, 2017 11:24 am

no it saved but ip not change at all.

pieuser
Posts: 38
Joined: Sat Jun 03, 2017 7:56 am

Re: MQTT PUB AND SUB

Thu Aug 24, 2017 11:33 am

but program i got that running in local network only , but for other network or ip when i gave it not responds at all.
another problem is my my ip and my etho ip what i have saved in /etc/network/interface not same . what ever i saved or changed in that file no effect on pi ip address. its not saved . i think that may be a problem ,is this ?

Return to “Beginners”