Relais über Google Talk steuern
Verfasst: Freitag 14. Februar 2014, 09:38
Hallo ich möchte über google talk auf meinem raspbarry pi ein Relay schalten und habe mir volgendes zusammen geschustert habe jedoch noch ein paar probleme z.B in zeile 60 kommt
File "raspiBot.py", line 60
print jid, " ---> ",bot.getResources(jid), bot.getShow(jid), bot.getStatus(jid)
^
SyntaxError: invalid syntax
währe jemand so freundlich da rüber zuschauen und mir zu helfen?
Mit freundlichen Grüssen
Willhelm
File "raspiBot.py", line 60
print jid, " ---> ",bot.getResources(jid), bot.getShow(jid), bot.getStatus(jid)
^
SyntaxError: invalid syntax
währe jemand so freundlich da rüber zuschauen und mir zu helfen?
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import subprocess
import pifacedigitalio
from PyGtalkRobot import GtalkRobot
BOT_GTALK_USER = 'irgendnemail@gmail.com'
BOT_GTALK_PASS = 'geheim'
BOT_ADMIN = 'sudo@gmail.com'
pfd = pifacedigitalio.PiFaceDigital()
class RaspiBot(GtalkRobot):
def command_001_setState(self, user, message, args):
'''(available|online|busy|dnd|away|idle|out|xa)( +(.*))?$(?i)'''
show = args[0]
status = args[1]
jid = user.getStripped()
if jid == BOT_ADMIN:
print jid , " ---> ",bot.getResources(jid), bot.getShow(jid), bot.getStatus(jid)
self.setState(show, status)
self.replyMessage(user, "State settings changed!")
def command_000_Relayon(self, user, message, args):
'''(relayon|pon|on|high)( +(.*))?$(?i)'''
print "Ein1"
relay_num = args[1]
pfd.relays[0].value = 1, True
self.replyMessage(user, "\nRelay on: "+ relay_num +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
def command_000_Relayoff(self, user, message, args):
'''(relayoff|poff|off|low)( +(.*))?$(?i)'''
print "Relay off\n"
relay_num = args[1]
pfd.relays[0].value = 0, False
self.replyMessage(user, "\nRelay off: "+ relay_num +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
def command_000_write(self, user, message, args):
'''(write|w)( +(.*))?$(?i)'''
print "Relay write\n"
arg_str = args[1]
aargs = arg_str.split()
relay_num = aargs[0]
state = aargs[1]
if int(state) == 1:
pfd.relays[0].value (int(relay_num), True)
self.replyMessage(user, "Relay on: "+ relay_num +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
elif int(state) == 0:
pfd.relays[0].value (int(relay_num), False)
self.replyMessage(user, "Relay off: "+ relay_num +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
def command_000_read(self, user, message, args):
'''(read|r)( +(.*))?$(?i)'''
print "Relay read\n"
relay_num = args[1]
pfd.relays[0].value = 0(int(relay_num))
self.replyMessage(user, "\nRelay read: "+ relay_num + " value: " + str(relay_value) + " at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
def command_003_shell(self, user, message, args):
'''(shell|bash)( +(.*))?$(?i)'''
cmd = args[1]
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = ""
for line in p.stdout.readlines():
output += line
print line,
retval = p.wait()
self.replyMessage(user, output +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
def command_100_default(self, user, message, args):
'''.*?(?s)(?m)'''
self.replyMessage(user, time.strftime("%Y-%m-%d %a %H:%M:%S", time.localtime()))
if __name__ == "__main__":
bot = RaspiBot()
bot.setState('available', "Raspi Gtalk Robot")
bot.start(BOT_GTALK_USER, BOT_GTALK_PASS)
Mit freundlichen Grüssen
Willhelm