https://github.com/natlee/mqtt-subscriber-and-publisher
Example for MQTT include client of publisher and background subscriber by using Python3!
https://github.com/natlee/mqtt-subscriber-and-publisher
beginner-code example iot mqtt mqtt-broker mqtt-client publisher python python3 subscriber
Last synced: 7 months ago
JSON representation
Example for MQTT include client of publisher and background subscriber by using Python3!
- Host: GitHub
- URL: https://github.com/natlee/mqtt-subscriber-and-publisher
- Owner: NatLee
- License: mit
- Created: 2020-01-20T06:38:23.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-03T02:13:01.000Z (over 5 years ago)
- Last Synced: 2025-01-21T20:48:43.087Z (9 months ago)
- Topics: beginner-code, example, iot, mqtt, mqtt-broker, mqtt-client, publisher, python, python3, subscriber
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MQTT Subscriber and Sender Example
Here's an example for MQTT subscriber and sender.
## Introduction
The MQTT protocol is very simple, which is very suitable for IoT devices with limited processor resources and limited network bandwidth.
## Requirements
- paho-mqtt
## Usage
First, make a subscriber.
You can change the topics and MQTT server address(a.k.a MQTT Broker) in the program.
The default is official server `test.mosquitto.org` with default port `1883`.
```bash
python3 example_subscriber.py
```And, we can try sender(a.k.a publisher) to send messages.
The messages can be any format like `JSON`, `list`, `Numpy Array` and so on cause `Sender` will change the data you send to be **binary object** in the backend by using pickle package.
When the message is sent, all users with subscription related items can receive the message.
```bash
python3 example_sender.py
```## Result
* Subscriber
```
Connected with result code 0
yee {'test1': 1234, 'test2': 'yee'}
yoo 1234
yoo b'ABCDEFG'
yoo ['1', 'a', 'b']
```