Can you use wildcard subscription with device.on and agent.on. Something like
device.on('button*", callback)
to handle events buttonOn and buttonOff
cheers
jima
Can you use wildcard subscription with device.on and agent.on. Something like
device.on('button*", callback)
to handle events buttonOn and buttonOff
cheers
jima
No, but you just do:
agent.send("button", hardware.pin1.read());
…to send the button state with the button message, and…
`function callback(value) {
server.log("button state "+value);
}
device.on(“button”, callback);`
…to receive it.
That part I understand but it would be cool to support wildcard events so that you can catch unhandled events or more importantly do some dynamic before/after event processing.
As you’re writing both ends, why would you have unhandled events?
What do you mean by dynamic before/after event processing?
The scenario is that I want to develop a generic event handler on the agent side to act as a pass through to an external service.
Again, this isn’t a problem. You’d just use a single name for all passthrough traffic, eg passthrough, and then nest the data one level deep in the table:
agent:
device.on("passthrough", function(t) { // event name is in t.eventname // event data is in t.data });
device:
agent.send("passthrough", { eventname="button", data=1 });
Thanks Hugo that would work well.