Skip to main content
mono wireless logo

MWings

A library that communicate with TWELITE wireless modules.

Lint with mypy / black / ruff MW-OSSLA

Overview

Receive packets from and send commands to TWELITE child devices through the connected TWELITE parent device.

The App_Wings firmware must be written to the TWELITE parent device connected to the host.

Built for Python 3.12+.

Receive packets from

  • App_Twelite
  • App_IO
  • App_ARIA
    • ARIA mode
  • App_CUE
    • CUE mode
    • PAL Event (Move/Dice) mode
  • App_PAL
    • AMBIENT
    • OPENCLOSE (CUE/ARIA OPENCLOSE mode)
    • MOTION
  • App_Uart (Mode A)
    • Simple
    • Extended
  • act

Send commands to

  • App_Twelite (Signals)
  • App_IO (Digital Signals)
  • App_PAL (NOTICE)
    • Simple
    • Detailed
    • Event
  • App_Uart (Mode A)
    • Simple

Installation

The package is available from PyPI.

Use pip

pip install mwings

Or poetry

poetry add mwings

Features

Written with modern python

Modules of the modern python, by the modern python, for the modern python.

  • Fully typed; passes mypy --strict
  • PEP8 compliance; formatted with black and passes ruff check
  • Built with poetry and pyproject.toml
  • numpy-style docstring, everywhere

Great data portability

Received data can be exported easily.

Data classes are derived from pydantic.BaseModel.

Examples

Receive App_Twelite packets

Using Twelite.receive()

Simplest way to receive some parsed packets.

Below script shows how to receive App_Twelite packets in blocking operations.

import mwings as mw


def main() -> None:
    # Create twelite object
    twelite = mw.Twelite(mw.utils.ask_user_for_port())

    # Attach handlers
    @twelite.on(mw.Twelite.Packet.APP_TWELITE)
    def on_app_twelite(packet: mw.parsers.app_twelite.ParsedPacket) -> None:
        print(packet.to_json())

    # Receive packets
    while True:
        print(twelite.receive())


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("...Aborting")

Using Twelite.start()

Practical way to receive some parsed packets.

The Twelite class is a subclass of the threading.Thread.

Below script shows how to receive packets in another thread.

import mwings as mw


def main() -> None:
    # Create twelite object
    twelite = mw.Twelite(mw.utils.ask_user_for_port())

    # Attach handlers
    @twelite.on(mw.Twelite.Packet.APP_TWELITE)
    def on_app_twelite(packet: mw.parsers.app_twelite.ParsedPacket) -> None:
        print(packet.to_json())

    # Start receiving
    try:
        twelite.daemon = True
        twelite.start()
        print("Started receiving")
        while True:
            twelite.join(0.5)
    except KeyboardInterrupt:
        print("...Stopping")
        twelite.stop()
        print("Stopped")


if __name__ == "__main__":
    main()

Note that event handlers are not called from the main thread. When you have to use parsed data from the main thread, data should be passed by queue or something.

Send App_Twelite packets

To send packets, just create a command and send it.

Below script shows how to blink an LED on the DO1 port.

from time import sleep
from typing import Any

import mwings as mw


def main() -> None:
    # Create twelite objec
    twelite = mw.Twelite(mw.utils.ask_user_for_port())

    # Create command (initialize in pydantic style)
    initial: dict[str, Any] = {
        "destination_logical_id": 0x78,
        "di_to_change": [True, False, False, False],
        "di_state": [False, False, False, False],
    }
    command = mw.serializers.app_twelite.Command(**initial)

    # Blinking
    while True:
        command.di_state[0] = not command.di_state[0]
        twelite.send(command)
        print(f"Flip DO1: {command.di_state[0]}")
        sleep(1)


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("...Aborting")

Note that command data classes (such as mw.serializers.app_twelite.Command) are derived from [pydantic.BaseModel](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.

See more advanced examples at mwings_python/examples at main.

LICENSE

MW-OSSLA

Metadata

Release files for mwings 1.0.18

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

Source distribution (sdist)

Source distribution for mwings 1.0.18
File Size Uploaded
mwings-1.0.18.tar.gz 28.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mwings 1.0.18
File Interpreter ABI Platform
mwings-1.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 72.7 kB

Release files / mwings-1.0.18.tar.gz

Download URL mwings-1.0.18.tar.gz
Size 28.5 kB
Tags Source
SHA-256 checksum
How to use checksums
852d0c0bed4758451fff5555425c91f0b3d26e867049a1e8afcab2b1d5bacc0f
BLAKE2b-256 checksum
How to use checksums
ffbd53f8f1bc78e316d72bf0c26a4bcb3bb3b23ed1b0abc2301a730ea3543eb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.9 Darwin/24.5.0

Release files / mwings-1.0.18-py3-none-any.whl

Download URL mwings-1.0.18-py3-none-any.whl
Size 44.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b70cfdbacd25944e0338b1e8b0ddc00b1141afa9439f5b8b78d9881d4f8af7e
BLAKE2b-256 checksum
How to use checksums
bd62d9e44c60073244ceb3d95109223c08880f549e3a963ae5645d84229005ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.12.9 Darwin/24.5.0

Release history Release notifications | RSS feed

This release

1.0.18 This release

2 release files

1.0.17

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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