Пример #1
0
def sensorDiscoveryService():
	global i2cBus	
	global connected_multiplexer
	global connected_sensor_light
	global connected_sensor_temp
	global connected_sensor_motion
	
	print "Start sensor discovery service..."
	
	while True:
		if exitFlag: return
			
		#Enable multiplexer
		try:
			while (not connected_multiplexer):
				result = ""
				multiplexer = wear_multiplexer.WearMultiplexer(i2cBus)
				connected_multiplexer = True

			if (connected_sensor_temp or connected_sensor_light or connected_sensor_motion):
				pass
				#print "MULTIPLEXER - Device(s) connected"
			else:
				for channel in range(1,17):
					if (connected_multiplexer):
						#Select channel
						try:
							result = multiplexer.setChannel(channel)
							print "MULTIPLEXER - Enabling channel ",channel," in the board... ", result
							
							current_channel = channel
							
							if (not connected_sensor_temp):
								try:
									#Start temperature sensor
									temperatureSensor = wear_sensor_heat.WearSensorHeat(i2cBus)

									#Set precision
									decimals = 4
									result = temperatureSensor.setPrecision(decimals)
					
									connected_sensor_temp = True
									
								except Exception as e: 
									#print "ERROR: HEAT SENSOR - ", e		
									connected_sensor_temp = False

							if (not connected_sensor_light):
								try:
									#Start light sensor
									lightSensor = wear_sensor_light.WearSensorLight(i2cBus)
								
									connected_sensor_light = True
									
								except Exception as e: 	
									#print "ERROR: LIGHT SENSOR - ", e
									connected_sensor_light = False
								
							if (not connected_sensor_motion):
								try:
									#Start motion sensor
									motionSensor = wear_sensor_motion.WearSensorMotion(bus)
								
									connected_sensor_motion = True
									
								except Exception as e: 	
									#print "ERROR: MOTION SENSOR - ", e
									connected_sensor_motion = False
										
							if (connected_sensor_temp or connected_sensor_light or connected_sensor_motion):
								break
								
						except Exception as e: 
							pass
							#print "ERROR: MULTIPLEXER - ", e		
					else:
						break

			#Start reading sensors
			if (connected_sensor_temp):
				try:
					result = temperatureSensor.getTemperature()		
					#print "HEAT SENSOR - Temperature ", result, " C"
				except Exception as e: 
					print "ERROR: HEAT SENSOR - ", e		
					connected_sensor_temp = False
			
			if (connected_sensor_light):
				try: 
					result = lightSensor.getLux()
					#print "LIGHT SENSOR - Lux ", result						
				except Exception as e: 	
					print "ERROR: LIGHT SENSOR - ", e
					connected_sensor_light = False

			if (connected_sensor_motion):
				try: 
					x = motionSensor.getXAxis()		
					y = motionSensor.getYAxis()		
					z = motionSensor.getZAxis()	
					print "MOTION SENSOR - X=", x, ", Y=", y, ", Z=", z						
				except Exception as e: 	
					print "ERROR: MOTION SENSOR - ", e
					connected_sensor_motion = False
					
		except Exception as e: 
			#print "ERROR: MULTIPLEXER - ", e		
			connected_multiplexer = False
Пример #2
0
											time.sleep(1)	
											msg = str(lightSensor.getLux())		
											print "LIGHT SENSOR - Light ", msg, " Lux"													
										except Exception as e: 
											msg = "ERROR: LIGHT SENSOR BOARD NOT CONNECTED"
									except Exception as e: 
										msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"		
								elif data == "GET_MOTION\n":
									try:
										msg = 0
										multiplexerReader = wear_multiplexer_reader.WearMultiplexerReader()
										msg = str(multiplexerReader.getChannel(i2cBus))
										print "MULTIPLEXER READER - Current channel selected ", msg
										time.sleep(1)		
										try:
											motionSensor = wear_sensor_motion.WearSensorMotion(i2cBus)
											time.sleep(1)
											x = motionSensor.getXAxis()		
											y = motionSensor.getYAxis()		
											z = motionSensor.getZAxis()	
											msg = str(x) + "X&" + str(y) + "Y&" + str(z) + "Z"		
											print "MOTION SENSOR - values ", msg												
										except Exception as e: 
											msg = "ERROR: MOTION SENSOR BOARD NOT CONNECTED"
									except Exception as e: 
										msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"												
								elif data == "BOT_STOP\n":
									try:
										print ("Robot - Stop")
										bot.stopBot()
									except Exception as e:
