altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

MQTT without internet

Thu Aug 22, 2019 1:20 pm

Hello guys, i want to make ROV with 2 raspberry pi, one on underwater one on above water, and communication between two RPİ based on TCP/IP. Can i use MQTT for this communication? I think i can add one more RPİ as a MQTT broker and i can use but cant decide. Can you guys help?

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: MQTT without internet

Thu Aug 22, 2019 1:29 pm

Yes - assuming your connecting the two using CAT ethernet cable, then you can just run a broker on one of them and use MQTT to pass data back and forth

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

Re: MQTT without internet

Thu Aug 22, 2019 1:36 pm

It only needs an IP network as it uses TCP/IP for comms between the subscriber or publisher and the broker. An IP network doesn't mean you need the public internet. Two devices and one ethernet cable makes a network.

I'd give the RPi a fixed IP address (172.31.4.159) and run dnsmasq (with a DHCP pool from 172.31.4.10 for five addresses) so that any device that connects to the RPi can find it on the network.

/etc/dnsmasq.conf

Code: Select all

interface=eth0
no-dhcp-interface=wlan0
dhcp-range=interface:eth0,172.31.4.10,172.31.4.14,86400
/etc/dhcpcd.conf

Code: Select all

#interface eth0
static ip_address=172.31.4.159/24
static routers=172.31.4.159
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.

hippy
Posts: 5935
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: MQTT without internet

Thu Aug 22, 2019 2:55 pm

mattmiller wrote:
Thu Aug 22, 2019 1:29 pm
Yes - assuming your connecting the two using CAT ethernet cable
It should also work across a three-wire serial link with PPP configured at both ends.

altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

Re: MQTT without internet

Fri Aug 23, 2019 11:41 am

mattmiller wrote:
Thu Aug 22, 2019 1:29 pm
Yes - assuming your connecting the two using CAT ethernet cable, then you can just run a broker on one of them and use MQTT to pass data back and forth
Can broker behave like a publisher at the same time? I think 3 RPİ should be connected with 2 ethernet cable. Am i right?

altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

Re: MQTT without internet

Fri Aug 23, 2019 11:43 am

DougieLawson wrote:
Thu Aug 22, 2019 1:36 pm
It only needs an IP network as it uses TCP/IP for comms between the subscriber or publisher and the broker. An IP network doesn't mean you need the public internet. Two devices and one ethernet cable makes a network.

I'd give the RPi a fixed IP address (172.31.4.159) and run dnsmasq (with a DHCP pool from 172.31.4.10 for five addresses) so that any device that connects to the RPi can find it on the network.

/etc/dnsmasq.conf

Code: Select all

interface=eth0
no-dhcp-interface=wlan0
dhcp-range=interface:eth0,172.31.4.10,172.31.4.14,86400
/etc/dhcpcd.conf

Code: Select all

#interface eth0
static ip_address=172.31.4.159/24
static routers=172.31.4.159
I get your idea. But i didnt understand how to do this. Is there any tutorial, or can you share with me?

Andyroo
Posts: 4465
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: MQTT without internet

Fri Aug 23, 2019 1:07 pm

The simplest way would be just to set each Pi up with a static IP address in /etc/dhcpcd.conf as per DougieLawsons example above.

Set one Pi to .159 and the other to .160 and only use these two addresses in programs / config. It’s not as neat as above (for example any new computer on this network would need to be manually allocated) but if it’s a closed network (i.e. just the two computers mentioned) then it’s fine.
Need Pi spray - these things are breeding in my house...

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: MQTT without internet

Fri Aug 23, 2019 2:40 pm

Can broker behave like a publisher at the same time?
The broker is just a running program on one of the machines. Each machine listens and publishes messages to the broker - even the one the broker is running on. The broker does all the message routing
I think 3 RPİ should be connected with 2 ethernet cable. Am i right?
Yep - but you'll also need an ethernet switch to connect them up

Andyroo
Posts: 4465
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: MQTT without internet

Fri Aug 23, 2019 3:26 pm

mattmiller wrote:
Fri Aug 23, 2019 2:40 pm
...
Yep - but you'll also need an ethernet switch to connect them up
Not convinced a switch is needed - I’ve connected Pi boards to Mac directly as the Pi handles swap-over Ethernet fine. Any specific reason a switch would be needed? To be fair - I’ve not tried Pi to Pi only Pi to other...
Need Pi spray - these things are breeding in my house...

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: MQTT without internet

