AsyncClient
For code that already usesasyncio:
Client (sync)
For simple scripts — relay commands and temperature, noasync/await:
client.on(...) on both clients.
Documentation Index
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Raspberry Pi Python SDK usage examples
asyncio:
import asyncio
from firmngin import AsyncClient, ClientConfig, Entity, Event, Payment
async def on_payment(payment: Payment) -> None:
if payment.is_success:
print("paid:", payment.order_id)
async def main():
config = ClientConfig.from_file("keys.json")
async with AsyncClient(config) as client:
client.on(Event.PAYMENT, on_payment)
await client.connect()
await client.push_entity(Entity("relay"), "on")
await client.run()
asyncio.run(main())
async/await:
from firmngin import Client, ClientConfig, Entity, EntityCommand
relay = Entity("relay")
temperature = Entity("temperature")
with Client(ClientConfig.from_file("keys.json")) as client:
@client.on_entity(relay)
def handle_relay(command: EntityCommand) -> None:
print("relay:", command.value)
client.connect()
client.push_entity(relay, "off")
client.push_entity(temperature, 27.5)
client.run()
client.on(...) on both clients.
from firmngin import Dispense, Event, Init
@client.on(Event.INIT)
def on_init(init: Init) -> None:
print("vending:" if init.is_vending_mode else "service")
@client.on(Event.DISPENSE)
def on_dispense(dispense: Dispense) -> None:
for sku in dispense.skus:
print("dispense:", sku)
import json
from firmngin import Event
@client.on(Event.METADATA_PENDING)
def on_pending(raw_json: str) -> None:
data = json.loads(raw_json)
from firmngin import Entity, EntityCommand
@client.on_entity(Entity("relay"))
def handle_relay(command: EntityCommand) -> None:
print(command.value)