Ambiorix wait_for example: build and run amxrt from one C file
Grow through practice
No need to finish reading — test nowOne line: it defines no data model; it only waits for an object. One C file — the smallest entry point to understand
amxrt.
Quick answer
wait_for is the "hello world" of Ambiorix: it starts amxrt, connects to the bus, calls amxb_wait_for_object, and enters the event loop until the object appears. It defines no data model and no ODL.
Working UCI mapping demo: amx-uci-route-demo.
What it does
baapi/wait_for connects to the bus and waits for an object path to appear; when it does, it prints Wait done and exits.
Files
Only one source file:
src/main.c
No ODL, no plugin, no data model.
Core code
amxrt_new();
amxrt_config_init(argc, argv, &index, NULL);
amxrt_connect();
amxrt_el_create();
amxb_wait_for_object(object); // wait for the object
amxrt_el_start(); // event loop
amxrt_new/config_init: initialize the runtime and command line;amxrt_connect: connect the backend/bus;amxb_wait_for_object: wait until the object is available;amxrt_el_start: enter the event loop untilamxrt_el_stop.
It also shows how to add custom command-line options (amxrt_cmd_line_add_option) and disable the pid file.
Compile/test on the AMX base environment
Prerequisite: build the base environment first, following “AMX / prplOS development environment” (libubox/ubus/AMX/amxrt or
amx-base:ubuntu). This article only builds/runswait_for.
Build the example
git clone https://gitlab.com/prpl-foundation/components/ambiorix/examples/baapi/wait_for.git
cd wait_for
make
Prepare a provider
hello.odl:
%config { name = "hello"; }
%define { object Hello { string Greeting = "hi"; } }
Test
# 1) start the bus
sudo ubusd -s /var/run/ubus/ubus.sock &
# 2) start the provider
sudo amxrt -N -u ubus:/var/run/ubus/ubus.sock \
-B /usr/bin/mods/amxb/mod-amxb-ubus.so \
./hello.odl &
# 3) wait for the object
./src/amx-wait-for -u ubus:/var/run/ubus/ubus.sock \
-B /usr/bin/mods/amxb/mod-amxb-ubus.so \
Hello.
Expected:
Wait until object [Hello.] is available
Wait done - object [Hello.] is available
Exit code 0.
Cleanup
sudo pkill -x amxrt
sudo pkill -x ubusd
What you learn
amxrtstartup order: new → config → connect → event loop;- bus waiting (
amxb_wait_for_object) is event-driven, not polling; - you can use
amxrtwithout ODL — it is a runtime first.
Limits
No data model, so no objects/parameters/transactions.
Next
amx-scheduler: 2 C + 2 ODL, with objects, instances and events.
Official example: wait_for Series: AMX Official Examples.
More: Ambiorix architecture · ODL reference · AMX examples map
Comments 0
No comments yet — be the first!