Skip to content
Snippets Groups Projects
Commit 08af1bfa authored by Matthias Stefan Bodenbenner's avatar Matthias Stefan Bodenbenner
Browse files

added publishing on PyPI

parent 226f017d
Branches
No related tags found
No related merge requests found
......@@ -16,8 +16,8 @@ Build Wheel:
- legacy
script:
- pip install -r requirements.txt
- python setup.py sdist bdist_wheel
#
- python build
Push Wheel to Package Registry:
image: python:3.9
tags:
......@@ -32,6 +32,20 @@ Push Wheel to Package Registry:
- pip install twine
- python -m twine upload -u gitlab-ci-token -p $CI_JOB_TOKEN --verbose --repository-url https://git-ce.rwth-aachen.de/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/*
Publish on PyPI:
image: python:3.9
tags:
- frodo
stage: push
artifacts:
paths:
- dist/*
only:
- master
script:
- pip install twine
- python -m twine upload -u __token__ -p $PyPIToken dist/*
pages:
image: python:3.9
stage: deploy
......
include PyPI-README.md
\ No newline at end of file
# WZL-MQTT
Current stable version: 2.5.1
## Documentation
For the full API documentation, view [https://iot.wzl-mq.rwth-aachen.de/documentation/libs/mqtt/](https://iot.wzl-mq.rwth-aachen.de/documentation/libs/mqtt/).
## Installation
Requires at least Python 3.6
1. Install the WZL-MQTT package via pip
```
pip install wzl-mqtt
```
## Usage
### Publish messages
```python
from wzl import mqtt
# username and password required to connect to the broker
MQTT_USER = ""
MQTT_PASSWORD = ""
# address, port and virtual host of the broker to connect to
MQTT_BROKER = "127.0.0.1"
MQTT_PORT = 1883
MQTT_VHOST = "/"
# initialize publisher and connect to the broker
client = mqtt.MQTTPublisher()
client.connect(MQTT_BROKER, MQTT_USER, MQTT_PASSWORD, vhost=MQTT_VHOST, port=MQTT_PORT)
# create message and publish the message as UTF-8 encoded string
message = json.dumps({"value": [random.uniform(0, 5) for i in range(3)], "timestamp": datetime.datetime.utcnow().isoformat() + "Z",
"covariance": [[2, 0, 0], [0, 2, 0], [0, 0, 0]], "nonce": str(uuid.uuid4()), "hash": None, "unit": "MTR"})
client.publish(MQTT_USER + "/channel-001", message.encode("utf-8"))
```
### Subscribe to topics and receive messages
```python
from wzl import mqtt
# username and password required to connect to the broker
MQTT_USER = ""
MQTT_PASSWORD = ""
# address, port and virtual host of the broker to connect to
MQTT_BROKER = "127.0.0.1"
MQTT_PORT = 1883
MQTT_VHOST = "/"
# initialize logger
logger = mqtt.Logger.get('Receiver') # change 'Receiver' to any string you like
# define callback which will be executed when a message is received
def print_mqtt_message(topic, message):
logger.info("### {} ###\r\n{}\r\n".format(topic, message.decode("utf-8")))
# initialize subscriber and connect to the broker
client = mqtt.MQTTSubscriber()
client.connect(MQTT_BROKER, MQTT_USER, MQTT_PASSWORD, vhost=MQTT_VHOST, port=MQTT_PORT)
# register the callback and subscribe topic
client.set_callback("PRINT", print_mqtt_message)
client.subscribe('#')
# start waiting loop to prevent program from exiting
while True:
try:
time.sleep(1)
except KeyboardInterrupt:
break
```
## Changelog
2.5.1
- increased verbosity in case of errors by including the full stack trace
2.5.0
- changed signature of connect method
- specifying the port is optional now, if not specified the port automatically is derived from the "websocket" and "ssl" flags
2.4.2
- fixed a bug of websocket connection
2.4.1
- made the error message of code 1 more precise
2.4.0
- added vhost parameter to connect function of client
- changed default logging behaviour
- now by default logging is only written to console
- if logging should also create log-files, the logger must be explicitly initialized
2.3.0
- a prefix can now be defined which is prepended to every published or subscribed topic
2.2.0
- it is possible to connect with more than one client with an identical username to the broker
2.1.0
- removed wzl-utilities dependency
2.0.0
- renamed the MQTReceiver to MQTTSubscriber for the sake of convenience
- added extensive documentation
1.3.0
- added wzl-utilities dependency by sourcing out logging functionality
# WZL-MQTT
[![pipeline status](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/digital-mars/mqtt/badges/master/pipeline.svg)](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/digital-mars/mqtt/badges/master)
Current stable version: 2.5.1
......
@echo off
rmdir dist /s /q
rmdir build /s /q
rmdir wzl_mqtt.egg-info /s /q
python setup.py bdist_wheel
\ No newline at end of file
name: 5f49f249-b55b-4f31-96da-3f69ccd0a975
channels:
- defaults
dependencies:
- ca-certificates=2020.12.5=h5b45459_0
- certifi=2020.12.5=py38haa244fe_1
- openssl=1.1.1k=h8ffe710_0
- paho-mqtt=1.5.1=pyhd3deb0d_0
- pip=21.0.1=pyhd8ed1ab_0
- python=3.8.8=h7840368_0_cpython
- python_abi=3.8=1_cp38
- setuptools=49.6.0=py38haa244fe_3
- sqlite=3.35.2=h8ffe710_0
- vc=14.2=hb210afc_4
- vs2015_runtime=14.28.29325=h5e1d092_4
- wheel=0.36.2=pyhd3deb0d_0
- wincertstore=0.2=py38haa244fe_1006
- pip:
- alabaster==0.7.12
- babel==2.9.0
- chardet==4.0.0
- colorama==0.4.4
- docutils==0.16
- idna==2.10
- imagesize==1.2.0
- jinja2==2.11.3
- markupsafe==1.1.1
- packaging==20.9
- pygments==2.8.1
- pyparsing==2.4.7
- pytz==2021.1
- requests==2.25.1
- snowballstemmer==2.1.0
- sphinx==3.5.3
- sphinx-rtd-theme==0.5.1
- sphinxcontrib-applehelp==1.0.2
- sphinxcontrib-devhelp==1.0.2
- sphinxcontrib-htmlhelp==1.0.3
- sphinxcontrib-jsmath==1.0.1
- sphinxcontrib-qthelp==1.0.3
- sphinxcontrib-serializinghtml==1.1.4
- urllib3==1.26.4
prefix: E:\environments\5f49f249-b55b-4f31-96da-3f69ccd0a975
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
\ No newline at end of file
......@@ -2,3 +2,4 @@ jinja2<3.1
sphinx==3.5.3
sphinx-rtd-theme==0.5.1
paho-mqtt==1.5.1
build==0.8.0
from setuptools import setup, find_packages
with open("PyPI-README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(name='wzl-mqtt',
version='2.5.1',
url='',
url='https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/',
project_urls={
"Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/iot/mqtt/-/issues",
},
author='Matthias Bodenbenner, Benjamin Montavon',
author_email='m.bodenbenner@wzl-mq.rwth-aachen.de',
description='Small library containing an MQTT publisher and receiver.',
package_dir={'wzl': 'src'},
packages=['wzl.mqtt'],
# long_description=open('./README.md').read(),
install_requires=['paho-mqtt'],
long_description=long_description,
long_description_content_type="text/markdown",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=['paho-mqtt==1.5.1'],
python_requires='>=3.6',
zip_safe=False)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment