vibration_anomaly when readings cross a threshold, which a handler on the platform stores and hands to the model. You need a Pico W set up as in Run a device on a Raspberry Pi Pico W, an analog vibration sensor on GP26, a temperature sensor on GP27, and a relay on GP16; without sensors the code still runs with noise readings.
Verified against lua-cli 3.45.0.
What you’ll build
- A MicroPython device
cnc-monitor-01withread_vibration,read_temperature, andemergency_stop. - A main loop that polls, heartbeats, and fires
vibration_anomalyevery 10 seconds when needed. - A
defineDeviceTriggerhandler that stores the event and invokes the agent.
1
Create the credential
From the agent project, issue a device credential for device name
cnc-monitor-01; the default operations, commands and triggers, are what the monitor needs. Copy LUA_AGENT_ID and LUA_DEVICE_CREDENTIAL from the file into config.py on the board together with the Wi-Fi settings, as in the Pico W tutorial.2
Write main.py
The loop mirrors what
run() does, so the periodic anomaly check can sit beside command polling: poll messages, heartbeat every 30 seconds, prune the duplicate cache, reconnect on any error. It reaches into the client’s underscore-prefixed members, which a later client version may rename.main.py
3
Handle the trigger on the agent
The handler stores every anomaly and asks the model to assess it;
device.name identifies the board.src/devices/VibrationAnomaly.ts
4
Register and publish
Register the trigger on the agent, then push it live.
src/index.ts
5
Run and verify
Copy Tap the vibration sensor hard enough to cross 3 g: within 10 seconds the board fires the trigger and the log shows the handler’s run.
main.py to the board and start it, then read the sensors from chat and watch for the trigger.What you learned
trigger()on MicroPython returns at once; the acknowledgment arrives on thetrigger_acktopic and is printed. See MicroPython device client.- A standalone
defineDeviceTriggermatches the name exactly and runs with{ device: { name } }. See Handle device triggers. - Triggers are limited to 10 per second per agent, so sample on an interval rather than on every reading. See Reliability and limits.
Next steps
Warehouse station
The same trigger pattern from a Node device.
MQTT protocol
The topics this board publishes and subscribes to.

