Module Integration Guides
...
Rust ESP-IDF
Receiving Actions
2 min
docid\ sxdqnjtvau iphckojgz3 are commands that platform sends to the client the json format for actions would look like { "name" "toggle board led", "id" "101", "kind" "process", "payload" { "status" "on", }, } note payload is optional, so it may or mayn't be there to handle an incoming action, you need to define and register an action handler an action handle must take action and \&bytebeamclient as arguments let bytebeam client = bytebeamclient init()?; // you can pass a closure bytebeam client register action handle( "example action" into(), &|action action, bytebeam client \&bytebeamclient| { // handler body }, ); // or you can also pass down a function bytebeam client register action handle("toggle" into(), \&toggle); // function signature fn toggle(action action, bytebeam client \&bytebeamclient) { // function body } we can also send the progress updates for actions using publish action status pub fn publish action status( \&self, action id \&str, percentage u32, status \&str, error messages option<&\[\&str]>, ) > anyhow result\<u32> { for example fn toggle(action action, bytebeam client \&bytebeamclient) { let mut onboard led = onboard led lock() unwrap(); let onboard led = onboard led get mut() as mut() unwrap(); match onboard led toggle() { ok( ) => bytebeam client publish action status(\&action id, 100, "toggled", none), err( ) => bytebeam client publish action status( \&action id, 0, "failed", some(&\["failed to toggle led"]), ), } ok(); // just to satisfy clippy for now! } check out https //github com/bytebeamio/bytebeam esp rs sdk/tree/main/examples for more details
