-- -- Lightswitch - Basic automaton to peer a button and a lamp -- ---[[ -- Just for debuging print("xAAL_Lua_baseaddr:") print(xAAL_Lua_baseaddr) print("xAAL_Lua_parent:") print(xAAL_Lua_parent) print("xAAL_Lua_parameter:") print(xAAL_Lua_parameter) --]] device = { info="Peering a button and lamp", devType="basic.basic", vendorId="IHSEV Team", productId="Peering automaton", version="0.2", url="http://recherche.telecom-bretagne.eu/xaal/documentation/", unsupportedAttributes={}, unsupportedMethods={}, unsupportedNotifications={} } device["addr"] = xAAL_Lua_declare_device(device) -- Assume xAAL_Lua_parameter contains a table named peering -- with a button address and a lamp address assert(loadstring(xAAL_Lua_parameter))() -- Accept messages from the button xAAL_Lua_filter_broadcast_by_source(device["addr"], { peering["button"] }) -- Main of the job function xAAL_Lua_receive_callback(dev, source, devType, msgType, action, body) ---[[ -- Just for debuging local serpent = dofile("serpent.lua") print(dev); print(source); print(devType); print(msgType); print(action); print(serpent.block(body)) print() --]] if ( dev == device.addr ) then if ( body["position"] ) then xAAL_Lua_write_bus(dev, "request", "on", {}, { peering["lamp"] } ) else xAAL_Lua_write_bus(dev, "request", "off", {}, { peering["lamp"] } ) end end end