Пример #3
0
def updateBox(command_sent):
    msg = "OK"

    data = command_sent.upper()

    subdata_pos = data.find("%")
    subdata = data[0:subdata_pos]
    subvalue = 0
    #print "character % found at ", subdata_pos, " command ", subdata

    subdata1_pos = data.find("&")
    subdata1 = data[0:subdata1_pos]
    subvalue1 = 0
    if data == "HELLO\n":
        try:
            btn_servers.index(str(client_address[0]))
            print("Existent buttons host. " + str(client_address[0]))
        except Exception as e:
            btn_servers.append(
                str(client_address[0])
            )  #Add a server to the list for receiving updates on buttons
            print("New buttons host added. " + str(client_address[0]))
    elif data == "PLAY1\n":
        pygame.mixer.init()
        pygame.mixer.music.load("/home/pi/BuzzBoards/music1.mp3")
        pygame.mixer.music.play()
    elif data == "PLAY2\n":
        pygame.mixer.init()
        pygame.mixer.music.load("/home/pi/BuzzBoards/music2.mp3")
        pygame.mixer.music.play()
    elif data == "STOP\n":
        pygame.mixer.stop()
        pygame.mixer.music.stop()
        pygame.mixer.quit()
    elif data == "LIGHT1_ON\n":
        print("Lighting set 1 ON")
        box.setLighting1(True, 0, False)
    elif data == "LIGHT1_BLINK\n":
        print("Lighting set 1 BLINK")
        box.setLighting1(True, 0, True)
    elif subdata == "LIGHT1_DIM":  #format for dimmable values LIGHT1_DIM%5
        try:
            subvalue = float(data[subdata_pos + 1:])
        except ValueError:
            msg = "ERROR: INVALID DIM VALUE"
            subvalue = 0
        #print "subvalue=", subvalue
        if subvalue > 100 or subvalue < 0:
            msg = "ERROR: VALUE OUT OF RANGE"
            print("Lighting set 1 DIMMABLE", msg)
        else:
            dim = float(subvalue / 100)
            print("Lighting set 1 DIMMABLE ", subvalue, " % - ", dim)
            box.setLighting1(True, dim, False)
    elif data == "GET_LIGHT1\n":
        msg = box.getLighting1()
        print("Lighting set 1  - Get status ", msg)
    elif data == "LIGHT2_ON\n":
        print("Lighting set 2 ON")
        box.setLighting2(True, 0, False)
    elif data == "LIGHT2_BLINK\n":
        print("Lighting set 2 BLINK")
        box.setLighting2(True, 0, True)
    elif subdata == "LIGHT2_DIM":  #format for dimmable values LIGHT1_DIM%5
        try:
            subvalue = float(data[subdata_pos + 1:])
        except ValueError:
            msg = "ERROR: INVALID DIM VALUE"
            subvalue = 0
        #print "subvalue=", subvalue
        if subvalue > 100 or subvalue < 0:
            msg = "ERROR: VALUE OUT OF RANGE"
            print("Lighting set 2 DIMMABLE", msg)
        else:
            dim = float(subvalue / 100)
            print("Lighting set 2 DIMMABLE ", subvalue, " % - ", dim)
            box.setLighting2(True, dim, False)
    elif data == "GET_LIGHT2\n":
        msg = box.getLighting2()
        print("Lighting set 2  - Get status ", msg)
    elif data == "FAN_ON\n":
        print("Fan ON")
        box.setFan(True)
    elif data == "HEATER_ON\n":
        print("Heater ON")
        box.setHeater(True)
    elif data == "LIGHT1_OFF\n":
        print("Lighting set 1 OFF")
        box.setLighting1(False, 0, False)
    elif data == "LIGHT2_OFF\n":
        print("Lighting set 2 OFF")
        box.setLighting2(False, 0, False)
    elif data == "FAN_OFF\n":
        print("Fan OFF")
        box.setFan(False)
    elif data == "HEATER_OFF\n":
        print("Heater OFF")
        box.setHeater(False)
    elif data == "GET_FAN\n":
        msg = box.getFan()
        print("Fan  - Get status ", msg)
    elif data == "PRESS_BTN1\n":
        msg = buttons.readValueVirtualBtn("BTN1")
        print("Virtual BTN1 - Get status ", msg)
    elif data == "PRESS_BTN2\n":
        msg = buttons.readValueVirtualBtn("BTN2")
        print("Virtual BTN2 - Get status ", msg)
    elif data == "PRESS_BTN3\n":
        msg = buttons.readValueVirtualBtn("BTN3")
        print("Virtual BTN3 - Get status ", msg)
    elif data == "PRESS_BTN4\n":
        msg = buttons.readValueVirtualBtn("BTN4")
        print("Virtual BTN4 - Get status ", msg)
    elif data == "PRESS_BTN5\n":
        msg = buttons.readValueVirtualBtn("BTN5")
        print("Virtual BTN5 - Get status ", msg)
    elif data == "PRESS_BTN6\n":
        msg = buttons.readValueVirtualBtn("BTN6")
        print("Virtual BTN6 - Get status ", msg)
    elif data == "PRESS_BTN7\n":
        msg = buttons.readValueVirtualBtn("BTN7")
        print("Virtual BTN7 - Get status ", msg)
    elif data == "PRESS_BTN8\n":
        msg = buttons.readValueVirtualBtn("BTN8")
        print("Virtual BTN8 - Get status ", msg)
    elif data == "GET_HEATER\n":
        msg = box.getHeater()
        print("Heater  - Get status ", msg)

    elif data == "GET_LED1\n":
        msg = tricolor.getLed1()
        print("Led 1  - Get status ", msg)

    elif data == "GET_LED2\n":
        msg = tricolor.getLed2()
        print("Led 2  - Get status ", msg)

    elif data == "GET_LED3\n":
        msg = tricolor.getLed3()
        print("Led 3  - Get status ", msg)

    elif data == "GET_LED4\n":
        msg = tricolor.getLed4()
        print("Led 4  - Get status ", msg)

    elif data == "GET_LED5\n":
        msg = tricolor.getLed5()
        print("Led 5  - Get status ", msg)

    elif data == "GET_LED6\n":
        msg = tricolor.getLed6()
        print("Led 6  - Get status ", msg)

    elif data == "GET_LED7\n":
        msg = tricolor.getLed7()
        print("Led 7  - Get status ", msg)

    elif data == "GET_LED8\n":
        msg = tricolor.getLed8()
        print("Led 8  - Get status ", msg)

    elif data == "LED1_R\n":
        print("Led 1 RED")
        tricolor.turnOnLed(1, 2)

    elif data == "LED1_G\n":
        print("Led 1 GREEN")
        tricolor.turnOnLed(1, 1)

    elif data == "LED1_Y\n":
        print("Led 1 YELLOW")
        tricolor.turnOnLed(1, 0)

    elif data == "LED1_OFF\n":
        print("Led 1 OFF")
        tricolor.turnOnLed(1, 3)

    elif data == "LED2_R\n":
        print("Led 2 RED")
        tricolor.turnOnLed(2, 2)

    elif data == "LED2_G\n":
        print("Led 2 GREEN")
        tricolor.turnOnLed(2, 1)

    elif data == "LED2_Y\n":
        print("Led 2 YELLOW")
        tricolor.turnOnLed(2, 0)

    elif data == "LED2_OFF\n":
        print("Led 2 OFF")
        tricolor.turnOnLed(2, 3)

    elif data == "LED3_R\n":
        print("Led 3 RED")
        tricolor.turnOnLed(3, 2)

    elif data == "LED3_G\n":
        print("Led 3 GREEN")
        tricolor.turnOnLed(3, 1)

    elif data == "LED3_Y\n":
        print("Led 3 YELLOW")
        tricolor.turnOnLed(3, 0)

    elif data == "LED3_OFF\n":
        print("Led 3 OFF")
        tricolor.turnOnLed(3, 3)

    elif data == "LED4_R\n":
        print("Led 4 RED")
        tricolor.turnOnLed(4, 2)

    elif data == "LED4_G\n":
        print("Led 4 GREEN")
        tricolor.turnOnLed(4, 1)

    elif data == "LED4_Y\n":
        print("Led 4 YELLOW")
        tricolor.turnOnLed(4, 0)

    elif data == "LED4_OFF\n":
        print("Led 4 OFF")
        tricolor.turnOnLed(4, 3)

    elif data == "LED5_R\n":
        print("Led 5 RED")
        tricolor.turnOnLed(5, 2)

    elif data == "LED5_G\n":
        print("Led 5 GREEN")
        tricolor.turnOnLed(5, 1)

    elif data == "LED5_Y\n":
        print("Led 5 YELLOW")
        tricolor.turnOnLed(5, 0)

    elif data == "LED5_OFF\n":
        print("Led 5 OFF")
        tricolor.turnOnLed(5, 3)

    elif data == "LED6_R\n":
        print("Led 6 RED")
        tricolor.turnOnLed(6, 2)

    elif data == "LED6_G\n":
        print("Led 6 GREEN")
        tricolor.turnOnLed(6, 1)

    elif data == "LED6_Y\n":
        print("Led 6 YELLOW")
        tricolor.turnOnLed(6, 0)

    elif data == "LED6_OFF\n":
        print("Led 6 OFF")
        tricolor.turnOnLed(6, 3)

    elif data == "LED7_R\n":
        print("Led 7 RED")
        tricolor.turnOnLed(7, 2)

    elif data == "LED7_G\n":
        print("Led 7 GREEN")
        tricolor.turnOnLed(7, 1)

    elif data == "LED7_Y\n":
        print("Led 7 YELLOW")
        tricolor.turnOnLed(7, 0)

    elif data == "LED7_OFF\n":
        print("Led 7 OFF")
        tricolor.turnOnLed(7, 3)

    elif data == "LED8_R\n":
        print("Led 8 RED")
        tricolor.turnOnLed(8, 2)

    elif data == "LED8_G\n":
        print("Led 8 GREEN")
        tricolor.turnOnLed(8, 1)

    elif data == "LED8_Y\n":
        print("Led 8 YELLOW")
        tricolor.turnOnLed(8, 0)

    elif data == "LED8_OFF\n":
        print("Led 8 OFF")
        tricolor.turnOnLed(8, 3)

    elif data == "GET_CHANNEL\n":
        try:
            #if (connected_multiplexer):
            msg = 0
            multiplexerReader = wear_multiplexer_reader.WearMultiplexerReader()
            msg = str(multiplexerReader.getChannel(i2cBus))
            print "MULTIPLEXER READER - Current channel selected ", msg

            #else:
            #	msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
        except Exception as e:
            msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
    elif data == "GET_TEMPERATURE\n":
        try:
            msg = 0
            multiplexerReader = wear_multiplexer_reader.WearMultiplexerReader()
            msg = str(multiplexerReader.getChannel(i2cBus))
            print "MULTIPLEXER READER - Current channel selected ", msg

            try:
                temperatureSensor = wear_sensor_heat.WearSensorHeat(i2cBus)
                read_val = temperatureSensor.setPrecision(4)
                msg = str(temperatureSensor.getTemperature())
                print "HEAT SENSOR - Temperature ", msg, " C"
            except Exception as e:
                msg = "ERROR: HEAT SENSOR BOARD NOT CONNECTED"
        except Exception as e:
            msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
    elif data == "GET_LUX\n":
        try:
            msg = 0
            multiplexerReader = wear_multiplexer_reader.WearMultiplexerReader()
            msg = str(multiplexerReader.getChannel(i2cBus))
            print "MULTIPLEXER READER - Current channel selected ", msg

            try:
                #if (connected_sensor_light):
                lightSensor = wear_sensor_light.WearSensorLight(i2cBus)

                msg = str(lightSensor.getLux())
                print "LIGHT SENSOR - Light ", msg, " Lux"
            except Exception as e:
                msg = "ERROR: LIGHT SENSOR BOARD NOT CONNECTED"
        except Exception as e:
            msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
    elif data == "GET_MOTION\n":
        try:
            msg = 0
            multiplexerReader = wear_multiplexer_reader.WearMultiplexerReader()
            msg = str(multiplexerReader.getChannel(i2cBus))
            print "MULTIPLEXER READER - Current channel selected ", msg

            try:
                motionSensor = wear_sensor_motion.WearSensorMotion(i2cBus)

                x = motionSensor.getXAxis()
                y = motionSensor.getYAxis()
                z = motionSensor.getZAxis()
                msg = str(x) + "X&" + str(y) + "Y&" + str(z) + "Z"
                print "MOTION SENSOR - values ", msg
            except Exception as e:
                msg = "ERROR: MOTION SENSOR BOARD NOT CONNECTED"
        except Exception as e:
            msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
    else:
        msg = "ERROR: WRONG CODE"
    print msg
    """			
	elif subdata == "SET_CHANNEL":  #format to set an specific channel on the multiplexer board SETCHANNEL%1
		if (connected_multiplexer):
			try:
				subvalue = float (data[subdata_pos+1:])
				#print "subvalue =", subvalue
				
				if subvalue < 1 or subvalue > 16:
					msg = "ERROR: VALUE OUT OF RANGE"			
					print ("Multiplexer board SET CHANNEL - ", msg)			
				else:
					result = multiplexer.setChannel(subvalue)
					print "MULTIPLEXER board - Enabling channel ",subvalue," in the board... ", result
					#time.sleep(1) 										
			except ValueError:
				msg = "ERROR: INVALID CHANNEL VALUE"
		else:
			msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
	"""
    """
	elif data == "BOT_STOP\n":
		if (connected_bot):
			print ("Robot - Stop")
			bot.stopBot()
		else:
			msg = "ERROR: BOT BOARD NOT CONNECTED"
	elif data == "BOT_FORWARD\n":
		print ("Robot - Move forward")
		bot.stopBot()
		# Move forward then stop
		bot.moveByStep(0,5)							
	elif data == "BOT_BACKWARD\n":
		print ("Robot - Move backward")
		bot.stopBot()
		# Move forward then stop
		bot.moveByStep(-5,0)	
	elif data == "7DISPLAY_OFF\n":
		print ("7 segment display - Clean display")
		display.clean()
	elif subdata1 == "7DISPLAY_ON":  #format for values 7DISPLAY_ON&1234
		try:
			subvalue1 = data[subdata1_pos+1:]
		except ValueError:
			msg = "ERROR: INVALID VALUE"
			subvalue1 = 0
		#print "subvalue1=", subvalue1
		if subvalue1 == "":
			msg = "ERROR: NO NUMBER TO DISPLAY"			
			print ("7 segment display - ", msg)			
		else:
			display.clean()
			display.showValue (n)
			print ("7 segment display - ", subvalue1)
	else:
		msg = "ERROR: WRONG CODE"
		print msg
	"""
    return msg
