Giter VIP home page Giter VIP logo

mosquitto-python-example's Introduction

Minor example using MQTT and Python.

Requirements

Requires Mosquitto to be installed.

On Linux with the apt-get package manager:

sudo apt-get install mosquitto
sudo apt-get install mosquitto-clients

Note: mosquitto-clients is to get the mosquitto_pub to make it simple to try stuff from the command line. You could leave it out and only use the supplied publisher.py.

Also install virtualenv if you want to use it (recommended):

sudo apt-get install python-virtualenv

Setup

The use of virtualenv is optional but recommended for playing around with this example code.

Simply clone this repo, setup virtualenv and use pip to install requirements.

git clone https://github.com/roppert/mosquitto-python-example.git
cd mqtt-mosquitto-example
virtualenv .
source bin/activate
pip install -r requirements.txt

Test the subscriber example

First start the subscriber which will enter a loop waiting for new messages:

./subscriber.py

Then open a new terminal and send a message:

mosquitto_pub -d -h localhost -q 0 -t adult/pics -m "can i haz moar kittenz"

This should generate a message in the terminal running the subscriber.

Take a look at publisher.py to see how to publish messages using python. Or just open another terminal and run it from command line while subscriber.py is running:

source bin/activate
./publisher.py

Configure SSL/TLS

See mosquitto-tls on how to generate certificates and keys.

Once created you need to adjust /etc/mosquitto/mosquitto.conf and subscriber.py accordingly and then use mosquitto_pub with cert and key:

mosquitto_pub -d -h localhost --cafile root.ca --cert c1.crt --key c1.key -q 0 -t adult/pics -m "can i haz moar kittenz"

References

mosquitto-python-example's People

Contributors

roppert avatar

Watchers

 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.