예제 #1
0
class RGBResource:
    def __init__(self):
        self.rgb = (0, 0, 0)
        self.blinkm = BlinkM()
        self.blinkm.reset()

    def _send_reponse(self, resp):
        red, green, blue = self.rgb
        body = {
            "red": self.rgb[0],
            "green": self.rgb[1],
            "blue": self.rgb[2]
        }
        resp.body = json.dumps(body)

    def on_get(self, req, resp):
        self._send_reponse(resp)

    def on_post(self, req, resp):
        body = req.stream.read()
        data = json.loads(body.decode('utf-8'))
        self.rgb = (
            data['red'],
            data['green'],
            data['blue']
        )

        self.blinkm.fade_to(
            self.rgb[0],
            self.rgb[1],
            self.rgb[2]
        )
        self._send_reponse(resp)
예제 #2
0
파일: aquapi.py 프로젝트: dubhunter/aqua-pi
    def __init__(self):
        self.log('AquaPi initializing...')

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(PIN_POWER, GPIO.OUT)

        self.led = BlinkM()
        self.led.reset()
        self.led.set_fade_speed(self.led_fade_speed)
        # self.led.write_script_line(Scripts.TRANSFER, 0, 10, 'c', 0xff, 0xff, 0xff)
        # self.led.write_script_line(Scripts.TRANSFER, 1, 10, 'c', 0x00, 0x00, 0x00)

        self.spi = spidev.SpiDev()
        self.spi.open(0, SPI_ADC)

        self.sio = serial.Serial('/dev/ttyAMA0', 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 1)

        self.sensor_temp = TempSensor(self.spi, ADC_TEMP)
        self.sensor_light = AnalogSensor(self.spi, ADC_LIGHT)
        self.sensor_liquid = SerialSensor(self.sio)

        self.metro_sensor_sample = Metro(500)
        self.metro_sensor_send = Metro(30000)
        self.metro_poll = Metro(6000)
        self.metro_health = Metro(180000)

        self.events = deque()
        self.running = False
        self.current_color = False

        self.happy()
예제 #3
0
	def __init__(self, name):
		#so we can have many different leds
		self.name = name
		self.led = BlinkM()
		self.delay(2)
		self.led.reset()
		self.delay(1)
		self.led.set_fade_speed(32)
		self.delay(1)
