Yo,
In this video, I’ll be covering how-to install, setup, and use Mosquitto MQTT broker on a Raspberry Pi. Mosquitto is an awesome open source MQTT broker that you can run on a device like a Raspberry Pi. It’s great because you don’t have to share you data to the cloud and can keep everything locally on your system. Plus, it’s free! MQTT is a great protocol for various DIY tech – like an Arduino, NodeMCU, or ESP8266 chip. If you have any questions, let me know! Happy to help with what I can!
Cheers,
Ben
— The Tech I Use —
—Favorite Parts—
Raspberry Pi 3 –
Case –
SD Card –
Power Supply –
LIFX –
Aeotec Z-Stick Gen 5 –
NodeMCU ESP8266 Chip –
—Shell Commands—
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients
sudo nano /etc/mosquitto/mosquitto.conf
allow_anonymous false
password_file /etc/mosquitto/pwfile
listener 1883
sudo mosquitto_passwd -c /etc/mosquitto/pwfile username
mosquitto_sub -d -u username -P password -t “dev/test”
mosquitto_pub -d -u username -P password -t “dev/test” -m “Hello world”
—Resources—
Mosquitto Configuration –
MQTT Home Assistant –
My Website –
Home Assistant –
HA Forum –
HA Chatroom –
HA GitHub –
Nguồn:https://dantrionline.com.vn/
Xem thêm Bài Viết:
- Tìm hiểu cổng HDMI ARC là gì và những ưu điểm vượt trội
- Góc chia sẻ: Cách đấu loa song song và nối tiếp chi tiết nhất
- Sửa lỗi a required CD/DVD drive device driver is missing hiệu quả
- Cục phát wifi là gì? Cách cài đặt wifi tenda n300 như thế nào?
- Sửa lỗi the application was unable to start correctly 0xc00007b win 8 nhanh
https://danhnhan.vn/cong-nghe
18 seconds in… Where's the link?
Love your Vids, this one helped me with my MQTT Server. But that part with the router and the port forwarding is extremly dangerous. Never ever expose Ports to the Internet if you don't have to. Actually i can't even think of a scenario to use MQTT on the internet. But MQTT is open source which means finding vulnerabilitys or zero days is a lot easier.
Also you don't remotely stress that you should use a complex password for your MQTT Server. You need it rarely so put it in a password manager and make it 30 chars long.
Someone that sets up his MQTT like in your example is gonna have a bad time.
I'd love a video about Smart Home Network Security and Password Security because it gets rarely mentioned in any Smart Home tutorial.
I'm a network security engineer. Maybe i could help?
Nice Tutorial. If anybody wants to test it's MQTT Broker then use web based MQTT Client http://mqtt.run
trying to get this done, but starting with the call (sudo apt-get install mosquitto) doesnt work on Raspbian, but i followed instructions and got it isntalled by downloading the file through github (webrowser), later on "make" and "sudo make isntall" worked, then trying to modify the config comes empty.
A great tutorial. Thank you! Theo
don't run nano (or any editor) as root unnecessarily! use sudoedit, which makes a temporary copy of the file, calls the editor (from the unprivileged account) on that copy, then copies it over the original when you exit the editor.
i have a blutooth enabled multisensor want to upload the data in raspberry pi using mqtt can you suggest the way?
when I type this in mosquitto_sub -d -u username -P password -t "dev/test"
I get this
pi@raspberrypi:~ $ mosquitto_sub -d -u username -P password -t "dev/test"
Client mosqsub|1246-raspberryp sending CONNECT
Client mosqsub|1246-raspberryp received CONNACK (0)
Client mosqsub|1246-raspberryp sending SUBSCRIBE (Mid: 1, Topic: dev/test, QoS: 0)
Client mosqsub|1246-raspberryp received SUBACK
Subscribed (mid: 1): 0
when I type this
mosquitto_pub -d -u username -P password -t "dev/test" -m "Hello world"
nothing happens
How to build mosquitto with websockets
Nice video! Please bear in mind, if you open the port of any MQTT broker to the internet from your home network, please secure it with authentication and authorization. You can read more about this here (https://www.hivemq.com/mqtt-security-fundamentals/). Otherwise it is open to anybody in the web.
Ha, I love things like this. I can't log in with putty the connection is refused. I suspect there is a long list of things I have to do before 'just logging in". Also by the time I've figured that out, I'll probably find all this is out of date as well as the RPi.
try this Web SCADA platform to create free MQTT connection to public MQTT broker: https://www.youtube.com/watch?v=u8Vm6SWnbj0
it works!!!! thank you
Hey buddy! what happened at 2:40?
Hi Ben,
Great instruction as always, but I think I am missing something. I have followed your other video that you published a year later called “Setting Up the SSH Add On – HassIO” works fine and enables access to HassIO as described. However this means that I cannot follow your instruction for installing updating using ‘sudo apt-get update’ because (as far as I can see) I do not have access to pi@raspberrypi: prompt.
I have tried a new connection in Putty without SSH connection authorisation but no luck there.
Does the SSH add-on as set up for HassIO mean I no longer have access to a ‘normal’ SSH connection?
I can’t help but think that I must be missing something basic, but any help would be greatfully received.
mqtt required in order to add sonof devices i created?
where i can find teh file configuration.yaml?
sorry if this is not allowed, but another video on here really messed this up, can you help please
pi@hassbian:~ $ sudo apt-get install mosquitto
Reading package lists… Done
Building dependency tree
Reading state information… Done
mosquitto is already the newest version (1.5.5-0mosquitto1).
0 upgraded, 0 newly installed, 0 to remove and 53 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up mosquitto (1.5.5-0mosquitto1) …
Failed to start mosquitto.service: Unit mosquitto.service is not loaded properly : Invalid argument.
See system logs and 'systemctl status mosquitto.service' for details.
invoke-rc.d: initscript mosquitto, action "start" failed.
● mosquitto.service – Mosquitto MQTT Broker daemon
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Jan 27 21:28:56 hassbian systemd[1]: [/etc/systemd/system/mosquitto.service…'='.
Jan 27 21:28:56 hassbian systemd[1]: [/etc/systemd/system/mosquitto.service…'='.
Jan 27 21:28:56 hassbian systemd[1]: [/etc/systemd/system/mosquitto.service…'='.
Hint: Some lines were ellipsized, use -l to show in full.
dpkg: error processing package mosquitto (–configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
mosquitto
E: Sub-process /usr/bin/dpkg returned an error code (1)
HI: a little problem my port :1883 does not appear on the order comand:.((C: Users > netstat )) …………End CMD mosquitto the message comes ((Error: Unable to connect because the target computer refused the connection)).
Maybe you can talk a little bit faster?
How do I set up a toggle switch on ha to send one message when toggled on and a different one when toggled off
Newbie here….. I am struggling with understanding the basic 'architecture' of running HA on a Raspberry Pi. I have one Pi and a micro SD card with Raspbian (ip address: 10.0.0.111) and a micro SD card with HA (ip address: 10.0.0.222). In my mind this means that I either run the OS Raspbian or I run HA, but when i watch the various HA video's you all use Linux (e.g. Sudo) commands while you have HA up and running. When I run HA, I can not SSH into Raspbian on my PI, I can only SSH into HA. Any hints or tips on how these two environments are integrated while the PI has the HA SD card, is very much appreciated!
Finally got past the connection refused and was successful in publishing the Hello World message to topic dev/test when sending from the pi console. When trying to publish from MQTT service in a browser it fails.
Seriously man, this is an excellent tutorial. Good job. You made me subscribe to you on this one.
You need to add the following to create file called /lib/systemd/system/mosquitto.service
Add this content to it:
[Unit]
Description=Mosquitto MQTT Broker daemon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
After=network.target
Requires=network.target
[Service]
Type=forking
RemainAfterExit=no
StartLimitInterval=0
PIDFile=/var/run/mosquitto.pid
ExecStart=/bin/sh -c "/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d"
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target
This will allow you create a service which can be enabled to start at boot with : sudo systemctl start mosquitto,
I also found that you need to modify the lines in
sudo nano /etc/mosquitto/mosquitto.conf to
allow_anonymous false
password_file /etc/mosquitto/pwfile
port 1883
after you do this reboot
May people and myself have been having issue with connection refused after rebooting. It seems running the command: mosquitto -d will fix the issue but that command needs to be run after each reboot. Therefore, my fix was to place a start up command in my LXDE file to run the mosquitto -d command upon restart / boot up. An easy single echo line command: echo "mosquitto -d" >> ~/.config/lxsession/LXDE-pi/autostart Now I have access after reboot without issue. Ben might want to add that to you commands in the description above … Good luck all.
can you tell us how to connect owntracks app to an mqtt broker and then publish the information in the form of latitudes and longitudes in google maps in another device? Please do reply 🙂 Cheers
Fantastic tutorial, works perfect first time
For those who are having issues, persist with it, because it is not this tutorial, but your own environment.
nic
good video, really helpful to setup the mosquitto with home assistant. Thanks for sharing it
Hi Ben, nice VID, like all yours, but for me "port: 1883" in configuration.yaml makes homeassistant refuse to start … also http://www.yamllint.com/ comes up with an error – any hints ? Without that line my home assistant rans well so far …
Thanks for that, helped me get going with it via openHab.
core-ssh:/# mosquitto_sub -d -u LedStrip -P LedStrip -t "dev/test"
Error: Address not available
:C Can every people help me?
If you're not able to connect, try erasing the username and password fields in the sonoff configuration menu. The default values won't work, they need to be cleared out and saved as blank (they'll fill in with '0' afterwards I think, not sure).
Hi Ben,
Need some help configuring a tasmotized WEMOS d1 mini with a ds18b20 temp sensor to talk with ha.
Everything is working, but not able to push temp values to dashboard ….. HELP!!!!!
Thanks for the video. much clearer and easier to understand than the others I found
How do I send messages from outside of the home network?
pi@raspberrypi:~ $ mosquitto_sub -d -u username -P password -t "dev/test"
Error: Connection refused
the following error coming
The following packages have unmet dependencies:
mosquitto : Depends: libssl1.0.0 (>= 1.0.1) but it is not installable
E: Unable to correct problems, you have held broken packages.
hass.io mqtt video pleases