Hi John, thanks for answer
no, i dont use VPN. Now I changed the Code :
#These are the imports google said to include
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import gdata.calendar
import atom
import getopt
import sys
import string
import time
import logging # used for development. Not needed for normal usage.
logging.basicConfig(filename='alarm.log', filemode='w')
import xe #for the time comparator
from feed.date.rfc3339 import tf_from_timestamp #also for the comparator
from datetime import datetime #for the time on the rpi end
from apscheduler.scheduler import Scheduler #this will let us check the calender on a regular interval
import os, random #to play the mp3 later
import multiprocessing
from random import randint
from BrickPi import *
import subprocess
#this is more stuff google told me to do, but essentially it handles the login credentials
calendar_service = gdata.calendar.service.CalendarService()
calendar_service.email = 'email' #your email
calendar_service.password = 'password' #your password
calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
calendar_service.ProgrammaticLogin()
#*****************************************
#Alarm processing starts
#To stop the output when playing the alarm
devnull = open('/dev/null', 'w')
#Plays the alarm
def play_alarm(num):
while(1):
subprocess.call(["mpg321", "alarm_sound.mp3"],stdout=devnull,stderr=devnull)
#return
#Move the bot forward and turns 90 degree if an obstacle is encountered
#Stops when a touch sensor is pressed on Port 1 or 2
def wait_inp(num):
ot = time.time()
while True:
#Move Motors
power = -150
BrickPi.MotorEnable[PORT_A]=1
BrickPi.MotorEnable[PORT_D]=1
BrickPi.MotorSpeed[PORT_A] = power
BrickPi.MotorSpeed[PORT_D] = power
result = BrickPiUpdateValues()
#Get values from both touch sensors and ultrasonic sensor
b1=BrickPi.Sensor[PORT_1]
b2=BrickPi.Sensor[PORT_2]
udist=BrickPi.Sensor[PORT_4]
#print udist
#Return to main if any touch sensor is pressed
if b1 or b2:
return
#If the US sensor reads less than 20cm and the new distance value is older by 5secs, rotate 90 degrees
#(New value checked because while rotating, the US sensor would read less that threshold for a few secs)
if int(udist)<200 and time.time() - ot > 5:
ot = time.time()
power1=[-150,-150]
deg=[110,-110]
port=[PORT_A,PORT_D]
motorRotateDegree(power1,deg,port,.1)
time.sleep(.1) # sleep for 10 ms
#Alarm processing ends
#*****************************************
def FullTextQuery(calendar_service, text_query='wake1'):
print 'Full text query for events on Primary Calendar: '%s'' % ( text_query,)
query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full', text_query)
feed = calendar_service.CalendarQuery(query)
for i, an_event in enumerate(feed.entry):
for a_when in an_event.when:
print "---"
print an_event.title.text ,"Number:",i,"Event Time:",time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.start_time))),"Current Time:",time.strftime('%d-%m-%Y %H:%M')
if time.strftime('%d-%m-%Y %H:%M',time.localtime(tf_from_timestamp(a_when.start_time))) == time.strftime('%d-%m-%Y %H:%M'):
print "Comparison: Pass"
print "---"
while True:
BrickPiSetup()
#Set up motors, US sensor and touch sensors
BrickPi.MotorEnable[PORT_A] = 1 #Enable the Motor A
BrickPi.MotorEnable[PORT_D] = 1 #Enable the Motor B
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_ULTRASONIC_CONT
BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH #Set the type of sensor at PORT_1
BrickPi.SensorType[PORT_2] = TYPE_SENSOR_TOUCH
BrickPiSetupSensors() #Send the properties of sensors to BrickPi
#Set timeout
BrickPi.Timeout=1000
BrickPiSetTimeout()
#Start two parallel processes
jobs = []
#Start alarm process
p1 = multiprocessing.Process(target=play_alarm, args=(0,))
jobs.append(p1)
p1.start()
#Start motor run process
p3 = multiprocessing.Process(target=wait_inp, args=(1,))
jobs.append(p3)
p3.start()
#The motor run process returns when any button is pressed
p3.join()
#Terminate the alarm process when any button press is recieved
p1.terminate()
#Button 1: Snooze
#Button 2: Turn Off alarm
result = BrickPiUpdateValues()
b1=BrickPi.Sensor[PORT_1]
b2=BrickPi.Sensor[PORT_2]
print b1,b2
#Kill the alarm that is already running
p = subprocess.Popen(['pidof', 'mpg321'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.split(" "):
os.kill(int(line), 9)
#If button 1 is pressed then snooze for 5 minutes
if b1:
print "Snooze for 5 mins"
time.sleep(300)
#If button 2 is pressed then stop the alarm
if b2:
print "exit:"
return
else:
print "Comparison:Fail" #the "wake" event's start time != the system's current time
def callable_func():
os.system("clear") #this is more for my benefit and is in no way necesarry
print "------------start-----------"
FullTextQuery(calendar_service)
print "-------------end------------"
scheduler = Scheduler(standalone=True)
scheduler.add_interval_job(callable_func,seconds=5)
scheduler.start() #runs the program indefinatly on an interval of 5 seconds
#while True:
# callable_func()
# time.sleep(60)
Instead ‘email’ I wrote my email from google.And instead ‘password’ I wrote my password to log in to Google. Now I get only the message:
------------start-----------
Full text query for events on Primary Calendar: 'wake1'
Ok, now i have the same error in a logfile.
If I use not my password, email, its the same
EDIT: With the original code in the example it doesnt work too. Must I change more than my email and password?