Esempio n. 1
0
	authPath = os.path.join(authPath, 'auth.temp')
	with open(authPath, 'r') as f:
		key = f.read()
		key = bytes(key.strip(), 'ascii')

	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	s.connect((TCP_IP, TCP_PORT))
	s.send(bytes([0x02, 0x00, 0x01, 0x00, 0x20]))
	s.send(key)
	s.settimeout(5.0)  # set timeout so we can ping
	return s


if __name__ == "__main__":
	# pwm setup
	pwm = PWM(0x70)
	pwm.setPWM(4, 0, 100)


	loop=255
	s = None
	while(1):
		loop += 1

		if s is None:
			s = connectSocket()

		try:
			data = s.recv(BUFFER_SIZE)

			if( len(data)==0 ):		# this is a disconnect packet, we probably got kicked for being too quick. Let's restart connection
Esempio n. 2
0
            print(line)
            split_line = line.split()
            time_str = split_line[0]
            set_vals = split_line[1:]
            assert len(set_vals) == 4        # Make sure we have just r, g, b, w

            dt = datetime.strptime(time_str, '%H:%M').replace(tzinfo=timezone.utc)
            time = dt.time()   # TODO shouldn't this be est time? the file is in est times...
            dt_after = dt + timedelta(0, 600, 0)        # TODO terrible naming
            time_after = dt_after.time()

            if line in alarmed_list:    # if we have already alarmed
                continue                # skip

            # !!TODO fix this. its a hack so we can set alarms for the next day
            if time_now_est < time or time_now_est > time_after:      # if we are before or more than 10 mins after alarm time
                print("\tpending")
                continue                       # skip 

            print('alarm! now %s for %s' % (time_now_est, time))
            pwm = PWM(0x70)     # TODO this resets the colors!
            for ch, val in enumerate(set_vals):
                pwm.setPWM(ch, 0, int(val))
                pwm.setPWM(ch+4, 0, int(val))

            alarmed_list.append(line)       # TODO document and think. same alarm twice won't be triggered, but different vals will
            with open(ALARMED_FILENAME, 'a') as alarmed_f:
                output_line= "%s\t# activated %s" % (line, dt_now_utc)		# TODO if we add a comment, the line comparison check fails above
                print(line, file=alarmed_f)