Giter VIP home page Giter VIP logo

mqtt-chat's Introduction

MQTT-Chat

A small MQTT based chat application

A project of mine to play with MQTT in python. Idea is to set up a small protocol and client to enable chatting in a chatroom based approach.

WhyMQTT

MQTT is most likely not the most sensible choice for implementing a chat. The point of the project in to play around with MQTT though.

How to start the MQTT Broker

Arch Linux

After installing the mosquitto package simply run:

mosquitto -c mosquitto.conf

This should start a MQTT-Broker running on the default port 1883.
The broker is configured to only accept connections from the user "Test" with the passworrd "test" and the user "Server" with the password "admin". Additionally this "Test" user is only allowed to read or write on the topic "test/" and all ist sub topics.
You can manually interact with your new broker:

mosquitto_sub -h localhost -t test/ -u Test -P test
The topic for testing is aptly named test/.

mosquitto_pub -h localhost -t test/ -u Test -P test -m "Hello World"
Publishes the message "Hello World" to the test/ topic. The message should now be recieved by the subscribed listener from above.

If you subscribe to a topic you do not have read access to you wont get a error you just wont get any messages.

For the RoboLab workshop the test user has the Username "chat" with password "chat" and access to topics starting with "chat". The broker is hosted on mothership.inf.tu-dresden.de .

How to start the application

Make sure you have the paho-mqtt and json python packages installed.
To read the chat you have to start the listener.py.
In order to send messages you have to start the publisher.py.

Both programs allow for a host, topic and a username to be specified.

About the chat protocol

MQTT allows us to transfer a payload. This Payload has to be a byte array like type. Internally the payload is represented as a python dictionary. This dictionary has to be converted in order to be transmitted. In this Project JSON is used for that purpose, since the json.dumps() and json.loads() methods from the json package for python allow for easy conversion.

The messages have multiple fields:

"type": Either "message" or "notice"
"from": Username of the author
"message": Only present if "type" is "message", contains the message string
"notice": Only present if "type" is "info", contains a string description

Misc

Documentation of the paho mqtt library for python [https://www.eclipse.org/paho/clients/python/docs/#client]

mqtt-chat's People

Contributors

simonbirkenheuer avatar

Stargazers

Dicelus Hantz Wydrosky avatar

Watchers

James Cloos 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.