Control LED using MQTT on Raspberry Pi

preview_player
Показать описание
Simple tutorial on how to implement Python MQTT client to handle MQTT payload (messages) and use them to control an LED.

We are using GPIOZERO library in this tutorial. Make sure you have pre-installed that library.

To install Python 3 library:
sudo apt-get install python3-gpiozero

To install Python 2 library:
sudo apt-get install python-gpiozero

To install PAHO MQTT client on Raspberry Pi:
sudo pip install paho-mqtt

Song: Ship Wrek, Zookeepers & Trauzers - Vessel [NCS Release]
Music provided by NoCopyrightSounds.
Рекомендации по теме
Комментарии
Автор

Hi Yazid,
Broker receives connection and is sending CONNACK but client is not printing "Connected with result code X", what could be the cause?
Broker is mosquitto 1.6.9

willemjacobusblom
Автор

Hi. Very nice tutorial. Would you know how to integrate mqtt messages and sensor read from same script please?

mateuszszalkowski
Автор

The installation command is giving the following exception:
In my Raspberry the time is correct:
I installed the Mosquitto.

I already executed the sequence below:
Sudo apt-get update
Sudo apt-get upgrade
Sudo apt-get install python-pip python-flask
Sudo pip install flask
Sudo pip install paho-mqtt

And it gives the following exception:

Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    Status = self.run (options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 290, in run
(finder, force_root_egg_info = self.bundle, bundle = self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1178, in prepare_files
    Url = finder.find_requirement (req_to_install, upgrade = self.upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 194, in find_requirement
    Page = self._get_page (main_index_url, req)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 568, in _get_page
    Session = self.session,
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 694, in get_page
    Req, link, "connection error:% s"% exc, url,
TypeError: __str__ returned non-string (type Error)

Storing debug log for failure in /root/.pip/pip.log

LuizChequini
visit shbcf.ru