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.0.0.tar.gz (13.8 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.0.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lua_device_client-1.0.0.tar.gz
  • Upload date:
  • Size: 13.8 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.0.0.tar.gz
Algorithm Hash digest
SHA256 e6a02683de18042dd34d2147c56a1d1ed4c3f6daddd32dee03a609231d99b012
MD5 dd5ef613e70a000ab95032ccf889fdaf
BLAKE2b-256 6d5a2c97afd7b1d8e0492f3fb8289c40362afb5de144eaa6ba89ba741c02d379

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lua_device_client-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f71dd11f0b71c315a0789868c08c6dd82b222bdac6699afac7c786592f11237
MD5 2a822009c4c536d34117fe26a3106535
BLAKE2b-256 7cafee95019a4117ad35cc797512a4581875040845ecc630754a7c336b555d6b

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