예제 #4
0
파일: aquapi.py 프로젝트: dubhunter/aqua-pi
class AquaPi:
    DEBUG = False
    HOST = 'http://aqua.willandchi.com'
    ENDPOINT_POLL = '/v1/poll'
    ENDPOINT_EVENT = '/v1/events'
    timeout = 5
    led_fade_speed = 64

    def __init__(self):
        self.log('AquaPi initializing...')

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(PIN_POWER, GPIO.OUT)

        self.led = BlinkM()
        self.led.reset()
        self.led.set_fade_speed(self.led_fade_speed)
        # self.led.write_script_line(Scripts.TRANSFER, 0, 10, 'c', 0xff, 0xff, 0xff)
        # self.led.write_script_line(Scripts.TRANSFER, 1, 10, 'c', 0x00, 0x00, 0x00)

        self.spi = spidev.SpiDev()
        self.spi.open(0, SPI_ADC)

        self.sio = serial.Serial('/dev/ttyAMA0', 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE, 1)

        self.sensor_temp = TempSensor(self.spi, ADC_TEMP)
        self.sensor_light = AnalogSensor(self.spi, ADC_LIGHT)
        self.sensor_liquid = SerialSensor(self.sio)

        self.metro_sensor_sample = Metro(500)
        self.metro_sensor_send = Metro(30000)
        self.metro_poll = Metro(6000)
        self.metro_health = Metro(180000)

        self.events = deque()
        self.running = False
        self.current_color = False

        self.happy()

    def loop(self):
        self.log("Loop...")

        if self.metro_health.check():
            self.log("Health checks are failing. I'm sad :(")
            self.sad()
            self.event('error', 'health-check-failure')

        if self.metro_sensor_sample.check():
            self.log("Sampling sensors...")
            self.sensor_temp.read()
            self.sensor_light.read()
            self.sensor_liquid.read()

        if self.metro_sensor_send.check():
            self.log("Creating sensor events...")

            # Temperature Sensor
            self.event('temp', round(self.sensor_temp.fahrenheit(), 2))

            # Light Sensor
            self.event('light', self.sensor_light.value())

            # Ultrasonic Range Finder
            self.event('liquid', round((URF_EMPTY - self.sensor_liquid.value()) / (URF_EMPTY - URF_FULL) * 100.0, 2))

        if self.metro_poll.check():
            self.poll()

        self.send_events()

        time.sleep(0.1)

    def poll(self):
        self.log('Polling...')

        self.led_script(Scripts.TRANSFER)
        self.current_color = colors.white

        try:
            r = requests.get(self.HOST + self.ENDPOINT_POLL,
                             auth=(credentials.username, credentials.password),
                             timeout=self.timeout)
            self.log(r.text)

            if r.status_code == 200:
                data = r.json()
                if len(data):
                    self.power(data['power'] == 'on')

                self.metro_health.reset()
                self.happy()
            else:
                self.log('Polling non-200 response')
                self.event('error', 'poll-non-200')
                self.sad()

        except requests.RequestException:
            self.log('Polling failed')
            self.event('error', 'poll-exception')
            self.sad()

    def send_events(self):
        if len(self.events) > 0:
            self.log('Sending event...')

            event = self.events.popleft()
            self.log(json.dumps(event))

            self.led_script(Scripts.TRANSFER)
            self.current_color = colors.white

            try:
                r = requests.post(self.HOST + self.ENDPOINT_EVENT,
                                  data=event,
                                  auth=(credentials.username, credentials.password),
                                  timeout=self.timeout)
                if r.status_code == 200:
                    self.metro_health.reset()
                    self.happy()
                else:
                    self.log('Sending event non-200 response')
                    self.event('error', 'event-non-200')
                    self.sad()

            except requests.RequestException:
                self.events.appendleft(event)
                self.log('Sending event failed')
                self.event('error', 'event-exception')
                self.sad()

    def power(self, on):
        if on:
            GPIO.output(PIN_POWER, True)
            self.running = True
            self.happy()
            self.event('power', 'on')
        else:
            GPIO.output(PIN_POWER, False)
            self.running = False
            self.happy()
            self.event('power', 'off')

    def event(self, name, data):
        self.events.append({
            'event': name,
            'data': data
        })

    def sad(self):
        if self.current_color != colors.red:
            self.led_script(Scripts.RED_FLASH)
            self.current_color = colors.red

    def happy(self):
        if self.running:
            if self.current_color != colors.blue:
                self.led_script(Scripts.BLUE_FLASH)
                self.current_color = colors.blue
        else:
            if self.current_color != colors.green:
                self.led_color(colors.green)
                self.current_color = colors.green

    def led_script(self, script):
        try:
            self.led.reset()
            self.led.play_script(script)
        except IOError:
            self.log('Playing led script failed')
            self.event('led', 'error')

    def led_color(self, color):
        try:
            self.led.reset()
            self.led.go_to_hex(color)
        except IOError:
            self.log('Changing led color failed')
            self.event('led', 'error')

    def log(self, msg):
        if self.DEBUG:
            print "[{}] {}".format(time.strftime('%Y-%m-%d %H:%M:%S'), msg)
