A small example package
Project description
Mqtt common library
Usage
from MqttLibPy.client import MqttClient
# from MqttLibPy.serializer import Serializer
# Both prefix and postfix are optional
client = MqttClient('myhost.com', 1883, prefix="myprefix")
# This function will be called when a message is received in the myprefix/myendpoint topic
@client.endpoint("myendpoint", force_json=True)
def myendpoint(mqtt_client, _, json_body):
print(json_body)
my_field = json_body["some_field"]
# Do stuff with my_field
# ..
# Return a response
my_response = {"another_field": "Ok!"}
# Sends message to topic "myendpoint"
client.send_message_serialized(my_response, "myendpoint", valid_json=True)
Send file
Sender
from MqttLibPy.client import MqttClient
client = MqttClient("myhost.com", 1883)
client.send_file("test_bytes", "/path/to/my/file/myfile.")
listener
from MqttLibPy.client import MqttClient
client = MqttClient("myhost.com", 1883)
@client.endpoint("test_bytes", is_file=True)
def get_file(client, user_data, file):
with open(f"/path/to/save/file/{file['data'][0]['filename']}", 'wb+') as f:
f.write(file['bytes'])
f.close()
threading.Thread(target=client.listen).start()
Changelog
1.5.0
- Return error codes on message sent
1.1.6
- Fix bug where the same file couldnt be received multiple times
1.1.0
- Add optional metadata to file transfers
1.0.3
- Fix bug where file metadata would get overwritten if metadata arrived after the file
1.0.2
- Fix bug that caused bytes to be empty if metadata arrived after the file
1.0.1
- Fix serializer crash with json objects
1.0.0
- Adds send file method
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mqttlibpy-1.5.0.tar.gz
(7.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mqttlibpy-1.5.0.tar.gz.
File metadata
- Download URL: mqttlibpy-1.5.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15e032baeac7ed2e46f1ee0af45779d940fdf0a2126e2265de470b0c0f42e290
|
|
| MD5 |
97420a0658230ef460ccb66c151dadcb
|
|
| BLAKE2b-256 |
51a903b8f1803cd705c59b7d9c83ec721ec74c4ba861f2e479d2d16e9f6db1d9
|
File details
Details for the file mqttlibpy-1.5.0-py3-none-any.whl.
File metadata
- Download URL: mqttlibpy-1.5.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e29ae7c617284be9c514c6065b1e53baf7afb17553d5ea59fba90f6d1a5dda9f
|
|
| MD5 |
02ef620f302a1283d7844b2e1cfb6ba6
|
|
| BLAKE2b-256 |
3a94130948c0c2d0880624cd910ab2e6ceab538545b98a7f67e9d20c07607674
|