Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Wirepas MQTT Library

This Python wheel is designed to ease the development of tools on top of Wirepas Gateway to backend Api (MQTT with protobuf payloads).

Connection through MQTT is wrapped and messages in protobuf format are generated and parsed for you.

Its main focus is to control a full network without to handle individually the connection to every gateways.

Most api can be used in a synchronous or asynchronous way to feat your design.

Automatically generated documentation is hosted here <https://wirepas.github.io/wirepas-mqtt-library/>__.

Installation

Install from PyPi


This package is available from
`PyPi <https://pypi.org/project/wirepas-mqtt-library/>`__.

.. code:: shell

        pip install wirepas-mqtt-library

From the source
~~~~~~~~~~~~~~~

This wheel can be install from source directly if you need modifications.

.. code:: shell

        pip install -e .

Basic example
-------------

Steps to write a script to send a message

Import the module ^^^^^^^^^^^^^^^^^

Once the wheel is installed, you can import the module easily

.. code:: python

from wirepas_mqtt_library import WirepasNetworkInterface

Create a Wirepas Network Interface object ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python

wni = WirepasNetworkInterface(host,
                              port,
                              username,
                              password)

This object will allow you to interact with the network. For example, you can retrieve the list of gateways

.. code:: python

wni.get_gateways()

Or print the list of sinks for a given network

.. code:: python

line = ""
for gw, sink, config in wni.get_sinks():
    line += "[%s:%s] " % (gw, sink)

print(line)

Send a message with broadcast address from all sinks of a given network ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python

for gw, sink, config in wni.get_sinks():
    try:
        res = wni.send_message(gw, sink, 0xFFFFFFFF, 1, 1, "This is a test message".encode())
        if res != wmm.GatewayResultCode.GW_RES_OK:
            print("Cannot send data to %s:%s res=%s" % (gw, sink, res))
    except TimeoutError:
        print("Cannot send data to %s:%s", gw, sink)

Architecture

Threading model


When creating a WirepasNetworkInterface object, few threads will be involved.

* **Network (MQTT) thread**: all the internal MQTT operations will happen on this dedicated thread but no code from your application will be executed on it

* | **Worker thread(s)**: these threads will be used to call all your callbacks.
  | It can be either asynchronous reception of gateway responses or the data you have registered to.
  | If long operation are expected in your callback (like IO operation), you can specify the number of threads to use when creating
  | your WirepasNetworkInterface object to avoid a bottleneck. In fact, multiple threads will allow to handle
  | a new callback if another one is executing long operations.
  | By default there is a single thread.

* **Your calling thread**: Any call made in synchronous mode (cb=None) will lock your calling thread until it a response is receive or a timeout has elapsed

Synchronous vs Asynchronous

Most of the WirepasNetworkInterface methods can be called synchronously or asynchronously. When synchronous, answer from the gateway is awaited before returning. from the gateway and a TimeoutError Exception will be generated if the gateway doesn't answer within the default 2s timeout.

.. code:: python

# Send a message as broadcast from sink sink_id attached to gateway gw_id on endpoint 1
# in a synchronous way
res = wni.send_message(gw, sink, 0xFFFFFFFF, 1, 1, "This is a test message".encode())
if res != wmm.GatewayResultCode.GW_RES_OK:
    print("Sending data synchronously failed: res=%s" % res)

But if you specify a callback, it will be called when the answer is received or never if the gateway doesn't answer.

.. code:: python

def on_message_sent_cb(res, param):
    if res != wmm.GatewayResultCode.GW_RES_OK:
        print("Sending data asynchronously failed: res=%s. Caller param is %s" % (res, param))

param = 1234
# Send a message as broadcast from sink sink_id attached to gateway gw_id on endpoint 1
# in an asynchronous way
wni.send_message(gw_id, sink_id, 0xFFFFFFFF, 1, 1, "This is a test message".encode(), cb=on_message_sent_cb, param=param)

License

Licensed under the Apache License, Version 2.0.

Metadata

Release files for wirepas-mqtt-library 1.4.0rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wirepas-mqtt-library 1.4.0rc1
File Size Uploaded Provenance Actions
wirepas_mqtt_library-1.4.0rc1.tar.gz 31.1 kB Without provenance Details for wirepas_mqtt_library-1.4.0rc1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wirepas-mqtt-library 1.4.0rc1
File Interpreter ABI Platform Actions
wirepas_mqtt_library-1.4.0rc1-py3-none-any.whl Python 3 none any Details for wirepas_mqtt_library-1.4.0rc1-py3-none-any.whl

Total release size: 63.3 kB

Release files / wirepas_mqtt_library-1.4.0rc1.tar.gz

Download URL wirepas_mqtt_library-1.4.0rc1.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c080f9ec3918748939816d003161f354a602fde17d8d22ea6b00e8bc10205ce0
BLAKE2b-256 checksum
How to use checksums
17e911d48aee04be78de273ecf7683903222fd5c69d15a72301cb99d83ba20f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release files / wirepas_mqtt_library-1.4.0rc1-py3-none-any.whl

Download URL wirepas_mqtt_library-1.4.0rc1-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
118ca4911e7768b703ceb5d0ca9ffad998f1c433beb76979185a2a2f28b4912c
BLAKE2b-256 checksum
How to use checksums
1037b705b8ee251847e03c85255b11a6dba3fc10573b7ef0cf98c47515bc93f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Security for wirepas-mqtt-library 1.4.0rc1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page