Пример #4
0
                                if (not connected_sensor_light):
                                    try:
                                        #Start light sensor
                                        lightSensor = wear_sensor_light.WearSensorLight(
                                            bus)
                                        connected_sensor_light = True

                                    except Exception as e:
                                        #print "ERROR: LIGHT SENSOR - ", e
                                        connected_sensor_light = False

                                if (not connected_sensor_motion):
                                    try:
                                        #Start motion sensor
                                        motionSensor = wear_sensor_motion.WearSensorMotion(
                                            bus)
                                        connected_sensor_motion = True

                                    except Exception as e:
                                        #print "ERROR: MOTION SENSOR - ", e
                                        connected_sensor_motion = False

                                if (connected_sensor_temp
                                        or connected_sensor_light
                                        or connected_sensor_motion):
                                    break

                            except Exception as e:
                                print "ERROR: MULTIPLEXER - ", e
                        else:
                            break
Пример #5
0
    def sensorDiscoveryService(self):
        global i2cBus
        global multiplexer
        global temperatureSensor
        global lightSensor
        global motionSensor
        global connected_multiplexer
        global connected_sensor_light
        global connected_sensor_temp
        global connected_sensor_motion
        global current_channel

        #print ("sensorDiscoveryService running......")
        if (connected_sensor_temp or connected_sensor_light
                or connected_sensor_motion):
            pass
        else:
            print("sensorDiscoveryService running......")
            for channel in range(1, 17):
                try:
                    result = multiplexer.setChannel(channel)
                    print("MULTIPLEXER - Enabling channel ", channel,
                          " in the board... ", result)

                    current_channel = channel

                    if (not connected_sensor_temp):
                        try:
                            #Start temperature sensor
                            temperatureSensor = wear_sensor_heat.WearSensorHeat(
                                i2cBus)

                            #Set precision
                            decimals = 4
                            result = temperatureSensor.setPrecision(decimals)
                            connected_sensor_temp = True

                        except Exception as e:
                            #print "ERROR: HEAT SENSOR - ", e
                            connected_sensor_temp = False

                    if (not connected_sensor_light):
                        try:
                            #Start light sensor
                            lightSensor = wear_sensor_light.WearSensorLight(
                                i2cBus)
                            connected_sensor_light = True

                        except Exception as e:
                            #print "ERROR: LIGHT SENSOR - ", e
                            connected_sensor_light = False

                    if (not connected_sensor_motion):
                        try:
                            #Start motion sensor
                            motionSensor = wear_sensor_motion.WearSensorMotion(
                                bus)
                            connected_sensor_motion = True

                        except Exception as e:
                            #print "ERROR: MOTION SENSOR - ", e
                            connected_sensor_motion = False

                    if (connected_sensor_temp or connected_sensor_light
                            or connected_sensor_motion):
                        break

                except Exception as e:
                    pass

        #Start reading sensors
        if (connected_sensor_temp):
            try:
                result = temperatureSensor.getTemperature()
                #print ("HEAT SENSOR - Temperature ", result, " C")
            except Exception as e:
                #print ("ERROR: HEAT SENSOR - ", e)
                connected_sensor_temp = False

        if (connected_sensor_light):
            try:
                result = lightSensor.getLux()
                #print ("LIGHT SENSOR - Lux ", result)
            except Exception as e:
                #print ("ERROR: LIGHT SENSOR - ", e)
                connected_sensor_light = False

        if (connected_sensor_motion):
            try:
                x = motionSensor.getXAxis()
                y = motionSensor.getYAxis()
                z = motionSensor.getZAxis()
                #print ("MOTION SENSOR - X=", x, ", Y=", y, ", Z=", z)
            except Exception as e:
                #print ("ERROR: MOTION SENSOR - ", e)
                connected_sensor_motion = False
