-
-
Save nicopace/6612d48880f07e61523c564364f5edab to your computer and use it in GitHub Desktop.
| #!/usr/bin/env lua | |
| require "ubus" | |
| require "uloop" | |
| uloop.init() | |
| local conn = ubus.connect() | |
| if not conn then | |
| error("Failed to connect to ubus") | |
| end | |
| -- This is used as namespace for the publishing of events | |
| local ubus_objects = { | |
| test = { | |
| -- You get notified when someone subscribes to a channel | |
| __subscriber_cb = function( subs ) | |
| print("total subs: ", subs ) | |
| end | |
| } | |
| } | |
| conn:add( ubus_objects ) | |
| -- We will send one message per second | |
| local timer | |
| local counter = 0 | |
| function t() | |
| counter = counter + 1 | |
| -- this is the call that does the publishing | |
| conn:notify(ubus_objects.test.__ubusobj, "test.alarm", {count = counter}) | |
| timer:set(1000) | |
| end | |
| timer = uloop.timer(t) | |
| timer:set(1000) | |
| uloop.run() |
| #!/usr/bin/env lua | |
| require "ubus" | |
| require "uloop" | |
| uloop.init() | |
| local conn = ubus.connect() | |
| if not conn then | |
| error("Failed to connect to ubus") | |
| end | |
| local sub = { | |
| notify = function(msg) | |
| print("Count: ", msg["count"]) | |
| end, | |
| } | |
| -- this is the call that does the subscribing | |
| conn:subscribe("test", sub) | |
| uloop.run() |
is it possible to get the objpath in the sub function?
I couldn't say, but please share your explorations! :)
I just create a function with the ifname in it. Not sure if this is a good idea. ^^
https://github.com/PolynomialDivision/uhostapd/blob/main/src/uhostapd.lua#L25
I just create a function with the ifname in it. Not sure if this is a good idea. ^^
https://github.com/PolynomialDivision/uhostapd/blob/main/src/uhostapd.lua#L25
What's uhostapd? someone curious once said?
Check the readme, you could be told.
nothing there... have to wait you will hear.
:D
Good that you found your way... I am curious why these mechanisms are not that used... I guess now that ubus subscribe is implemented on uhttpd rpc I hope it starts being used more, as for the web it is really valuable!
I love this ubus stuff. ;)
Currently, I try adding ubus bindings to mesh daemon babeld: openwrt/routing#630
uhostapd is just some code I wanted to upload somewhere, that access hostapd ubus bindings in lua.
I will make use of it for another project.
is it possible to get the objpath in the sub function?