Skip to main content

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


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.4.9.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

mqttlibpy-1.4.9-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mqttlibpy-1.4.9.tar.gz.

File metadata

  • Download URL: mqttlibpy-1.4.9.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for mqttlibpy-1.4.9.tar.gz
Algorithm Hash digest
SHA256 70908b3ddf09af36bef5c2d4094d7fb93b40481087597f01434998be14b11d16
MD5 ea7f90350ebb7114bea0164b5659166d
BLAKE2b-256 967a53859a88170bf3652bafc42163ec75a00d147f1da0260bd9a015e6b6906f

See more details on using hashes here.

File details

Details for the file mqttlibpy-1.4.9-py3-none-any.whl.

File metadata

  • Download URL: mqttlibpy-1.4.9-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for mqttlibpy-1.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f187cc2062b6924b7427d40eb598f3ec096549aca5681fa58aa2c3064160011e
MD5 396cfb73bd3117a0b2bf366612560d32
BLAKE2b-256 71db876c3d255e2da98c8b53f73c659fe9b46a226966c3c6667a0a5ed013d105

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page