Skip to main content

Connect physical devices to Lua AI agents via MQTT.

Project description

lua-device-client

Connect physical devices to Lua AI agents via MQTT.

Install

pip install lua-device-client

Quick Start

import asyncio
from lua_device import DeviceClient, DeviceCommandDefinition

client = DeviceClient(
    agent_id="baseAgent_agent_abc123",
    api_key="api_your_key_here",
    device_name="warehouse-scanner",
    commands=[
        DeviceCommandDefinition(
            name="scan_barcode",
            description="Scan a barcode and return its value",
        ),
        DeviceCommandDefinition(
            name="get_status",
            description="Return device battery and connectivity status",
        ),
    ],
)

async def handle_scan(payload):
    return {"barcode": "ABC-12345", "format": "CODE128"}

async def handle_status(payload):
    return {"battery": 85, "signal": "strong"}

client.on_command("scan_barcode", handle_scan)
client.on_command("get_status", handle_status)

async def main():
    await client.connect()
    print("Device connected!")

    # Fire a trigger to the agent
    ack = await client.trigger("barcode_scanned", {"value": "ABC-12345"})
    print(f"Trigger acknowledged: {ack}")

    # Keep running
    await asyncio.Event().wait()

asyncio.run(main())

Features

  • MQTT transport -- connects to Lua AI via MQTT (paho-mqtt)
  • Self-describing commands -- no server config needed
  • CDN uploads -- upload screenshots and files via CDN.upload()
  • Device triggers -- fire events from device to agent
  • Auto-reconnection -- exponential backoff
  • Async/await -- built on asyncio

MicroPython

For Raspberry Pi Pico W and other MicroPython boards, use the standalone MicroPython client included in lua_device/micropython.py. See the MicroPython docs for details.

Documentation

Full documentation: https://docs.heylua.ai/devices

License

MIT

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

lua_device_client-1.3.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lua_device_client-1.3.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file lua_device_client-1.3.0.tar.gz.

File metadata

  • Download URL: lua_device_client-1.3.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for lua_device_client-1.3.0.tar.gz
Algorithm Hash digest
SHA256 4ffce173856d9ba2c69ab20d5a3a94462122fde42e3f65b3862d0f3167b4ef9e
MD5 5dd0c4f586fb7be523d459830f424c89
BLAKE2b-256 73e403bc4b763b3bc5801d065748a1f3369b25b9748893a304ad721dabe5219d

See more details on using hashes here.

File details

Details for the file lua_device_client-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lua_device_client-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0159d86b61ba03be723787d6e5505bc7edb4ee277793236078c6e1b125949153
MD5 23703a335442cc63c37efef23a1031d9
BLAKE2b-256 82ab7fe3483e46da1b3de4ffb251dfea7d51841a2756c1e6e894094073227c49

See more details on using hashes here.

Supported by

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