-- -- Lightswitch - Basic automaton to peer a button and a lamp -- ---[[ -- Just for debuging print("-- lightswitch.lua --") print("xAAL_Lua_baseaddr: "..xAAL_Lua_uuid_unparse(xAAL_Lua_baseaddr)) print("xAAL_Lua_groupId: "..xAAL_Lua_uuid_unparse(xAAL_Lua_groupId)) print("xAAL_Lua_parameter: "..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))() peering["button"] = xAAL_Lua_uuid_parse(peering["button"]) peering["lamp"] = xAAL_Lua_uuid_parse(peering["lamp"]) -- 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(xAAL_Lua_uuid_unparse(dev)); print(xAAL_Lua_uuid_unparse(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