Пример #6
0
    def get_BUZZBOX_STATUS(self, data):
        global i2cBus
        global box
        global tricolor
        global buttons
        global multiplexer
        global temperatureSensor
        global lightSensor
        global motionSensor
        global connected_multiplexer
        global connected_sensor_light
        global connected_sensor_temp
        global connected_sensor_motion
        global current_channel
        global btn_servers

        #Evaluates data
        data = data.upper()
        msg = "OK"

        subdata_pos = data.find("%")
        subdata = data[0:subdata_pos]
        subvalue = 0
        #print "character % found at ", subdata_pos, " command ", subdata

        subdata1_pos = data.find("&")
        subdata1 = data[0:subdata1_pos]
        subvalue1 = 0
        if data == "HELLO\n":
            try:
                btn_servers.index(self._peer.host)
                print("Existent buttons host. ", self._peer.host)
            except Exception as e:
                btn_servers.append(
                    self._peer.host
                )  #Add a server to the list for receiving updates on buttons
                print("New buttons host added. ", self._peer.host)
        elif data == "PLAY1\n":
            pygame.mixer.init()
            pygame.mixer.music.load("/home/pi/BuzzBoards/music1.mp3")
            pygame.mixer.music.play()
        elif data == "PLAY2\n":
            pygame.mixer.init()
            pygame.mixer.music.load("/home/pi/BuzzBoards/music2.mp3")
            pygame.mixer.music.play()
        elif data == "STOP\n":
            pygame.mixer.stop()
            pygame.mixer.music.stop()
            pygame.mixer.quit()
        elif data == "LIGHT1_ON\n":
            print("Lighting set 1 ON")
            box.setLighting1(True, 0, False)
        elif data == "LIGHT1_BLINK\n":
            print("Lighting set 1 BLINK")
            box.setLighting1(True, 0, True)
        elif subdata == "LIGHT1_DIM":  #format for dimmable values LIGHT1_DIM%5
            try:
                subvalue = float(data[subdata_pos + 1:])
            except ValueError:
                msg = "ERROR: INVALID DIM VALUE"
                subvalue = 0
            #print "subvalue=", subvalue
            if subvalue > 100 or subvalue < 0:
                msg = "ERROR: VALUE OUT OF RANGE"
                print("Lighting set 1 DIMMABLE", msg)
            else:
                dim = float(subvalue / 100)
                print("Lighting set 1 DIMMABLE ", subvalue, " % - ", dim)
                box.setLighting1(True, dim, False)
        elif data == "GET_LIGHT1\n":
            msg = box.getLighting1()
            print("Lighting set 1  - Get status ", msg)
        elif data == "LIGHT2_ON\n":
            print("Lighting set 2 ON")
            box.setLighting2(True, 0, False)
        elif data == "LIGHT2_BLINK\n":
            print("Lighting set 2 BLINK")
            box.setLighting2(True, 0, True)
        elif subdata == "LIGHT2_DIM":  #format for dimmable values LIGHT1_DIM%5
            try:
                subvalue = float(data[subdata_pos + 1:])
            except ValueError:
                msg = "ERROR: INVALID DIM VALUE"
                subvalue = 0
            #print "subvalue=", subvalue
            if subvalue > 100 or subvalue < 0:
                msg = "ERROR: VALUE OUT OF RANGE"
                print("Lighting set 2 DIMMABLE", msg)
            else:
                dim = float(subvalue / 100)
                print("Lighting set 2 DIMMABLE ", subvalue, " % - ", dim)
                box.setLighting2(True, dim, False)
        elif data == "GET_LIGHT2\n":
            msg = box.getLighting2()
            print("Lighting set 2  - Get status ", msg)
        elif data == "FAN_ON\n":
            print("Fan ON")
            box.setFan(True)
        elif data == "HEATER_ON\n":
            print("Heater ON")
            box.setHeater(True)
        elif data == "LIGHT1_OFF\n":
            print("Lighting set 1 OFF")
            box.setLighting1(False, 0, False)
        elif data == "LIGHT2_OFF\n":
            print("Lighting set 2 OFF")
            box.setLighting2(False, 0, False)
        elif data == "FAN_OFF\n":
            print("Fan OFF")
            box.setFan(False)
        elif data == "HEATER_OFF\n":
            print("Heater OFF")
            box.setHeater(False)
        elif data == "GET_FAN\n":
            msg = box.getFan()
            print("Fan  - Get status ", msg)
        elif data == "GET_HEATER\n":
            msg = box.getHeater()
            print("Heater  - Get status ", msg)
        elif data == "PRESS_BTN1\n":
            msg = buttons.readValueVirtualBtn("BTN1")
            print("Virtual BTN1 - Get status ", msg)
        elif data == "PRESS_BTN2\n":
            msg = buttons.readValueVirtualBtn("BTN2")
            print("Virtual BTN2 - Get status ", msg)
        elif data == "PRESS_BTN3\n":
            msg = buttons.readValueVirtualBtn("BTN3")
            print("Virtual BTN3 - Get status ", msg)
        elif data == "PRESS_BTN4\n":
            msg = buttons.readValueVirtualBtn("BTN4")
            print("Virtual BTN4 - Get status ", msg)
        elif data == "PRESS_BTN5\n":
            msg = buttons.readValueVirtualBtn("BTN5")
            print("Virtual BTN5 - Get status ", msg)
        elif data == "PRESS_BTN6\n":
            msg = buttons.readValueVirtualBtn("BTN6")
            print("Virtual BTN6 - Get status ", msg)
        elif data == "PRESS_BTN7\n":
            msg = buttons.readValueVirtualBtn("BTN7")
            print("Virtual BTN7 - Get status ", msg)
        elif data == "PRESS_BTN8\n":
            msg = buttons.readValueVirtualBtn("BTN8")
            print("Virtual BTN8 - Get status ", msg)
        elif data == "GET_LED1\n":
            msg = tricolor.getLed1()
            print("Led 1  - Get status ", msg)
        elif data == "GET_LED2\n":
            msg = tricolor.getLed2()
            print("Led 2  - Get status ", msg)
        elif data == "GET_LED3\n":
            msg = tricolor.getLed3()
            print("Led 3  - Get status ", msg)
        elif data == "GET_LED4\n":
            msg = tricolor.getLed4()
            print("Led 4  - Get status ", msg)
        elif data == "GET_LED5\n":
            msg = tricolor.getLed5()
            print("Led 5  - Get status ", msg)
        elif data == "GET_LED6\n":
            msg = tricolor.getLed6()
            print("Led 6  - Get status ", msg)
        elif data == "GET_LED7\n":
            msg = tricolor.getLed7()
            print("Led 7  - Get status ", msg)
        elif data == "GET_LED8\n":
            msg = tricolor.getLed8()
            print("Led 8  - Get status ", msg)
        elif data == "LED1_R\n":
            print("Led 1 RED")
            tricolor.turnOnLed(1, 2)
        elif data == "LED1_G\n":
            print("Led 1 GREEN")
            tricolor.turnOnLed(1, 1)
        elif data == "LED1_Y\n":
            print("Led 1 YELLOW")
            tricolor.turnOnLed(1, 0)
        elif data == "LED1_OFF\n":
            print("Led 1 OFF")
            tricolor.turnOnLed(1, 3)
        elif data == "LED2_R\n":
            print("Led 2 RED")
            tricolor.turnOnLed(2, 2)
        elif data == "LED2_G\n":
            print("Led 2 GREEN")
            tricolor.turnOnLed(2, 1)
        elif data == "LED2_Y\n":
            print("Led 2 YELLOW")
            tricolor.turnOnLed(2, 0)
        elif data == "LED2_OFF\n":
            print("Led 2 OFF")
            tricolor.turnOnLed(2, 3)
        elif data == "LED3_R\n":
            print("Led 3 RED")
            tricolor.turnOnLed(3, 2)
        elif data == "LED3_G\n":
            print("Led 3 GREEN")
            tricolor.turnOnLed(3, 1)
        elif data == "LED3_Y\n":
            print("Led 3 YELLOW")
            tricolor.turnOnLed(3, 0)
        elif data == "LED3_OFF\n":
            print("Led 3 OFF")
            tricolor.turnOnLed(3, 3)
        elif data == "LED4_R\n":
            print("Led 4 RED")
            tricolor.turnOnLed(4, 2)
        elif data == "LED4_G\n":
            print("Led 4 GREEN")
            tricolor.turnOnLed(4, 1)
        elif data == "LED4_Y\n":
            print("Led 4 YELLOW")
            tricolor.turnOnLed(4, 0)
        elif data == "LED4_OFF\n":
            print("Led 4 OFF")
            tricolor.turnOnLed(4, 3)
        elif data == "LED5_R\n":
            print("Led 5 RED")
            tricolor.turnOnLed(5, 2)
        elif data == "LED5_G\n":
            print("Led 5 GREEN")
            tricolor.turnOnLed(5, 1)
        elif data == "LED5_Y\n":
            print("Led 5 YELLOW")
            tricolor.turnOnLed(5, 0)
        elif data == "LED5_OFF\n":
            print("Led 5 OFF")
            tricolor.turnOnLed(5, 3)
        elif data == "LED6_R\n":
            print("Led 6 RED")
            tricolor.turnOnLed(6, 2)
        elif data == "LED6_G\n":
            print("Led 6 GREEN")
            tricolor.turnOnLed(6, 1)
        elif data == "LED6_Y\n":
            print("Led 6 YELLOW")
            tricolor.turnOnLed(6, 0)
        elif data == "LED6_OFF\n":
            print("Led 6 OFF")
            tricolor.turnOnLed(6, 3)
        elif data == "LED7_R\n":
            print("Led 7 RED")
            tricolor.turnOnLed(7, 2)
        elif data == "LED7_G\n":
            print("Led 7 GREEN")
            tricolor.turnOnLed(7, 1)
        elif data == "LED7_Y\n":
            print("Led 7 YELLOW")
            tricolor.turnOnLed(7, 0)
        elif data == "LED7_OFF\n":
            print("Led 7 OFF")
            tricolor.turnOnLed(7, 3)
        elif data == "LED8_R\n":
            print("Led 8 RED")
            tricolor.turnOnLed(8, 2)
        elif data == "LED8_G\n":
            print("Led 8 GREEN")
            tricolor.turnOnLed(8, 1)
        elif data == "LED8_Y\n":
            print("Led 8 YELLOW")
            tricolor.turnOnLed(8, 0)
        elif data == "LED8_OFF\n":
            print("Led 8 OFF")
            tricolor.turnOnLed(8, 3)
        elif data == "GET_CHANNEL\n":
            try:
                msg = 0
                msg = str(multiplexer.getChannel(i2cBus))
                print "MULTIPLEXER - Current channel selected ", msg
            except Exception as e:
                msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
        elif data == "GET_TEMPERATURE\n":
            try:
                msg = 0
                msg = str(multiplexer.getChannel(i2cBus))
                #print "MULTIPLEXER - Current channel selected ", msg
                try:
                    temperatureSensor = wear_sensor_heat.WearSensorHeat(i2cBus)
                    read_val = temperatureSensor.setPrecision(4)
                    msg = str(temperatureSensor.getTemperature())
                    print "HEAT SENSOR - Temperature ", msg, " C"
                except Exception as e:
                    msg = "ERROR: HEAT SENSOR BOARD NOT CONNECTED"
            except Exception as e:
                msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
        elif data == "GET_LUX\n":
            try:
                msg = 0
                msg = str(multiplexer.getChannel(i2cBus))
                #print "MULTIPLEXER - Current channel selected ", msg
                try:
                    lightSensor = wear_sensor_light.WearSensorLight(i2cBus)
                    msg = str(lightSensor.getLux())
                    print "LIGHT SENSOR - Light ", msg, " Lux"
                except Exception as e:
                    msg = "ERROR: LIGHT SENSOR BOARD NOT CONNECTED"
            except Exception as e:
                msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
        elif data == "GET_MOTION\n":
            try:
                msg = 0
                msg = str(multiplexer.getChannel(i2cBus))
                #print "MULTIPLEXER - Current channel selected ", msg
                try:
                    motionSensor = wear_sensor_motion.WearSensorMotion(i2cBus)
                    x = motionSensor.getXAxis()
                    y = motionSensor.getYAxis()
                    z = motionSensor.getZAxis()
                    msg = str(x) + "X&" + str(y) + "Y&" + str(z) + "Z"
                    print "MOTION SENSOR - values ", msg
                except Exception as e:
                    msg = "ERROR: MOTION SENSOR BOARD NOT CONNECTED"
            except Exception as e:
                msg = "ERROR: MULTIPLEXER BOARD NOT CONNECTED"
        else:
            msg = "ERROR: WRONG CODE"

        print("Result: ", msg + "\n")
        self.handle_MESSAGE(msg + "\n")