WASM Module Guide
Custom Broadcast Logic
Sometimes you want a WASM module to actively push notifications directly to the Admin HUD without storing permanent state. You can do this using the qos_sdk::broadcast module.
#Low Stock Alerts
Building upon the Inventory module, we can dispatch a critical alert to the manager's dashboard if a SKU drops below 5 items.
src/lib.rs
#![no_std]
// Assuming the qos_sdk has a broadcast module:
use qos_sdk::{state, output, broadcast, LogLevel};
#[no_mangle]
pub extern "C" fn run() -> i32 {
let sku_key = "inventory:sku_beer";
if let Some(val) = state::get(sku_key) {
if val.len() == 4 {
let mut buf = [0u8; 4];
buf.copy_from_slice(&val);
let mut stock = u32::from_le_bytes(buf);
if stock > 0 {
stock -= 1;
state::set(sku_key, &stock.to_le_bytes()).unwrap();
// --- NEW LOGIC HERE ---
if stock == 5 {
broadcast::send(LogLevel::Warn, b"Beer stock is critically low! Only 5 left.");
}
output::write(b"{\"status\":\"success\"}");
return 0;
}
}
}
1
}