Im running it from an ssh terminal on my mac. At first I thought my mac going to sleep was causing the problem but I dont think so because even if the mac goes to sleep, the rpi2 shouldnt. The script is scheduled to fetch data from the web every hour indefinitely. Can anyone tell me if its wrong to make the rpi2 run a scheduled job indefinitely?
Here is the code:
# class to hold read and write
#!/usr/bin/env python
import serial
import logging
import time, datetime
from firebase import firebase
from firebase_token_generator import create_token
from apscheduler.schedulers.blocking import BlockingScheduler
class AIHome:
def __init__(self, onTime, offTime):
self.onTime=onTime
self.offTime=offTime
self.updateInterval = 6
self.webPush = False
self.relayStatesA = []
self.relayStatesD = {}
logging.basicConfig()
print('initting AIHome...scheduling job')
sched = BlockingScheduler()
@sched.scheduled_job('interval', hours=1)
def timed_job():
print('This job runs every 1 hrs. timed_job gets called or something else')
self.fetchUpdate();
sched.configure()
sched.start()
def fetchUpdate(self):
#Must separate credentials
AIHome.authentication = firebase.FirebaseAuthentication('mykey', '[email protected]', extra={'id': 123})
AIHome.firebase = firebase.FirebaseApplication('https://myapp.firebaseio.com/', AIHome.authentication)
print AIHome.authentication.extra
AIHome.user = AIHome.authentication.get_user()
print AIHome.user.firebase_auth_token
AIHome.results = AIHome.firebase.get('/Relays', None)#, {'print': 'pretty'})
print AIHome.results
print AIHome.results['Relay1ON']
print AIHome.results['Relay1OFF']
self.relayToggle()
def relayToggle(self):
timestring = AIHome.results['Relay1ON']
print timestring
hours,minutes = timestring.split(":")
print hours
print minutes
print(datetime.datetime.now())
ref_time = datetime.datetime.combine(datetime.datetime.now(), datetime.time(int(hours), int(minutes)))
if ref_time > datetime.datetime.now():
print("ref_time>relay should be OFF")
else:
print("now>relay should be ON")
x = AIHome(1,2)
Thanks in advance!