def Execute_Action_Button(root):

	# conditionally import BlinkM
	if (Config.i2c_demo()):
		from pyblinkm import BlinkM, Scripts
	
	
	
	# find the interface object type

	objectServerID = root.find("./OBJECTSERVERID").text
	objectName = root.find("./OBJECTNAME").text
	objectFlags = root.find("./OBJECTFLAGS").text

	validate = Validate.checkForValidate(root)

	if (Config.debug()):
		print("VALIDATE=%s" % validate)

	outgoingXMLData = BuildResponse.buildHeader(root)


	if (Config.debug()):
		print("objectServerID = %s" % objectServerID)


	# we have the objectServerID so now we can choose the correct
	# program

	# FB-1 just does a toggle from on to off from the button name 

	if (objectServerID == "FB-1"):	
		# do a toggle

		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()

			return outgoingXMLData


		responseData = "XXX"

		lowername = objectName.lower()

		if (lowername.count(" off") > 0):
			
			lowername = lowername.replace(" off", " on")
			responseData = lowername.title()
		
		elif (lowername.count(" on") > 0):
			
			lowername = lowername.replace(" on", " off")
			responseData = lowername.title()
			
		else: 
			responseData = objectName
			
		outgoingXMLData += BuildResponse.buildResponse(responseData)



	# B-1 does a toggle on a BlinkM module on I2C bus address 0xb (11)

	elif (objectServerID == "B-1"):	
		# do a toggle

		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()

			return outgoingXMLData

		if (Config.debug()):
			print("Config.i2c_demo=%i" % Config.i2c_demo())


		if (Config.i2c_demo()):

			blinkm = BlinkM(1,0xb)
			blinkm.reset()

			try:
				blinkm.go_to(0, 0, 255)
				time.sleep(0.2)
				blinkm.go_to(0, 255, 0)
				responseData = "OK"

			except IOError as e:
				#blinkm.reset()
				print("I/O error({0}): {1}".format(e.errno, e.strerror))
				responseData = "FAILED"
			except:
				blinkm.reset()
				print("Unexpected error:", sys.exc_info()[0])
				raise

		responseData = "OK"

		outgoingXMLData += BuildResponse.buildResponse(responseData)



	else:
		# invalid RaspiConnect Code
		outgoingXMLData += Validate.buildValidateResponse("NO")



	outgoingXMLData += BuildResponse.buildFooter()
	if (Config.debug()):
		print(outgoingXMLData)

	return outgoingXMLData
def Execute_Action_Button(root):

	# conditionally import BlinkM
	if (Config.i2c_demo()):
		from pyblinkm import BlinkM, Scripts
        
	
	
	# find the interface object type

        objectServerID = root.find("./OBJECTSERVERID").text
        objectName = root.find("./OBJECTNAME").text
        objectFlags = root.find("./OBJECTFLAGS").text

        validate = Validate.checkForValidate(root)

        if (Config.debug()):
		print "VALIDATE=%s" % validate

        outgoingXMLData = BuildResponse.buildHeader(root)


        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)


	# we have the objectServerID so now we can choose the correct
	# program

	# FB-1 just does a toggle from on to off from the button name 

	if (objectServerID == "FB-1"):	
		# do a toggle

                #check for validate request
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()

                        return outgoingXMLData


		responseData = "XXX"

		lowername = objectName.lower()

		if (lowername.count(" off") > 0):
			
			lowername = lowername.replace(" off", " on")
			responseData = lowername.title()
		
		elif (lowername.count(" on") > 0):
			
			lowername = lowername.replace(" on", " off")
			responseData = lowername.title()
			
		else: 
			responseData = objectName
			
                outgoingXMLData += BuildResponse.buildResponse(responseData)



	# B-1 does a toggle on a BlinkM module on I2C bus address 0xb (11)

	elif (objectServerID == "B-1"):	
		# do a toggle

                #check for validate request
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()

                        return outgoingXMLData

		if (Config.debug()):
			print "Config.i2c_demo=%i" % Config.i2c_demo()


		if (Config.i2c_demo()):

			blinkm = BlinkM(1,0xb)
			blinkm.reset()

        		try:
                		blinkm.go_to(0, 0, 255)
				time.sleep(0.2)
                		blinkm.go_to(0, 255, 0)
				responseData = "OK"

        		except IOError as e:
                		#blinkm.reset()
                		print "I/O error({0}): {1}".format(e.errno, e.strerror)
				responseData = "FAILED"
        		except:
                		blinkm.reset()
                		print "Unexpected error:", sys.exc_info()[0]
                		raise

		responseData = "OK"

                outgoingXMLData += BuildResponse.buildResponse(responseData)



        else:
                # invalid RaspiConnect Code
                outgoingXMLData += Validate.buildValidateResponse("NO")



        outgoingXMLData += BuildResponse.buildFooter()
        if (Config.debug()):
        	print outgoingXMLData

	return outgoingXMLData





