def messageCB(conn, msg): reply = None user = xmpp.protocol.JID(msg.getFrom()) print "%s:\n%s\n" %(user, msg.getBody()) # answer with same Thread ID ... try: cmd = Command(msg.getBody()) print cmd.getToken() print messageCB.tokens if str(cmd.getToken()) in messageCB.tokens: to = messageCB.tokens[str(cmd.getToken())] to_cmd = Command(to.getBody()) cmd = ampel.translate_response(cmd) print cmd.toString() cmd.setToken(to_cmd.getToken()) reply = to.buildReply(text = cmd.toString()) reply.setType("chat") print reply.getBody() conn.send(reply) return None messageCB.tokens[str(messageCB.token)] = msg if cmd.getPrefix() == "ampel": ampel.process(cmd, conn, messageCB.token) except ValueError, e: print e
def messageCB(conn, msg): reply = None user = xmpp.protocol.JID(msg.getFrom()) print "%s:\n%s\n" % (user, msg.getBody()) # answer with same Thread ID ... try: cmd = Command(msg.getBody()) print cmd.getToken() print messageCB.tokens if str(cmd.getToken()) in messageCB.tokens: to = messageCB.tokens[str(cmd.getToken())] to_cmd = Command(to.getBody()) cmd = ampel.translate_response(cmd) print cmd.toString() cmd.setToken(to_cmd.getToken()) reply = to.buildReply(text=cmd.toString()) reply.setType("chat") print reply.getBody() conn.send(reply) return None messageCB.tokens[str(messageCB.token)] = msg if cmd.getPrefix() == "ampel": ampel.process(cmd, conn, messageCB.token) except ValueError, e: print e
def send_command_to_ampel(conn, token, i2c_command, data=None): """ send the new command to the ampel """ cmd = Command("i3c.call\n%s\n1 device\n0x20\n1 command\n%s" %(token, hex(i2c_command))) if data: cmd.params["data"] = data cmd = xmpp.Message(ampel_xmpp_account, cmd.toString()) conn.send(cmd)
def send_command_to_ampel(conn, token, i2c_command, data=None): """ send the new command to the ampel """ cmd = Command("i3c.call\n%s\n1 device\n0x20\n1 command\n%s" % (token, hex(i2c_command))) if data: cmd.params["data"] = data cmd = xmpp.Message(ampel_xmpp_account, cmd.toString()) conn.send(cmd)