Beispiel #1
0
	def run(self):
		phidget_id = random_phidget_id()
		while True:
			#print 'putting a temp change!'
			global sensor_id
			put_value_change(random_temp(),phidget_id,sensor_id)
			time.sleep(interval)
Beispiel #2
0
 def run(self):
     phidget_id = random_phidget_id()
     while True:
         #print 'putting a temp change!'
         global sensor_id
         put_value_change(random_temp(), phidget_id, sensor_id)
         time.sleep(interval)
def sensorChanged(e):
 device.setOutputState(0,1)
 dev_id = gen_id_val()
 sensor_index = e.index
 sesnor_value = e.value
 #log_info( "Sensor change at %i: %i" % (e.index, e.value))
 values = checkSensors(device,6)
 put_value_change(dev_id,values,True)
 device.setOutputState(0,0)
Beispiel #4
0
            values_dict[n] = 'N/A'

    return values_dict


if __name__ == '__main__':
    #get the id_val of the device
    dev_id = gen_id_val()
    device = connect_phidget()
    #We can use a timer thread for this.. just wanted to keep it simple for
    #my own sake.
    while True:
        sleep(3)
        device.setOutputState(0, 0)
        #getting the IP here, don't really need to do this after some recent updates
        ip_addy = get_local_ip('eth0')
        log_info('IP is: %s' % ip_addy)
        register_device(ip_addy, dev_id)
        sensor_data = check_sensors(device)
        log_info(sensor_data)
        response = put_value_change(dev_id, sensor_data, True)
        if response == 0:
            device.setOutputState(0, 1)
    device.closePhidget()

#Only here to block until user keyboard input, which will end the program.
#character = str(raw_input())

#we have to close the phidget after we are done..
#device.closePhidget()
Checks the range of sensors for the phidget
'''
def checkSensors(device,sensor_number):
	#since we can have up to 8 sensors, we check to all 8 ports
	values_dict={}
	for n in range(0,sensor_number):
		try:
			#print 'checking sensor on %s'%n
			values_dict[n] = device.getSensorValue(n)
		except:
			#print 'no sensor attached to port %s'%n
			values_dict[n] = 'N/A'

	return values_dict

if __name__ == '__main__':
	dev_id = gen_id_val()

	#Connect to the sensors
	device = connectSensors()
	while True:
		sleep(1.5)
		
		device.setOutputState(0,0)
		sensor_data = checkSensors(device,5)
		response = put_value_change(dev_id,sensor_data,True)
		device.setOutputState(0,1)

	device.closePhidget()