# End of ExecuteActionButton.py
				
예제 #7
0
class Led():

	def __init__(self, name):
		#so we can have many different leds
		self.name = name
		self.led = BlinkM()
		self.delay(2)
		self.led.reset()
		self.delay(1)
		self.led.set_fade_speed(32)
		self.delay(1)
	
	def delay(self, seconds):
		time.sleep(seconds)

	def show_status_light(self):
		self.led.fade_to_hex("0000ff")
		self.delay(1)

	def show_thinking_light(self):
		#self.led.play_script(Scripts.WHITE_FLASH)
		self.led.fade_to_hex("ffffff")
		self.delay(1)

	def show_positive_light(self):
		#self.led.stop_script()
		self.led.fade_to_hex("00ff00")
		self.delay(1)

	def show_negative_light(self):
		#self.led.stop_script()
		self.led.fade_to_hex("ff0000")
		self.delay(1)
예제 #8
0
if 2 != len(sys.argv):
    print usageLine
    exit(1)

# Grab the first argument.  (Not argv[0], that's the command name.)
arg1 = int(sys.argv[1])

# range() is a little unintuitive, to me.  range(0, 256) excludes 256, meaning
# it includes numbers 0 - 255, inclusive.
if not arg1 in range(0, 256):
    print usageLine
    exit(1)

# Get the i2c bus number, then create a blinkm object with that bus number.
bus = GFDITools.guessBus()
blinkm = BlinkM(bus=bus)

# Issue the command to the I2C
blinkm.reset()
blinkm.go_to(arg1, arg1, arg1)

sys.exit(0)

