xiaomi-ndef


Namexiaomi-ndef JSON
Version 0.1.2 PyPI version JSON
download
home_page
SummaryEncode and decode NDEF message using Xiaomi NFC protocol.
upload_time2024-02-27 05:44:30
maintainerXFY9326
docs_urlNone
authorXFY9326
requires_python>=3.10
license
keywords mi ndef ndef-library nfc xiaomi
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Xiaomi NDEF

![!python-versions](https://img.shields.io/badge/Python-3.10-blue)
[![Pypi](https://img.shields.io/pypi/v/xiaomi-ndef?color=orange)](https://pypi.org/project/xiaomi-ndef/)

[![Test](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/test.yml/badge.svg)](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/test.yml)
[![Release](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/release.yml/badge.svg)](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/release.yml)

Encode and decode NDEF message using Xiaomi NFC protocol.

## Usage

```shell
pip install xiaomi-ndef
```

```python
from pyndef import NdefMessage

from xiaomi_ndef import MiConnectData, XiaomiNfcPayload, V2NfcProtocol
from xiaomi_ndef import ndef, xiaomi, handoff, tag

# Example
NDEF_MSG_BYTES = b"..."

# Parse ndef
ndef_msg = NdefMessage.parse(NDEF_MSG_BYTES)

ndef_type = ndef.get_xiami_ndef_payload_type(ndef_msg)
ndef_bytes = ndef.get_xiami_ndef_payload_bytes(ndef_msg, ndef_type)

# Parse ndef payload
mi_connect_data = MiConnectData.parse(ndef_bytes)
nfc_protocol = mi_connect_data.get_nfc_protocol()
nfc_payload = mi_connect_data.to_xiaomi_nfc_payload(nfc_protocol)

# Build new screen mirror record
handoff_ndef_type, handoff_payload = xiaomi.new_handoff_screen_mirror(
    device_type=handoff.DeviceType.PC,
    bluetooth_mac="00:00:00:00:00:00",
    enable_lyra=True
)
handoff_record = ndef.new_xiaomi_ndef_record(handoff_ndef_type, handoff_payload)

# Build new ndef msg
handoff_msg = NdefMessage(handoff_record)
print(handoff_msg.to_bytes().hex())

# Customize xiaomi ndef
XiaomiNfcPayload(
    major_version=1,
    minor_version=11,
    id_hash=0,
    protocol=V2NfcProtocol,
    appData=tag.NfcTagAppData(
        major_version=1,
        minor_version=0,
        write_time=1666666666,
        flags=0,
        records=(
            tag.NfcTagDeviceRecord(
                device_type=tag.DeviceType.MI_SOUND_BOX,
                flags=0,
                device_number=0,
                attributes_map=tag.NfcTagDeviceRecord.new_attributes_map([
                    tag.DeviceAttribute.WIFI_MAC_ADDRESS.new_pair("00:00:00:00:00:00"),
                    tag.DeviceAttribute.BLUETOOTH_MAC_ADDRESS.new_pair("00:00:00:00:00:01")
                ])
            ),
            tag.NfcTagActionRecord(
                action=tag.Action.CUSTOM,
                condition=tag.Condition.AUTO,
                device_number=0,
                flags=0
            )
        )
    )
)
```

## Related Projects

- [PyNdef](https://github.com/XFY9326/PyNdef)
- [MiLinkNFC](https://github.com/XFY9326/MiLinkNFC)

## Reference

| Package name                    | Version                    |
|---------------------------------|----------------------------|
| `com.xiaomi.mi_connect_service` | `3.1.453.10`               |
| `com.milink.service`            | `15.0.5.0.ceaac61.2919843` |
| `com.xiaomi.smarthome`          | `9.1.501`                  |
| `com.android.nfc`               | `14`                       |

## License

```text
MIT License

Copyright (c) 2024 XFY9326

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "xiaomi-ndef",
    "maintainer": "XFY9326",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "mi,ndef,ndef-library,nfc,xiaomi",
    "author": "XFY9326",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/01/8b/704e7d7933cd6a68febf7190fc7a8c2d8865d7187e677df3e44cdf4a7d7f/xiaomi_ndef-0.1.2.tar.gz",
    "platform": null,
    "description": "# Xiaomi NDEF\n\n![!python-versions](https://img.shields.io/badge/Python-3.10-blue)\n[![Pypi](https://img.shields.io/pypi/v/xiaomi-ndef?color=orange)](https://pypi.org/project/xiaomi-ndef/)\n\n[![Test](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/test.yml/badge.svg)](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/test.yml)\n[![Release](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/release.yml/badge.svg)](https://github.com/XFY9326/XiaomiNDEF/actions/workflows/release.yml)\n\nEncode and decode NDEF message using Xiaomi NFC protocol.\n\n## Usage\n\n```shell\npip install xiaomi-ndef\n```\n\n```python\nfrom pyndef import NdefMessage\n\nfrom xiaomi_ndef import MiConnectData, XiaomiNfcPayload, V2NfcProtocol\nfrom xiaomi_ndef import ndef, xiaomi, handoff, tag\n\n# Example\nNDEF_MSG_BYTES = b\"...\"\n\n# Parse ndef\nndef_msg = NdefMessage.parse(NDEF_MSG_BYTES)\n\nndef_type = ndef.get_xiami_ndef_payload_type(ndef_msg)\nndef_bytes = ndef.get_xiami_ndef_payload_bytes(ndef_msg, ndef_type)\n\n# Parse ndef payload\nmi_connect_data = MiConnectData.parse(ndef_bytes)\nnfc_protocol = mi_connect_data.get_nfc_protocol()\nnfc_payload = mi_connect_data.to_xiaomi_nfc_payload(nfc_protocol)\n\n# Build new screen mirror record\nhandoff_ndef_type, handoff_payload = xiaomi.new_handoff_screen_mirror(\n    device_type=handoff.DeviceType.PC,\n    bluetooth_mac=\"00:00:00:00:00:00\",\n    enable_lyra=True\n)\nhandoff_record = ndef.new_xiaomi_ndef_record(handoff_ndef_type, handoff_payload)\n\n# Build new ndef msg\nhandoff_msg = NdefMessage(handoff_record)\nprint(handoff_msg.to_bytes().hex())\n\n# Customize xiaomi ndef\nXiaomiNfcPayload(\n    major_version=1,\n    minor_version=11,\n    id_hash=0,\n    protocol=V2NfcProtocol,\n    appData=tag.NfcTagAppData(\n        major_version=1,\n        minor_version=0,\n        write_time=1666666666,\n        flags=0,\n        records=(\n            tag.NfcTagDeviceRecord(\n                device_type=tag.DeviceType.MI_SOUND_BOX,\n                flags=0,\n                device_number=0,\n                attributes_map=tag.NfcTagDeviceRecord.new_attributes_map([\n                    tag.DeviceAttribute.WIFI_MAC_ADDRESS.new_pair(\"00:00:00:00:00:00\"),\n                    tag.DeviceAttribute.BLUETOOTH_MAC_ADDRESS.new_pair(\"00:00:00:00:00:01\")\n                ])\n            ),\n            tag.NfcTagActionRecord(\n                action=tag.Action.CUSTOM,\n                condition=tag.Condition.AUTO,\n                device_number=0,\n                flags=0\n            )\n        )\n    )\n)\n```\n\n## Related Projects\n\n- [PyNdef](https://github.com/XFY9326/PyNdef)\n- [MiLinkNFC](https://github.com/XFY9326/MiLinkNFC)\n\n## Reference\n\n| Package name                    | Version                    |\n|---------------------------------|----------------------------|\n| `com.xiaomi.mi_connect_service` | `3.1.453.10`               |\n| `com.milink.service`            | `15.0.5.0.ceaac61.2919843` |\n| `com.xiaomi.smarthome`          | `9.1.501`                  |\n| `com.android.nfc`               | `14`                       |\n\n## License\n\n```text\nMIT License\n\nCopyright (c) 2024 XFY9326\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Encode and decode NDEF message using Xiaomi NFC protocol.",
    "version": "0.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/XFY9326/XiaomiNDEF/issues",
        "Homepage": "https://github.com/XFY9326/XiaomiNDEF",
        "Repository": "https://github.com/XFY9326/XiaomiNDEF.git"
    },
    "split_keywords": [
        "mi",
        "ndef",
        "ndef-library",
        "nfc",
        "xiaomi"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3d52f8483fe71af8995074fe0ad86924b3b007f8f9bfb51439792a8127688f35",
                "md5": "a3289b6259037244baa581e1048b4eda",
                "sha256": "c4ded2570b331f917b96156da8536efde9c740327c960a70e924cff34e1a2869"
            },
            "downloads": -1,
            "filename": "xiaomi_ndef-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a3289b6259037244baa581e1048b4eda",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 16256,
            "upload_time": "2024-02-27T05:44:28",
            "upload_time_iso_8601": "2024-02-27T05:44:28.547475Z",
            "url": "https://files.pythonhosted.org/packages/3d/52/f8483fe71af8995074fe0ad86924b3b007f8f9bfb51439792a8127688f35/xiaomi_ndef-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "018b704e7d7933cd6a68febf7190fc7a8c2d8865d7187e677df3e44cdf4a7d7f",
                "md5": "3d25b7262f9e3b4226597563f655db00",
                "sha256": "8ecd32a410cd54e1e6feea6efa30ac2a5d1021f5c5c7bdf4a944bfa646e2dc8d"
            },
            "downloads": -1,
            "filename": "xiaomi_ndef-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3d25b7262f9e3b4226597563f655db00",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 11364,
            "upload_time": "2024-02-27T05:44:30",
            "upload_time_iso_8601": "2024-02-27T05:44:30.329937Z",
            "url": "https://files.pythonhosted.org/packages/01/8b/704e7d7933cd6a68febf7190fc7a8c2d8865d7187e677df3e44cdf4a7d7f/xiaomi_ndef-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-27 05:44:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "XFY9326",
    "github_project": "XiaomiNDEF",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "xiaomi-ndef"
}
        
Elapsed time: 0.21034s