Coder Social home page Coder Social logo

naztronaut / ep-mqtt Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 4.0 235 KB

Home Page: https://www.easyprogramming.net/raspberrypi/python_mqtt_setup.php

License: MIT License

Python 100.00%
mosquitto mqtt python raspberry-pi home-automation mqtt-service

ep-mqtt's Introduction

EP MQTT Setup

Python MQTT Thumbnail

Install Mosquitto

Run the following commands to install install mosquitto:

sudo apt install -y mosquitto mosquitto-clients

Make sure mosquitto service is enabled:

sudo systemctl enable mosquitto.service

Check of mosquitto is running:

ps -ef | grep mosquitto

Run mosquitto as a daemon:

mosquitto -d

Install Paho-Mqtt Python Library

Install paho-mqtt:

sudo pip3 install paho-mqtt

Set up mqtt_subscriber.py as a service

Get the mqtt_subscriber.py script from this repo and place it anywhere on your server.

Move the MQTT Subscriber service and run it:

sudo cp mqtt_subscriber.service /etc/systemd/system

Reload systemctl and turn it on:

sudo systemctl daemon-reload
sudo systemctl enable mqtt_subscriber.service
sudo service mqtt_subscriber start

To see if it's running:

service mqtt_subscriber/status

Set up authentication for your Mosquitto broker

Method 1: Create a password file manually:

nano password_file

Add your credentials:

username:password

Substitute username for your username and password for your password.

Encrypt the file:

sudo mosquitto_passwd -U password_file

Method 2: Create password file via CLI

Run command:

sudo mosquitto_passwd -c password_file username

Substitute username for your username and password for your password.

Mosquitto Configuration

Move the newly created password_file to its proper location:

sudo mv password_file /etc/mosquitto

Edit the configuration file:

cd /etc/mosquitto 
sudo nano mosquitto.conf

Add the two following lines at the end:

allow_anonymous false
password_file /etc/mosquitto/password_file

Also be sure to look at the mosquitto.conf file in this repo for a full example.

Restart mosquitto service:

sudo service mosquitto restart

ep-mqtt's People

Contributors

naztronaut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.