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.2.0.tar.gz (16.0 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.2.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lua_device_client-1.2.0.tar.gz
  • Upload date:
  • Size: 16.0 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.2.0.tar.gz
Algorithm Hash digest
SHA256 ca3a507dac693fedaabb41b7c04fb27ba913accf9cbd025c26dc99290a17a7d1
MD5 532323df126f3ced93e9adac09df5b2a
BLAKE2b-256 c9340ad4d2632143aebf45f7d4f2c38952c8817026939d2319e33f874a9a7997

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lua_device_client-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64cb2ef0d1f0118824761e2191965b8d961228ed4a87f78057448dd2a1684af8
MD5 fccce5480ee2862a48125561e876bae3
BLAKE2b-256 ccf6663a8917771d14a188bd8f723e087a908a6778dea4fff2250b9a23857654

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