diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-05-05 05:35:12 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-05-05 05:35:12 +0000 |
| commit | 6ff2a22372ce9e8083fae62abfaa74a9b3552795 (patch) | |
| tree | 19c906c39e597b1ee72153c9c4895a20ea0730d6 | |
| parent | c4e21dc2e6a2c0ee1a413d4c90b361f7f19efca5 (diff) | |
automatic import of python-flask-mqttopeneuler20.03
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | python-flask-mqtt.spec | 702 | ||||
| -rw-r--r-- | sources | 1 |
3 files changed, 704 insertions, 0 deletions
@@ -0,0 +1 @@ +/Flask-MQTT-1.1.1.tar.gz diff --git a/python-flask-mqtt.spec b/python-flask-mqtt.spec new file mode 100644 index 0000000..084680f --- /dev/null +++ b/python-flask-mqtt.spec @@ -0,0 +1,702 @@ +%global _empty_manifest_terminate_build 0 +Name: python-Flask-MQTT +Version: 1.1.1 +Release: 1 +Summary: Flask extension for the MQTT protocol +License: MIT +URL: https://github.com/MrLeeh/Flask-MQTT +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/aa/01/da65ea5c0fb5f5e96ddb41bd3e0b526c26edf9f09907966e0c8f2aa72c4e/Flask-MQTT-1.1.1.tar.gz +BuildArch: noarch + + +%description +# Flask-MQTT + +Flask Extension for the [MQTT protocol][1]. Basically it is a thin wrapper +around [paho-mqtt][0] and aims to simplify MQTT integration in Flask. MQTT is a +machine-to-machine "Internet of Things" protocol and was designed for extremely +lightweight publish/subscribe messaging transport. + +[](http://flask-mqtt.readthedocs.io/en/latest/?badge=latest) +[](https://badge.fury.io/py/Flask-MQTT) +[](https://travis-ci.org/stlehmann/Flask-MQTT) +[](https://coveralls.io/github/stlehmann/Flask-MQTT?branch=master) +[](https://conda.anaconda.org/conda-forge) +[](https://pepy.tech/project/flask-mqtt) +[](https://pepy.tech/project/flask-mqtt/week) + +Find the documentation on [http://flask-mqtt.readthedocs.io][2]. + +## Features + +* configuration via Flask config variables +* auto-connect on start of your web application +* publish and subscribe messages +* use callbacks for certain topics +* use one callback for all subscribed topics + +## Limitations + +Flask-MQTT was developed to provide an easy-to-setup solution for interacting +with IoT devices. A typical scenario would be a Raspberry Pi running a +mosquitto mqtt server combined with a Flask webserver. + +### Multiple workers + +**Flask-MQTT is currently not suitable for the use with multiple worker +instances.** So if you use a WSGI server like *gevent* or *gunicorn* make sure +you only have one worker instance. + +### Reloader + +Make sure to disable Flasks autoreloader. If activated it spawns two +instances of a Flask application. This leads to the same problems as multiple +workers. To prevent Flask-MQTT from running code twice it is necessary to +deactivate the automatic reloader. + +## Installation + +Simply install the package as usual via pip: + +```bash +$ pip install flask-mqtt +``` + +Or with conda from the conda-forge channel: + +```bash +$ conda config --add channels conda-forge +$ conda install flask-mqtt +``` + +## Usage + +### Basic Setup + +```python +from flask import Flask +from flask_mqtt import Mqtt + +app = Flask(__name__) +app.config['MQTT_BROKER_URL'] = 'mybroker.com' +app.config['MQTT_BROKER_PORT'] = 1883 +app.config['MQTT_USERNAME'] = 'user' +app.config['MQTT_PASSWORD'] = 'secret' +app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds +mqtt = Mqtt(app) + +@app.route('/') +def index(): + return render_template('index.html') + +``` + +### Subscribe to a topic + +To subscribe to a topic simply use `mqtt.subscribe()`. To make sure the +subscription gets handled correctly on startup place the subscription inside +an `on_connect()` callback function. + +```python +@mqtt.on_connect() +def handle_connect(client, userdata, flags, rc): + mqtt.subscribe('home/mytopic') +``` + +To handle the subscribed messages you can define a handling function by +decorating it with `@mqtt.on_message()`. + +```python +@mqtt.on_message() +def handle_mqtt_message(client, userdata, message): + data = dict( + topic=message.topic, + payload=message.payload.decode() + ) +``` + +To unsubscribe do: + +```python +mqtt.unsubscribe('home/mytopic') +``` + +Or if you want to unsubscribe all topics use `unsubscribe_all()`. + +```python +mqtt.unsubscribe_all() +``` + +### Publish + +To publish a message you can use the `publish()` method. + +```python +mqtt.publish('home/mytopic', 'this is my message') +``` + +### Small publish/subscribe MQTT client + +```python +""" + +A small Test application to show how to use Flask-MQTT. + +""" + +import eventlet +import json +from flask import Flask, render_template +from flask_mqtt import Mqtt +from flask_socketio import SocketIO +from flask_bootstrap import Bootstrap + +eventlet.monkey_patch() + +app = Flask(__name__) +app.config['SECRET'] = 'my secret key' +app.config['TEMPLATES_AUTO_RELOAD'] = True +app.config['MQTT_BROKER_URL'] = 'broker.hivemq.com' +app.config['MQTT_BROKER_PORT'] = 1883 +app.config['MQTT_USERNAME'] = '' +app.config['MQTT_PASSWORD'] = '' +app.config['MQTT_KEEPALIVE'] = 5 +app.config['MQTT_TLS_ENABLED'] = False +app.config['MQTT_CLEAN_SESSION'] = True + +# Parameters for SSL enabled +# app.config['MQTT_BROKER_PORT'] = 8883 +# app.config['MQTT_TLS_ENABLED'] = True +# app.config['MQTT_TLS_INSECURE'] = True +# app.config['MQTT_TLS_CA_CERTS'] = 'ca.crt' + +mqtt = Mqtt(app) +socketio = SocketIO(app) +bootstrap = Bootstrap(app) + + +@app.route('/') +def index(): + return render_template('index.html') + + +@socketio.on('publish') +def handle_publish(json_str): + data = json.loads(json_str) + mqtt.publish(data['topic'], data['message']) + + +@socketio.on('subscribe') +def handle_subscribe(json_str): + data = json.loads(json_str) + mqtt.subscribe(data['topic']) + + +@socketio.on('unsubscribe_all') +def handle_unsubscribe_all(): + mqtt.unsubscribe_all() + + +@mqtt.on_message() +def handle_mqtt_message(client, userdata, message): + data = dict( + topic=message.topic, + payload=message.payload.decode() + ) + socketio.emit('mqtt_message', data=data) + + +@mqtt.on_log() +def handle_logging(client, userdata, level, buf): + print(level, buf) + + +if __name__ == '__main__': + # important: Do not use reloader because this will create two Flask instances. + # Flask-MQTT only supports running with one instance + socketio.run(app, host='0.0.0.0', port=5000, use_reloader=False, debug=False) + +``` + +[0]: https://github.com/eclipse/paho.mqtt.python +[1]: http://mqtt.org/ +[2]: http://flask-mqtt.readthedocs.io/en/latest/ + +%package -n python3-Flask-MQTT +Summary: Flask extension for the MQTT protocol +Provides: python-Flask-MQTT +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-Flask-MQTT +# Flask-MQTT + +Flask Extension for the [MQTT protocol][1]. Basically it is a thin wrapper +around [paho-mqtt][0] and aims to simplify MQTT integration in Flask. MQTT is a +machine-to-machine "Internet of Things" protocol and was designed for extremely +lightweight publish/subscribe messaging transport. + +[](http://flask-mqtt.readthedocs.io/en/latest/?badge=latest) +[](https://badge.fury.io/py/Flask-MQTT) +[](https://travis-ci.org/stlehmann/Flask-MQTT) +[](https://coveralls.io/github/stlehmann/Flask-MQTT?branch=master) +[](https://conda.anaconda.org/conda-forge) +[](https://pepy.tech/project/flask-mqtt) +[](https://pepy.tech/project/flask-mqtt/week) + +Find the documentation on [http://flask-mqtt.readthedocs.io][2]. + +## Features + +* configuration via Flask config variables +* auto-connect on start of your web application +* publish and subscribe messages +* use callbacks for certain topics +* use one callback for all subscribed topics + +## Limitations + +Flask-MQTT was developed to provide an easy-to-setup solution for interacting +with IoT devices. A typical scenario would be a Raspberry Pi running a +mosquitto mqtt server combined with a Flask webserver. + +### Multiple workers + +**Flask-MQTT is currently not suitable for the use with multiple worker +instances.** So if you use a WSGI server like *gevent* or *gunicorn* make sure +you only have one worker instance. + +### Reloader + +Make sure to disable Flasks autoreloader. If activated it spawns two +instances of a Flask application. This leads to the same problems as multiple +workers. To prevent Flask-MQTT from running code twice it is necessary to +deactivate the automatic reloader. + +## Installation + +Simply install the package as usual via pip: + +```bash +$ pip install flask-mqtt +``` + +Or with conda from the conda-forge channel: + +```bash +$ conda config --add channels conda-forge +$ conda install flask-mqtt +``` + +## Usage + +### Basic Setup + +```python +from flask import Flask +from flask_mqtt import Mqtt + +app = Flask(__name__) +app.config['MQTT_BROKER_URL'] = 'mybroker.com' +app.config['MQTT_BROKER_PORT'] = 1883 +app.config['MQTT_USERNAME'] = 'user' +app.config['MQTT_PASSWORD'] = 'secret' +app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds +mqtt = Mqtt(app) + +@app.route('/') +def index(): + return render_template('index.html') + +``` + +### Subscribe to a topic + +To subscribe to a topic simply use `mqtt.subscribe()`. To make sure the +subscription gets handled correctly on startup place the subscription inside +an `on_connect()` callback function. + +```python +@mqtt.on_connect() +def handle_connect(client, userdata, flags, rc): + mqtt.subscribe('home/mytopic') +``` + +To handle the subscribed messages you can define a handling function by +decorating it with `@mqtt.on_message()`. + +```python +@mqtt.on_message() +def handle_mqtt_message(client, userdata, message): + data = dict( + topic=message.topic, + payload=message.payload.decode() + ) +``` + +To unsubscribe do: + +```python +mqtt.unsubscribe('home/mytopic') +``` + +Or if you want to unsubscribe all topics use `unsubscribe_all()`. + +```python +mqtt.unsubscribe_all() +``` + +### Publish + +To publish a message you can use the `publish()` method. + +```python +mqtt.publish('home/mytopic', 'this is my message') +``` + +### Small publish/subscribe MQTT client + +```python +""" + +A small Test application to show how to use Flask-MQTT. + +""" + +import eventlet +import json +from flask import Flask, render_template +from flask_mqtt import Mqtt +from flask_socketio import SocketIO +from flask_bootstrap import Bootstrap + +eventlet.monkey_patch() + +app = Flask(__name__) +app.config['SECRET'] = 'my secret key' +app.config['TEMPLATES_AUTO_RELOAD'] = True +app.config['MQTT_BROKER_URL'] = 'broker.hivemq.com' +app.config['MQTT_BROKER_PORT'] = 1883 +app.config['MQTT_USERNAME'] = '' +app.config['MQTT_PASSWORD'] = '' +app.config['MQTT_KEEPALIVE'] = 5 +app.config['MQTT_TLS_ENABLED'] = False +app.config['MQTT_CLEAN_SESSION'] = True + +# Parameters for SSL enabled +# app.config['MQTT_BROKER_PORT'] = 8883 +# app.config['MQTT_TLS_ENABLED'] = True +# app.config['MQTT_TLS_INSECURE'] = True +# app.config['MQTT_TLS_CA_CERTS'] = 'ca.crt' + +mqtt = Mqtt(app) +socketio = SocketIO(app) +bootstrap = Bootstrap(app) + + +@app.route('/') +def index(): + return render_template('index.html') + + +@socketio.on('publish') +def handle_publish(json_str): + data = json.loads(json_str) + mqtt.publish(data['topic'], data['message']) + + +@socketio.on('subscribe') +def handle_subscribe(json_str): + data = json.loads(json_str) + mqtt.subscribe(data['topic']) + + +@socketio.on('unsubscribe_all') +def handle_unsubscribe_all(): + mqtt.unsubscribe_all() + + +@mqtt.on_message() +def handle_mqtt_message(client, userdata, message): + data = dict( + topic=message.topic, + payload=message.payload.decode() + ) + socketio.emit('mqtt_message', data=data) + + +@mqtt.on_log() +def handle_logging(client, userdata, level, buf): + print(level, buf) + + +if __name__ == '__main__': + # important: Do not use reloader because this will create two Flask instances. + # Flask-MQTT only supports running with one instance + socketio.run(app, host='0.0.0.0', port=5000, use_reloader=False, debug=False) + +``` + +[0]: https://github.com/eclipse/paho.mqtt.python +[1]: http://mqtt.org/ +[2]: http://flask-mqtt.readthedocs.io/en/latest/ + +%package help +Summary: Development documents and examples for Flask-MQTT +Provides: python3-Flask-MQTT-doc +%description help +# Flask-MQTT + +Flask Extension for the [MQTT protocol][1]. Basically it is a thin wrapper +around [paho-mqtt][0] and aims to simplify MQTT integration in Flask. MQTT is a +machine-to-machine "Internet of Things" protocol and was designed for extremely +lightweight publish/subscribe messaging transport. + +[](http://flask-mqtt.readthedocs.io/en/latest/?badge=latest) +[](https://badge.fury.io/py/Flask-MQTT) +[](https://travis-ci.org/stlehmann/Flask-MQTT) +[](https://coveralls.io/github/stlehmann/Flask-MQTT?branch=master) +[](https://conda.anaconda.org/conda-forge) +[](https://pepy.tech/project/flask-mqtt) +[](https://pepy.tech/project/flask-mqtt/week) + +Find the documentation on [http://flask-mqtt.readthedocs.io][2]. + +## Features + +* configuration via Flask config variables +* auto-connect on start of your web application +* publish and subscribe messages +* use callbacks for certain topics +* use one callback for all subscribed topics + +## Limitations + +Flask-MQTT was developed to provide an easy-to-setup solution for interacting +with IoT devices. A typical scenario would be a Raspberry Pi running a +mosquitto mqtt server combined with a Flask webserver. + +### Multiple workers + +**Flask-MQTT is currently not suitable for the use with multiple worker +instances.** So if you use a WSGI server like *gevent* or *gunicorn* make sure +you only have one worker instance. + +### Reloader + +Make sure to disable Flasks autoreloader. If activated it spawns two +instances of a Flask application. This leads to the same problems as multiple +workers. To prevent Flask-MQTT from running code twice it is necessary to +deactivate the automatic reloader. + +## Installation + +Simply install the package as usual via pip: + +```bash +$ pip install flask-mqtt +``` + +Or with conda from the conda-forge channel: + +```bash +$ conda config --add channels conda-forge +$ conda install flask-mqtt +``` + +## Usage + +### Basic Setup + +```python +from flask import Flask +from flask_mqtt import Mqtt + +app = Flask(__name__) +app.config['MQTT_BROKER_URL'] = 'mybroker.com' +app.config['MQTT_BROKER_PORT'] = 1883 +app.config['MQTT_USERNAME'] = 'user' +app.config['MQTT_PASSWORD'] = 'secret' +app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds +mqtt = Mqtt(app) + +@app.route('/') +def index(): + return render_template('index.html') + +``` + +### Subscribe to a topic + +To subscribe to a topic simply use `mqtt.subscribe()`. To make sure the +subscription gets handled correctly on startup place the subscription inside +an `on_connect()` callback function. + +```python +@mqtt.on_connect() +def handle_connect(client, userdata, flags, rc): + mqtt.subscribe('home/mytopic') +``` + +To handle the subscribed messages you can define a handling function by +decorating it with `@mqtt.on_message()`. + +```python +@mqtt.on_message() +def handle_mqtt_message(client, userdata, message): + data = dict( + topic=message.topic, + payload=message.payload.decode() + ) +``` + +To unsubscribe do: + +```python +mqtt.unsubscribe('home/mytopic') +``` + +Or if you want to unsubscribe all topics use `unsubscribe_all()`. + +```python +mqtt.unsubscribe_all() +``` + +### Publish + +To publish a message you can use the `publish()` method. + +```python +mqtt.publish('home/mytopic', 'this is my message') +``` + +### Small publish/subscribe MQTT client + +```python +""" + +A small Test application to show how to use Flask-MQTT. + +""" + +import eventlet +import json +from flask import Flask, render_template +from flask_mqtt import Mqtt +from flask_socketio import SocketIO +from flask_bootstrap import Bootstrap + +eventlet.monkey_patch() + +app = Flask(__name__) +app.config['SECRET'] = 'my secret key' +app.config['TEMPLATES_AUTO_RELOAD'] = True +app.config['MQTT_BROKER_URL'] = 'broker.hivemq.com' +app.config['MQTT_BROKER_PORT'] = 1883 +app.config['MQTT_USERNAME'] = '' +app.config['MQTT_PASSWORD'] = '' +app.config['MQTT_KEEPALIVE'] = 5 +app.config['MQTT_TLS_ENABLED'] = False +app.config['MQTT_CLEAN_SESSION'] = True + +# Parameters for SSL enabled +# app.config['MQTT_BROKER_PORT'] = 8883 +# app.config['MQTT_TLS_ENABLED'] = True +# app.config['MQTT_TLS_INSECURE'] = True +# app.config['MQTT_TLS_CA_CERTS'] = 'ca.crt' + +mqtt = Mqtt(app) +socketio = SocketIO(app) +bootstrap = Bootstrap(app) + + +@app.route('/') +def index(): + return render_template('index.html') + + +@socketio.on('publish') +def handle_publish(json_str): + data = json.loads(json_str) + mqtt.publish(data['topic'], data['message']) + + +@socketio.on('subscribe') +def handle_subscribe(json_str): + data = json.loads(json_str) + mqtt.subscribe(data['topic']) + + +@socketio.on('unsubscribe_all') +def handle_unsubscribe_all(): + mqtt.unsubscribe_all() + + +@mqtt.on_message() +def handle_mqtt_message(client, userdata, message): + data = dict( + topic=message.topic, + payload=message.payload.decode() + ) + socketio.emit('mqtt_message', data=data) + + +@mqtt.on_log() +def handle_logging(client, userdata, level, buf): + print(level, buf) + + +if __name__ == '__main__': + # important: Do not use reloader because this will create two Flask instances. + # Flask-MQTT only supports running with one instance + socketio.run(app, host='0.0.0.0', port=5000, use_reloader=False, debug=False) + +``` + +[0]: https://github.com/eclipse/paho.mqtt.python +[1]: http://mqtt.org/ +[2]: http://flask-mqtt.readthedocs.io/en/latest/ + +%prep +%autosetup -n Flask-MQTT-1.1.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-Flask-MQTT -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Fri May 05 2023 Python_Bot <Python_Bot@openeuler.org> - 1.1.1-1 +- Package Spec generated @@ -0,0 +1 @@ +383028565cc2ae0d232af7411bab62f7 Flask-MQTT-1.1.1.tar.gz |