# BlinkM makes some scripts available, which flash the lights in various
# patterns.  They're included here in commented form.  Copy lines as needed, or
# uncomment the whole block if you want to throw a rave.
'''
raw_input("Press Enter to continue...")
print "STARTUP\n"
blinkm.play_script(Scripts.STARTUP)
def Generate_Remote_WebView(root, LOCALURL):

       	if (Config.i2c_demo()):
		from pyblinkm import BlinkM, Scripts

	
	objectServerID = root.find("./OBJECTSERVERID").text
        objectFlags = root.find("./OBJECTFLAGS").text
	
	validate = Validate.checkForValidate(root) 

        if (Config.debug()):
		print "VALIDATE=%s" % validate

	outgoingXMLData = BuildResponse.buildHeader(root)

	if (objectServerID == "W-1"):
	
		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()

			return outgoingXMLData
			
		# normal response requested	
	
		responseData = ""

		# check to see if i2c_demo is turned on
		if (Config.i2c_demo()):
		
        		if (Config.debug()):
				print "Config.i2c_demo passed as True" 


			# Yes, it is on

			# Initialise the BMP085 and use STANDARD mode (default value)
			# bmp = BMP085(0x77, debug=True)
			# bmp = BMP085(0x77)
		
			# To specify a different operating mode, uncomment one of the following:
			# bmp = BMP085(0x77, 0)  # ULTRALOWPOWER Mode
			# bmp = BMP085(0x77, 1)  # STANDARD Mode
			# bmp = BMP085(0x77, 2)  # HIRES Mode
			bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode
			
			count = 0
			exceptionCount = 0
			exceptionCountBMP = 0
			blinkm = BlinkM(1,0xc)
			blinkm.reset()
			
	
			
			try:
				temp = bmp.readTemperature()
				pressure = bmp.readPressure()
				altitude = bmp.readAltitude()
		
				tempData = "%.2f C" % temp
				pressureData = "%.2f hPa" % (pressure / 100.0)

			except IOError as e:
    				exceptionCountBMP = exceptionCountBMP + 1	
				print "I/O error({0}): {1}".format(e.errno, e.strerror)
			except:
    				exceptionCountBMP = exceptionCountBMP + 1	
    				print "Unexpected error:", sys.exc_info()[0]
    				raise

		else:    # now set some values for display since we don't have i2C
			tempData = "xx.x C (no i2c enabled)" 
			pressureData = "xxxx.x hPa (no i2c enabled)" 

				

		# read an HTML template into aw string		
		with open ("./Templates/W-1.html", "r") as myfile:
    			responseData += myfile.read().replace('\n', '')
	
		# replace the URL so it will point to static
		responseData = responseData.replace("XXX", LOCALURL) 
	

		# now replace the AAA, BBB, etc with the right data
		responseData = responseData.replace("AAA", subprocess.check_output(["date", ""], shell=True))	

		# split uptime at first blank, then at first ,
		uptimeString = subprocess.check_output(["uptime", ""])	
	
		uptimeType = uptimeString.split(",")
		uptimeCount = len(uptimeType)

		if (uptimeCount == 6):
			# over 24 hours
			uptimeSplit = uptimeString.split(",")
			uptimeSplit = uptimeSplit[0]+uptimeSplit[1]
			uptimeSplit = uptimeSplit.split(" ", 1)
			uptimeData = uptimeSplit[1]
		else:	
			# under 24 hours
			uptimeSplit = uptimeString.split(" ", 2)
			uptimeSplit = uptimeSplit[2].split(",", 1)
			uptimeData = uptimeSplit[0]

		responseData = responseData.replace("BBB", uptimeData)	

		usersString = subprocess.check_output(["who", "-q"], shell=False, stderr=subprocess.STDOUT,)	
		responseData = responseData.replace("CCC", usersString)	

		freeString = subprocess.check_output(["free", "-mh"])	
		freeSplit = freeString.split("cache: ", 1)
		freeSplit = freeSplit[1].split("       ", 2)
		freeSplit = freeSplit[2].split("\nSwap:", 1)
		freeData = freeSplit[0]


		responseData = responseData.replace("DDD", freeData)	
			
		responseData = responseData.replace("EEE", tempData)	
		responseData = responseData.replace("FFF", pressureData)	


		output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
		cpuTemp = "%3.2f C" % (float(output)/1000.0)
			
		responseData = responseData.replace("GGG", cpuTemp)	
		
		freeString = subprocess.check_output(["ifconfig", "eth0"])	
		freeSplit = freeString.split("inet addr:", 1)
		freeSplit = freeSplit[1].split(" ", 1)
		freeData = freeSplit[0]

		responseData = responseData.replace("HHH", freeData)	
			
		responseData = responseData.replace("III", Config.localURL())
		# responseData = responseData.replace("III", "'your external address here'")

		responseData = responseData.replace("JJJ", Config.version_number())

		# read latest data from ST-1 SendText control on RasPiConnect 

		try:
			with open ("./local/ST-1.txt", "r") as myfile:
    				sendTextData = myfile.read().replace('\n', '')
   		except IOError:
			sendTextData = ""

		responseData = responseData.replace("KKK", sendTextData)

	

		# check to see if i2c_demo is turned on
		if (Config.i2c_demo()):
		
			time.sleep(0.2)

   	 		try:
	
               			blinkm.go_to(255, 0, 0)
				time.sleep(0.2)
               			blinkm.go_to(0, 255, 0)
	
	
       			except IOError as e:
             			#blinkm.reset()
                		exceptionCount = exceptionCount + 1
                		print "I/O error({0}): {1}".format(e.errno, e.strerror)
        		except:
               			blinkm.reset()
                		exceptionCount = exceptionCount + 1
                		print "Unexpected error:", sys.exc_info()[0]
                		raise
	
		#responseData += subprocess.check_output(["cat", "/proc/cpuinfo"])
		#responseData += subprocess.check_output(["cat", "/proc/meminfo"])
		
		outgoingXMLData += BuildResponse.buildResponse(responseData)

        	if (Config.debug()):
			print outgoingXMLData	
	elif (objectServerID == "W-2"):
	
		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()

			return outgoingXMLData
			
		# normal response requested	

		imageName = "RovioImage.jpg"	


		responseData = "<html><head>"
		responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
		responseData += "</head>"
		
		responseData += "<body><img src=\""
 		responseData += LOCALURL 
 		responseData += "static/"
		responseData += imageName
		responseData += "\" type=\"jpg\" width=\"300\" height=\"300\">"
		responseData += "<BR>Picture<BR>"

		responseData +="</body>"
		
		responseData += "</html>"
	
		
		outgoingXMLData += BuildResponse.buildResponse(responseData)

        	if (Config.debug()):
			print outgoingXMLData	

	else:
		# invalid RaspiConnect Code
		outgoingXMLData += Validate.buildValidateResponse("NO")	
	

	outgoingXMLData += BuildResponse.buildFooter()

	return outgoingXMLData
예제 #10
0
 def __init__(self):
     self.rgb = (0, 0, 0)
     self.blinkm = BlinkM()
     self.blinkm.reset()
예제 #11
0
def Generate_Remote_WebView(root, LOCALURL):

       	if (Config.i2c_demo()):
		from pyblinkm import BlinkM, Scripts

	
	objectServerID = root.find("./OBJECTSERVERID").text
        objectFlags = root.find("./OBJECTFLAGS").text
	
	validate = Validate.checkForValidate(root) 

        if (Config.debug()):
		print "VALIDATE=%s" % validate

	outgoingXMLData = BuildResponse.buildHeader(root)

	if (objectServerID == "W-1"):
	
		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()

			return outgoingXMLData
			
		# normal response requested	
	
		responseData = ""

		# check to see if i2c_demo is turned on
		if (Config.i2c_demo()):
		
        		if (Config.debug()):
				print "Config.i2c_demo passed as True" 


			# Yes, it is on

			# Initialise the BMP085 and use STANDARD mode (default value)
			# bmp = BMP085(0x77, debug=True)
			# bmp = BMP085(0x77)
		
			# To specify a different operating mode, uncomment one of the following:
			# bmp = BMP085(0x77, 0)  # ULTRALOWPOWER Mode
			# bmp = BMP085(0x77, 1)  # STANDARD Mode
			# bmp = BMP085(0x77, 2)  # HIRES Mode
			bmp = BMP085(0x77, 3)  # ULTRAHIRES Mode
			
			count = 0
			exceptionCount = 0
			exceptionCountBMP = 0
			blinkm = BlinkM(1,0xc)
			blinkm.reset()
			
	
			
			try:
				temp = bmp.readTemperature()
				pressure = bmp.readPressure()
				altitude = bmp.readAltitude()
		
				tempData = "%.2f C" % temp
				pressureData = "%.2f hPa" % (pressure / 100.0)

			except IOError as e:
    				exceptionCountBMP = exceptionCountBMP + 1	
				print "I/O error({0}): {1}".format(e.errno, e.strerror)
			except:
    				exceptionCountBMP = exceptionCountBMP + 1	
    				print "Unexpected error:", sys.exc_info()[0]
    				raise

		else:    # now set some values for display since we don't have i2C
			tempData = "xx.x C (no i2c enabled)" 
			pressureData = "xxxx.x hPa (no i2c enabled)" 

				

		# read an HTML template into aw string		
		with open ("./Templates/W-1.html", "r") as myfile:
    			responseData += myfile.read().replace('\n', '')
	
		# replace the URL so it will point to static
		responseData = responseData.replace("XXX", LOCALURL) 
	

		# now replace the AAA, BBB, etc with the right data
		responseData = responseData.replace("AAA", subprocess.check_output(["date", ""], shell=True))	

		# split uptime at first blank, then at first ,
		uptimeString = subprocess.check_output(["uptime", ""])	
	
		uptimeType = uptimeString.split(",")
		uptimeCount = len(uptimeType)

		if (uptimeCount == 6):
			# over 24 hours
			uptimeSplit = uptimeString.split(",")
			uptimeSplit = uptimeSplit[0]+uptimeSplit[1]
			uptimeSplit = uptimeSplit.split(" ", 1)
			uptimeData = uptimeSplit[1]
		else:	
			# under 24 hours
			uptimeSplit = uptimeString.split(" ", 2)
			uptimeSplit = uptimeSplit[2].split(",", 1)
			uptimeData = uptimeSplit[0]

		responseData = responseData.replace("BBB", uptimeData)	

		usersString = subprocess.check_output(["who", "-q"], shell=False, stderr=subprocess.STDOUT,)	
		responseData = responseData.replace("CCC", usersString)	

		freeString = subprocess.check_output(["free", "-mh"])	
		freeSplit = freeString.split("cache: ", 1)
		freeSplit = freeSplit[1].split("       ", 2)
		freeSplit = freeSplit[2].split("\nSwap:", 1)
		freeData = freeSplit[0]


		responseData = responseData.replace("DDD", freeData)	
			
		responseData = responseData.replace("EEE", tempData)	
		responseData = responseData.replace("FFF", pressureData)	


		output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
		cpuTemp = "%3.2f C" % (float(output)/1000.0)
			
		responseData = responseData.replace("GGG", cpuTemp)	

		try:	
			freeString = subprocess.check_output(["ifconfig", "eth0"])	
			freeSplit = freeString.split("inet addr:", 1)
			if (len(freeSplit) > 1):
				freeSplit = freeSplit[1].split(" ", 1)
				freeData = freeSplit[0]
			else:
				freeData = ""

		except:
			freeData = ""


		responseData = responseData.replace("HHH", freeData)	
			
		responseData = responseData.replace("III", Config.localURL())
		# responseData = responseData.replace("III", "'your external address here'")

		responseData = responseData.replace("JJJ", Config.version_number())

		# read latest data from ST-1 SendText control on RasPiConnect 

		try:
			with open ("./local/ST-1.txt", "r") as myfile:
    				sendTextData = myfile.read().replace('\n', '')
   		except IOError:
			sendTextData = ""

		responseData = responseData.replace("KKK", sendTextData)

	

		# check to see if i2c_demo is turned on
		if (Config.i2c_demo()):
		
			time.sleep(0.2)

   	 		try:
	
               			blinkm.go_to(255, 0, 0)
				time.sleep(0.2)
               			blinkm.go_to(0, 255, 0)
	
	
       			except IOError as e:
             			#blinkm.reset()
                		exceptionCount = exceptionCount + 1
                		print "I/O error({0}): {1}".format(e.errno, e.strerror)
        		except:
               			blinkm.reset()
                		exceptionCount = exceptionCount + 1
                		print "Unexpected error:", sys.exc_info()[0]
                		raise
	
		#responseData += subprocess.check_output(["cat", "/proc/cpuinfo"])
		#responseData += subprocess.check_output(["cat", "/proc/meminfo"])
		
		outgoingXMLData += BuildResponse.buildResponse(responseData)

        	if (Config.debug()):
			print outgoingXMLData	
	elif (objectServerID == "W-2"):
	
		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()

			return outgoingXMLData
			
		# normal response requested	

		imageName = "RovioImage.jpg"	


		responseData = "<html><head>"
		responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
		responseData += "</head>"
		
		responseData += "<body><img src=\""
 		responseData += LOCALURL 
 		responseData += "static/"
		responseData += imageName
		responseData += "\" type=\"jpg\" width=\"300\" height=\"300\">"
		responseData += "<BR>Picture<BR>"

		responseData +="</body>"
		
		responseData += "</html>"
	
		
		outgoingXMLData += BuildResponse.buildResponse(responseData)

        	if (Config.debug()):
			print outgoingXMLData	

	else:
		# invalid RaspiConnect Code
		outgoingXMLData += Validate.buildValidateResponse("NO")	
	

	outgoingXMLData += BuildResponse.buildFooter()

	return outgoingXMLData
	

# End of ExecuteWebView.py
				
def setProgram(program):
  blinkm = BlinkM()
  blinkm.reset()
  blinkm.go_to_hex(OFF) # Some programs mix colors with the previously selected ones. We don't like that.
  blinkm.play_script(program)
  blinkm = None 
def setLight(hexColor):
  blinkm = BlinkM()
  blinkm.reset()
  blinkm.go_to_hex(hexColor)
  blinkm = None