def main(): # Get the application data f = open(".access_token", "r") keydata = json.loads(f.read()) # Initiate the moves object m = Moves(keydata) # Initiate the com link with arduino c = Comm() loops = 0 # Run program loop while True: state = 0 # Load date interval currentDate = datetime.datetime.now().strftime("%Y%m%d") oldDate = (datetime.datetime.now() - datetime.timedelta(days=30)).strftime("%Y%m%d") data = m.getRangeSummary(oldDate, currentDate) processor = DataProcessor(data) msg = processor.getDuration() print msg c.send(msg) # Sleep program untill next check time.sleep(30)
def main(): # Get the application data f = open('.access_token', 'r') keydata = json.loads(f.read()) # Initiate the moves object m = Moves(keydata) # Initiate the com link with arduino c = Comm() loops = 0 # Run program loop while True: state = 0 if loops is 0: # Load date interval currentDate = datetime.datetime.now().strftime('%Y%m%d') oldDate = (datetime.datetime.now() - datetime.timedelta(days=30)).strftime('%Y%m%d') data = m.getRangeSummary(oldDate, currentDate) processor = DataProcessor(data) raw = processor.newDataProcessor() if processor.checkMoving(): state = 1 # Check realtime realtime = datetime.datetime.strptime(requests.get('http://studier.albinhubsch.se/lucy-light').text, "%Y-%m-%d %H:%M:%S") now = datetime.datetime.now() if realtime + datetime.timedelta(minutes=10) > now: state = 1 msg = str(state) + ',' + raw c.send(msg) if loops < 10: loops += 1 else: loops = 0 # Sleep program untill next check time.sleep(6)
__dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(__dir + "/model") sys.path.append(__dir + "/utils") sys.path.append(__dir + "/collectors") from Config import Config from Comm import Comm import json config = Config(os.path.dirname(os.path.realpath(__file__)) + "/test/config.json") # TODO collectors = config.getCollectors() inventory = [] for collector_name in collectors: try: module_ = __import__(collector_name) collector = getattr(module_, collector_name)() collector.load() dataset = config.getData(collector_name) for data in dataset: inventory.append(collector.retrieveData()) except: print "No " + collector_name + " collector defined!" comm = Comm("localhost") comm.send(json.dumps(inventory))
while button_flag: try: value = grovepi.digitalRead(button) # 0 not pressed, 1 pressed if value == 1: set button_flag False time.sleep(.5) except TypeError: print(TypeError) except IOError: print(IOError) print('Got button press') #Step 2. Tell both workers open for business worker1.send( {'message': 'ready'} ) print('sent ready to ': + worker1_ip) worker2.send( {'message': 'ready'} ) print('sent ready to ': + worker2_ip) lcd.setRGB(0,128,128) # green time.sleep(2) #long enough to see it go green #Step 3. Wait until receive a signal from both workers waiting_flag1 = True waiting_flag2 = True while waiting_flag1 and waiting_flag2: if waiting_flag1:
def test_comm(self): comm = Comm('localhost') comm.send('test') self.assertTrue(True)
from Comm import Comm #import Server import time neighbor1_ip = Comm("192.168.0.105") neighbor2_ip = Comm("192.168.0.100") neighbor1_ip.send( {'message': 'fyi', 'value': "Test"} ) neighbor2_ip.send( {'message': 'fyi', 'value': "Test"} ) flag1 = True flag2 = True while flag1 and flag2: if flag1: table1 = neighbor1_ip.get_table() print('neighbor1 sent: ' + str( table1 )) flag1 = table1 == [] #if still empty then keep flag True if flag2: table2 = neighbor2_ip.get_table() print('neighbor2 sent: ' + str( table2 )) flag2 = table2 == [] #if still empty then keep flag True time.sleep( .5 ) print( 'got them both' )