Skip to main content

Communicate with TWELITE wireless modules (Lite edition)

Project description

mono wireless logo

MWings (Lite edition)

A library that communicate with TWELITE wireless modules (Lite edition).

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

Differences between mwings and mwingslite

  • Renamed module to mwingslite from mwings
  • Removed some heavy dependencies (pandas and its deps like numpy, pyarrow, etc.)
    • to_df() is not available, raises EnvironmentError
  • Built for Python 3.11+ (not 3.12+)

Scripts are same as original. Only configs or docs are different.

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

Use pip

pip install mwingslite

Or poetry

poetry add mwingslite

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 mwingslite 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 mwingslite 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 mwingslite 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_lite/examples at main.

LICENSE

MW-OSSLA

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

mwingslite-1.0.7.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

mwingslite-1.0.7-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file mwingslite-1.0.7.tar.gz.

File metadata

  • Download URL: mwingslite-1.0.7.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.3 Darwin/22.6.0

File hashes

Hashes for mwingslite-1.0.7.tar.gz
Algorithm Hash digest
SHA256 0a30a30155ff8185807242b3d1c5b85d9c279f3b40fc37a8f053755c5e85f72f
MD5 29791fc5baf99fe9f4d525ba35c134ee
BLAKE2b-256 fcaa0cdd5f2480aaefff5696aaa10142e7a643f94194c821962bdcf39d9348b5

See more details on using hashes here.

File details

Details for the file mwingslite-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: mwingslite-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 43.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.3 Darwin/22.6.0

File hashes

Hashes for mwingslite-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 aac16a437787c58d0c51858045f7011b0cdf2fd4184c9d4fc5bfc8583435c4d4
MD5 834084401a08d6c0c8918287458f425d
BLAKE2b-256 5f4208b8b39f2046493f4b8de91f23c7dc0d347077c111bf718f5dbe77eed382

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