Fri Aug 23, 2019 3:32 pm

Not convinced a switch is needed
I think 3 RPİ should be connected with 2 ethernet cable. Am i right?

:)

Andyroo
Posts: 4465
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: MQTT without internet

Fri Aug 23, 2019 3:40 pm

mattmiller wrote:
Fri Aug 23, 2019 3:32 pm
Not convinced a switch is needed
I think 3 RPİ should be connected with 2 ethernet cable. Am i right?

:)
Good point - I would just use one long one :lol:
Need Pi spray - these things are breeding in my house...

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

Re: MQTT without internet

Fri Aug 23, 2019 4:16 pm

A switch isn't needed with two stations. But a five port ethernet switch costs a tenner (aka a Jane Austen). You can even get a gigabit switch for two Janes or four Winstons.
https://www.amazon.co.uk/NETGEAR-Gigabi ... B0000E5SEQ

If you use my dnsmasq configuration then plugging a laptop into the five port switch gets a DHCP address assigned and you know the master RPi is 172.31.4.159 so can find it easily. Once you've reached the master then it's trivial to find any other device connected to the switch.

Tutorial time for the OP:
sudo apt install dnsmasq
sudo nano /etc/dnsmasq.conf
sudo systemctl restart dnsmasq
sudo nano /etc/dhcpcd.conf
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.

altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

Re: MQTT without internet

Tue Aug 27, 2019 7:02 am

I think there is one missing point. I have two RPis, one on underwater, one on above water. I make communication with wire them with ethernet cable. I use pure tcp to connection, communication (socket module in python). But it is hard because i should make my program multithreaded, i should make stream parsing vs. vs. but if i add one more RPi to system as a broker, i can set it as MQTT broker and it will be solve my problems. If i connect RPis with ethernet cable, i get static ip. What should i do?

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: MQTT without internet

Tue Aug 27, 2019 8:38 am

but if i add one more RPi to system as a broker,
There is no need to add a 3rd Pi - the mosquitto broker can run on either of your two Pi and both Pi can use it to send/receive messages to each other.

altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

Re: MQTT without internet

Tue Aug 27, 2019 11:37 am

Thanks, i set my Raspberry Pi as a broker and i made communication from localhost. Now i will try one RPi to another RPi. But when i searching on the internet, i cant see continous data transfer. Is there any example?

mattmiller
Posts: 2106
Joined: Thu Feb 05, 2015 11:25 pm

Re: MQTT without internet

Tue Aug 27, 2019 12:21 pm

MQTT is not a continuous protocol - it is for passing discrete messages

altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

Re: MQTT without internet

Tue Aug 27, 2019 2:23 pm

mattmiller wrote:
Tue Aug 27, 2019 12:21 pm
MQTT is not a continuous protocol - it is for passing discrete messages
For continuous i mean; i want to send instant data, for example turn right, from one RPi to another RPi. But i want to do it continuously. For example with one RPi with joystick, i want to send this joystick values to the other RPi for controlling motors. Can i do that with MQTT?

altanhaligur
Posts: 38
Joined: Mon Jul 08, 2019 6:54 am

Re: MQTT without internet

Tue Aug 27, 2019 2:24 pm

mattmiller wrote:
Tue Aug 27, 2019 12:21 pm
MQTT is not a continuous protocol - it is for passing discrete messages
For example you can take GPS data continuously with MQTT, am i wrong?

PhatFil
Posts: 1363
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: MQTT without internet

Tue Aug 27, 2019 3:58 pm

you can only read new data to which you subscribe as and when its published. Mqtt brokers can be configured to retain payloads but that will just provide the last data published. You could publish on demand by responding to a Request mqtt publication but thats counter intuitive to how the protocol is designed and would double+ any lag.

so if you have something publishing gps data every 10 seconds you can only read new values after its published every 10 seconds.

there can be a lag in data transmission/receipt using mqtt depending on numerous factors such as how busy the broker is and wifi/network reliability. if its significant enough to be an issue for your needs its probably simplest to test it, write a script to publish on the minute every minute and record/display when your subscribing process receives the messages.
if using 2 seperate puters sync the time in advance..
http://www.steves-internet-guide.com/in ... on-client/
https://www.programiz.com/python-progra ... rrent-time

the lag involved in publication and subscription will be evident, I use mqtt to control lighting there is an occasional detectable lag but its hardly noticeable and infrequent to be of consequence for lighting control.

Return to “Networking and servers”