def Execute_Text_And_Title(root):

    # find the interface object type

    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 Config.debug():
        print ("objectServerID = %s" % objectServerID)

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

    if objectServerID == "LT-1":

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

            return outgoingXMLData

        output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
        FMOutput = float(output) / 1000.0

        responseData = "%3.2f, %3.2f, %s" % (FMOutput, FMOutput, "CPU Temp (deg C)")

        outgoingXMLData += BuildResponse.buildResponse(responseData)

    else:

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

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

    return outgoingXMLData
示例#2
0
def handleFeedBackButtonRequest(validate):
  global lastFileCount
  
  #check for validate request
  # validate allows RasPiConnect to verify this object is here 
  
  outgoingXMLData = ""
  if (validate == "YES"):
     outgoingXMLData = Validate.buildValidateResponse("YES")
     outgoingXMLData += BuildResponse.buildFooter()
  else:

     # not validate request, so execute
     # note that python is in the main directory for this call, not the local directory
     # check this is not the first file to be copied
     fileCount = readFileCount()
     print "lastFileCount = %d" % lastFileCount
     if (lastFileCount == -1):
        lastFileCount = fileCount
        # make sure that a latest file exists - should use excpetions really!
        filename ="/home/pi/imageprocessing/capture-%06d.jpg" %lastFileCount
        subprocess.call("cp %s ~/RasPiConnectServer/static/latest.jpg" %filename, shell=True)
        subprocess.call("cp %s ~/RasPiConnectServer/static/previous.jpg" %filename, shell=True)     	                   	
     if(fileCount !=-1):
       if (lastFileCount < fileCount):
          lastFileCount+=1
     subprocess.call("mv ~/RasPiConnectServer/static/latest.jpg ~/RasPiConnectServer/static/previous.jpg", shell=True)
     filename ="/home/pi/imageprocessing/capture-%06d.jpg" %lastFileCount
     subprocess.call("cp %s ~/RasPiConnectServer/static/latest.jpg" %filename, shell=True)
     responseData = "Image number %s" %lastFileCount
 
     outgoingXMLData = BuildResponse.buildResponse(responseData)
     outgoingXMLData += BuildResponse.buildFooter()
  return outgoingXMLData
def Execute_Single_LED(root):

	# find the interface object type

	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 (Config.debug()):
		print("objectServerID = %s" % objectServerID)

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

	# L-1 sends back the current second to provide an interesting display 



	if (objectServerID == "L-1"):	

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

			return outgoingXMLData

		output = subprocess.check_output(["date", "+%s"])
		ledoutput = int(output)%7



		responseData = "%i" % ledoutput


		outgoingXMLData += BuildResponse.buildResponse(responseData)


	else:

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


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

	return outgoingXMLData
def Execute_Freq_Mod_LED(root):

    # find the interface object type

    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 (Config.debug()):
        print("objectServerID = %s" % objectServerID)

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

# L-1 sends back the current second to provide an interesting display

    if (objectServerID == "BL-1"):

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

            return outgoingXMLData

        output = subprocess.check_output(["uptime", ""])
        list = output.split("average:")
        list2 = list[1].split(",")
        if (Config.debug()):
            print list2
            print list2[0]
        element = list2[0]

        FMOutput = 1 / (float(element) * 4.0 + 0.01)

        responseData = "%3.2f, %3.2f, %s" % (FMOutput, float(element),
                                             "CPU Load")

        outgoingXMLData += BuildResponse.buildResponse(responseData)

    else:

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

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

    return outgoingXMLData
示例#5
0
def Execute_BarMeter(root):

      # find the interface object type


        objectServerID = root.find("./OBJECTSERVERID").text
        objectID = root.find("./OBJECTID").text

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

        validate = Validate.checkForValidate(root)

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

        outgoingXMLData = BuildResponse.buildHeader(root)


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

	# BR-1 sends back the power supply voltage 


	# BR-1
	if (objectServerID == "BR-1"):	


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

                        return outgoingXMLData

		import random
        	if (Config.debug()):
	        	print random.randrange(0,9)
		voltage = 10.0 + (random.randrange(0,9)-10)/10.0
		responseData = "%f" % voltage
                outgoingXMLData += BuildResponse.buildResponse(responseData)
        else:
                # invalid RaspiConnect Code
                outgoingXMLData += Validate.buildValidateResponse("NO")


        outgoingXMLData += BuildResponse.buildFooter()

        return outgoingXMLData




# End of ExecuteBarMeter.py
				
def Execute_Server_Status(root):

        # find the interface object type

        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 (Config.debug()):
        	print("objectServerID = %s" % objectServerID)

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



	if (objectServerID == "SS-1"):	

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

                        return outgoingXMLData




		responseData = "2"


                outgoingXMLData += BuildResponse.buildResponse(responseData)


	else:

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


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

        return outgoingXMLData
def Execute_BarMeter(root):

      # find the interface object type


	objectServerID = root.find("./OBJECTSERVERID").text
	objectID = root.find("./OBJECTID").text

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

	validate = Validate.checkForValidate(root)

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

	outgoingXMLData = BuildResponse.buildHeader(root)


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

	# BR-1 sends back the power supply voltage 


	# BR-1
	if (objectServerID == "BR-1"):	


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

			return outgoingXMLData

		import random
		if (Config.debug()):
			print(random.randrange(0,9))
		voltage = 10.0 + (random.randrange(0,9)-10)/10.0
		responseData = "%f" % voltage
		outgoingXMLData += BuildResponse.buildResponse(responseData)
	else:
		# invalid RaspiConnect Code
		outgoingXMLData += Validate.buildValidateResponse("NO")


	outgoingXMLData += BuildResponse.buildFooter()

	return outgoingXMLData
示例#8
0
def handleImageRequest(validate, imageName):
	#check for validate request
	response=""
	if (validate == "YES"):
		response = Validate.buildValidateResponse("YES")
		response += BuildResponse.buildFooter()
		
	else:	
		responseData =buildImageResponse(imageName)
		response = BuildResponse.buildResponse(responseData)
		response += BuildResponse.buildFooter()
		
        if (Config.debug()):
		print response	
	return response
def Execute_File_Write(root):

	# find the interface object type

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


	outgoingXMLData = BuildResponse.buildHeader(root)


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

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


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


	if (objectServerID == "FWC-1"):	


		
					
		

		myfile = open("./ClientXMLConfigFiles/"+objectName, "w")
		myfile.write(objectResponseBody)
		myfile.close
		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_File_Directory(root):

	# find the interface object type

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



	outgoingXMLData = BuildResponse.buildHeader(root)


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


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


	if (objectServerID == "FDC-1"):	

		print(glob.glob("ClientXMLConfigFiles/*.xml"))
		file_list = glob.glob("ClientXMLConfigFiles/*.xml")
		responseData = ""

		for pathname in file_list:
				
			responseData += "<FILENAME>"
			responseData += os.path.basename(pathname)			
			responseData += "</FILENAME>"
		

		outgoingXMLData += BuildResponse.buildResponse(responseData)


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



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

	return outgoingXMLData
示例#11
0
def Execute_Text_And_Title(root):

    # find the interface object type

    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 (Config.debug()):
        print("objectServerID = %s" % objectServerID)

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

    if (objectServerID == "LT-1"):

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

            return outgoingXMLData

        output = subprocess.check_output(
            ["cat", "/sys/class/thermal/thermal_zone0/temp"])
        FMOutput = float(output) / 1000.0

        responseData = "%3.2f, %3.2f, %s" % (FMOutput, FMOutput,
                                             "CPU Temp (deg C)")

        outgoingXMLData += BuildResponse.buildResponse(responseData)

    else:

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

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

    return outgoingXMLData
def Execute_Single_LED(root):

    # find the interface object type

    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 (Config.debug()):
        print("objectServerID = %s" % objectServerID)

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

# L-1 sends back the current second to provide an interesting display

    if (objectServerID == "L-1"):

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

            return outgoingXMLData

        output = subprocess.check_output(["date", "+%s"])
        ledoutput = int(output) % 7

        responseData = "%i" % ledoutput

        outgoingXMLData += BuildResponse.buildResponse(responseData)

    else:

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

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

    return outgoingXMLData
def Execute_File_Read(root):

	# find the interface object type

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



	outgoingXMLData = BuildResponse.buildHeader(root)


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


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


	if (objectServerID == "FRC-1"):	

		responseData = ""

		print(os.getcwd())

		with open ("./ClientXMLConfigFiles/"+objectName, "r") as myfile:
    			responseData=myfile.read().replace('\n', '')
				
		

		outgoingXMLData += BuildResponse.buildResponse(responseData)


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



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

	return outgoingXMLData
def Execute_Server_Status(root):

    # find the interface object type

    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 (Config.debug()):
        print("objectServerID = %s" % objectServerID)

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

    if (objectServerID == "SS-1"):

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

            return outgoingXMLData

        responseData = "2"

        outgoingXMLData += BuildResponse.buildResponse(responseData)

    else:

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

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

    return outgoingXMLData
def Execute_File_Directory(root):

    # find the interface object type

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

    outgoingXMLData = BuildResponse.buildHeader(root)

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

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

    if (objectServerID == "FDC-1"):

        print glob.glob("ClientXMLConfigFiles/*.xml")
        file_list = glob.glob("ClientXMLConfigFiles/*.xml")
        responseData = ""

        for pathname in file_list:

            responseData += "<FILENAME>"
            responseData += os.path.basename(pathname)
            responseData += "</FILENAME>"

        outgoingXMLData += BuildResponse.buildResponse(responseData)

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

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

    return outgoingXMLData
def Execute_File_Write(root):

    # find the interface object type

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

    outgoingXMLData = BuildResponse.buildHeader(root)

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

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

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

    if (objectServerID == "FWC-1"):

        myfile = open("./ClientXMLConfigFiles/" + objectName, "w")
        myfile.write(objectResponseBody)
        myfile.close
        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_File_Read(root):

    # find the interface object type

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

    outgoingXMLData = BuildResponse.buildHeader(root)

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

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

    if (objectServerID == "FRC-1"):

        responseData = ""

        print os.getcwd()

        with open("./ClientXMLConfigFiles/" + objectName, "r") as myfile:
            responseData = myfile.read().replace('\n', '')

        outgoingXMLData += BuildResponse.buildResponse(responseData)

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

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

    return outgoingXMLData
示例#18
0
def ExecuteUserObjects(objectType, element):

    # Example Objects
    global port25
    global port24
    global FMOutput

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
    #
    # check to see if this is a Validate request
    #
    validate = Validate.checkForValidate(element)

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

    # Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    # objects are split up by object types by Interface Constants
    #
    #
    #
    # search for matches to object Type

    # object Type match
    print("+++++++++++OBJECTTYPE %i" % objectType)
    if (objectType == ACTION_BUTTON_UITYPE):

        if (Config.debug()):
            print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

        # B-2 - play a beep on the Raspberry Pi
        if (objectServerID == "B-2"):

            #check for validate request
            # validate allows RasPiConnect to verify this object is here
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        # not validate request, so execute

        # note that python is in the main directory for this call, not the local directory

            output = subprocess.call(["aplay", "sounds/match1.wav"])

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
    if (objectType == TEXT_DISPLAY_UITYPE):

        if (objectServerID == "LT-1"):

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

                return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
            output = board_revision
            FMOutput += 1000.0

            print "VERSION++++++++++++++=%s" % output

            responseData = "%3.2f, %3.2f, %s" % (
                FMOutput,
                FMOutput,
                output,
            )

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        if (objectServerID == "LT-2"):

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

                return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
            output = board_revision
            FMOutput = 2222.0

            print "VERSION---------=%s" % output

            responseData = "%3.2f, %3.2f, %s" % (output, output, "RPI Version")

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

    if (objectType == SINGLE_LED_DISPLAY):

        #check for validate request
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        if (port25):
            wiringpi.digitalWrite(25, 0)  # switch on an led
            port25 = False
            ledColour = 5
            print "Led off"
        else:
            wiringpi.digitalWrite(25, 1)  # switch on an led
            port25 = True
            ledColour = 2
            print "Led on"

        responseData = "%i" % (ledColour)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData
    if (objectType == FEEDBACK_ACTION_BUTTON_UITYPE):
        #check for validate request
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        if (port24):
            wiringpi.digitalWrite(24, 0)  # switch on an led
            port24 = False
            responseData = "Port 24 Led off"
        else:
            wiringpi.digitalWrite(24, 1)  # switch on an led
            port24 = True
            responseData = "port 24 Led on"

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData
    if (objectType == VOLTMETER_UITYPE):
        #check for validate request
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        adc_value = (get_adc(0))  # read ADC voltage
        if adc_value > 511:  # above half-way on the pot
            wiringpi.digitalWrite(17, 0)  # motor spins one way
            pwm = (adc_value - 511) * 2 - 1
        else:  # below half-way on the pot
            wiringpi.digitalWrite(17, 1)  # motor spins the other way
            pwm = adc_value * 2 + 1

        wiringpi.pwmWrite(18, pwm)  # send PWM value to port 18

        responseData = "%i" % (adc_value)
        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    else:
        return ""
    # returning a zero length string tells the server that you have not matched
    # the object and server
    return ""
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
def ExecuteUserObjects(objectType, element):

	# Example Objects

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)

	#
	# B-1 Flashes LED on GPIO
	if (objectServerID == "B-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 

               	if (validate == "YES"):
                       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       	outgoingXMLData += BuildResponse.buildFooter()
                       	return outgoingXMLData

		# not validate request, so execute
		#
		
		#
		#
		# Execute your code
		#
		#

		# To put an LED on GPIO Pin 7 on your pi read this:
		#		http://www.thirdeyevis.com/pi-page-2.php
		#
        	if (Config.debug()):
        		print("Button # %s: Blinking GPIO pin 7" % objectServerID)

		GPIO.output(7,True) ## Turn on GPIO pin 7
		time.sleep(1) ## sleep 1 second
		GPIO.output(7,False) ## Turn off GPIO pin 7
              	responseData = "OK" ## send an OK back to the App

		print "responseData =", responseData

		#
		#
		# Done with your code
		#
		#

               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData
		


	else:
		# returning a zero length string tells the server that you have not matched 
		# the object and server 
		return ""
def ExecuteUserObjects(objectType, element):

	# Example Objects

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text
      # find the interface object type
        objectName = element.find("./OBJECTNAME").text
        objectFlags = element.find("./OBJECTFLAGS").text


        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)


	# objects are split up by object types by Interface Constants
	#
	#
	#
	# search for matches to object Type 



	# object Type match
	if (objectType ==  COMPLEX_LINE_GRAPH_LIVE_UITYPE):

		if (Config.debug()):
			print "COMPLEX_LINE_GRAPH_LIVE_UITYPE of %s found" % objectServerID

		# CLGL-1 - ultrasonic graph
		if (objectServerID == "CLGL-1"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
	
                        # normal response requested
			try:
        			f = open("/home/pi/MouseAir/state/UltrasonicGraph.txt", "r")
        			commandresponse = f.read()
        			f.close()	
			except IOError as e:
				commandresponse = "0^^0||No Data from MouseAir^^"			

                        outgoingXMLData += BuildResponse.buildResponse(commandresponse)


                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData	



	# object Type match
	if (objectType ==  SIMPLE_LINE_GRAPH_LIVE_UITYPE):

		if (Config.debug()):
			print "SIMPLE_LINE_GRAPH_LIVE_UITYPE of %s found" % objectServerID

		# SLGL-1 - ultrasonic graph
		if (objectServerID == "SLGL-1"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
	
                        # normal response requested
			try:
        			f = open("/home/pi/MouseAir/state/UltrasonicGraph.txt", "r")
        			commandresponse = f.read()
        			f.close()	
			except IOError as e:
				commandresponse = "0^^0||No Data from MouseAir^^"			

                        outgoingXMLData += BuildResponse.buildResponse(commandresponse)


                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData	

	# object Type match
	if (objectType == PICTURE_REMOTE_WEBVIEW_UITYPE):

		if (Config.debug()):
			print "PICTURE_REMOTE_WEBVIEW_UITYPE of %s found" % objectServerID

		# W-10 - play a beep on the Raspberry Pi
		if (objectServerID == "W-10"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
	
                        # normal response requested

                        imageName = "picamera.jpg"


                        responseData = "<html><head>"
                        responseData += "<META HTTP-EQUIV='CACHE-CONTROL' CONTENT='NO-CACHE'>"
                        responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
                        responseData += "</head>"

                        responseData += "<body><img src=\""
                        responseData += Config.localURL()
                        responseData += "static/"
                        responseData += imageName
                        responseData += "\" type=\"jpg\" width=\"585\" height=\"300\">"

                        responseData +="</body>"

                        responseData += "</html>"


                        outgoingXMLData += BuildResponse.buildResponse(responseData)


                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData	

	# object Type match
	if (objectType == ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-10 - fire Mouse 
		if (objectServerID == "B-10"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-10 Fire Mouse"
			status = sendCommandToMouseAirAndWait("FIREMOUSE")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		

		# B-11 - take picture 
		if (objectServerID == "B-11"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-11 Take Picture"
			status = sendCommandToMouseAirAndWait("TAKEPICTURE")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		

		# B-13 - Pan to Mouse watch
		if (objectServerID == "B-13"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-13 Pan to Watch Mouse"
			status = sendCommandToMouseAirAndWait("PANTOMOUSE")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		
		# B-14 - Pan to Cat watch
		if (objectServerID == "B-14"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-14 Pan to Watch Cat"
			status = sendCommandToMouseAirAndWait("PANTOCAT")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		



		# B-15 - Shoot Solenoid 
		if (objectServerID == "B-15"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-15 Shoot Solenoid "
			status = sendCommandToMouseAirAndWait("SHOOTSOLENOID")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		
		# B-16 - Pan Left 
		if (objectServerID == "B-16"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-16 Pan Left"
			status = sendCommandToMouseAirAndWait("PANLEFT")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		
		
		
		
		# B-17 - Pan Right 
		if (objectServerID == "B-17"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-17 Pan Right"
			status = sendCommandToMouseAirAndWait("PANRIGHT")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		
		# B-18 - Tilt Up 
		if (objectServerID == "B-18"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-18 Tilt Up "
			status = sendCommandToMouseAirAndWait("TILTUP")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		
		# B-19 - Tilt Down 
		if (objectServerID == "B-19"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			print "set B-19 Tilt Down"
			status = sendCommandToMouseAirAndWait("TILTDOWN")
			
			responseData = "OK" 
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
	



	
	# object Type match
	if (objectType == FEEDBACK_ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "FEEDBACK_ACTION_BUTTON_UTYPE of %s found" % objectServerID

		
		# FB-10 -  turn ultrasonics on and off 
		if (objectServerID == "FB-10"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

                        responseData = "XXX"

                        if (objectName is None):
                                objectName = "XXX"

               		lowername = objectName.lower()


                	if (lowername == "ultrasonic on"):
				
				status = sendCommandToMouseAirAndWait("ULTRASONICON") 
                        	responseData = "ultrasonic off" 
                        	responseData = responseData.title()


                	elif (lowername == "ultrasonic off"):
				
				status = sendCommandToMouseAirAndWait("ULTRASONICOFF")
                        	responseData = "ultrasonic on" 
                        	responseData = responseData.title()


			 # defaults to off 
                	else:
				status = sendCommandToMouseAirAndWait("ULTRASONICOFF") 
                        	lowername = "ultrasonic on" 
                        	responseData = lowername.title()

	
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData


		
		# FB-11 -  turn RFID on and off 
		if (objectServerID == "FB-11"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

                        responseData = "XXX"

                        if (objectName is None):
                                objectName = "XXX"

               		lowername = objectName.lower()


                	if (lowername == "rfid on"):
				
				status = sendCommandToMouseAirAndWait("RFIDON") 
                        	responseData = "RFID off" 
                        	responseData = responseData.title()


                	elif (lowername == "rfid off"):
				
				status = sendCommandToMouseAirAndWait("RFIDOFF")
                        	responseData = "RFID on" 
                        	responseData = responseData.title()


			 # defaults to off 
                	else:
				status = sendCommandToMouseAirAndWait("RFIDOFF") 
                        	lowername = "RFID on" 
                        	responseData = lowername.title()

	
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData

		# FB-12 -  turn USECAMERAMOTION on and off 
		if (objectServerID == "FB-11"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

                        responseData = "XXX"

                        if (objectName is None):
                                objectName = "XXX"

               		lowername = objectName.lower()


                	if (lowername == "camera motion on"):
				
				status = sendCommandToMouseAirAndWait("CAMERAMOTIONON") 
                        	responseData = "camera motion off" 
                        	responseData = responseData.title()


                	elif (lowername == "camera motion off"):
				
				status = sendCommandToMouseAirAndWait("CAMERAMOTIONOFF")
                        	responseData = "camera motion on" 
                        	responseData = responseData.title()


			 # defaults to off 
                	else:
				status = sendCommandToMouseAirAndWait("CAMERAMOTIONOFF") 
                        	lowername = "camera motion on" 
                        	responseData = lowername.title()

	
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData


		# FB-13 -  turn top servo on
		if (objectServerID == "FB-13"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

                        responseData = "XXX"

                        if (objectName is None):
                                objectName = "XXX"

               		lowername = objectName.lower()

			print("lowername =", lowername)

                	if (lowername == "top servo close"):
				
				print "set top servo close"
				status = sendCommandToMouseAirAndWait("TOPSERVOCLOSE") 
                        	responseData = "top servo open" 
                        	responseData = responseData.title()


                	elif (lowername == "top servo open"):
				
				print "set top servo open"
				status = sendCommandToMouseAirAndWait("TOPSERVOOPEN")
                        	responseData = "top servo close" 
                        	responseData = responseData.title()


			 # defaults to top servo closed
                	else:
				print "set top servo close"
				status = sendCommandToMouseAirAndWait("TOPSERVOCLOSE") 
                        	lowername = "top servo open" 
                        	responseData = lowername.title()

	
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData


		# FB-15 -  turn bottom servo on
		if (objectServerID == "FB-15"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

                        responseData = "XXX"

                        if (objectName is None):
                                objectName = "XXX"

               		lowername = objectName.lower()

			print("lowername =", lowername)

                	if (lowername == "bottom servo close"):
				
				print "set bottom servo close"
				status = sendCommandToMouseAirAndWait("BOTTOMSERVOCLOSE") 
                        	responseData = "bottom servo open" 
                        	responseData = responseData.title()


                	elif (lowername == "bottom servo open"):
				
				print "set bottom servo open"
				status = sendCommandToMouseAirAndWait("BOTTOMSERVOOPEN")
                        	responseData = "bottom servo close" 
                        	responseData = responseData.title()


			 # defaults to top servo closed
                	else:
				print "set bottom servo close"
				status = sendCommandToMouseAirAndWait("BOTTOMSERVOCLOSE") 
                        	lowername = "bottom servo open" 
                        	responseData = lowername.title()

	
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData


		# FB-16 -  turn motors on 
		if (objectServerID == "FB-16"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

                        responseData = "XXX"

                        if (objectName is None):
                                objectName = "XXX"

               		lowername = objectName.lower()


                	if (lowername == "motors on"):
				
				print "set Motors On"
				status = sendCommandToMouseAirAndWait("MOTORSON") 
                        	responseData = "motors Off" 
                        	responseData = responseData.title()


                	elif (lowername == "motors off"):
				
				status = sendCommandToMouseAirAndWait("MOTORSOFF")
                        	responseData = "Motors On" 
                        	responseData = responseData.title()


			 # defaults to Motors off 
                	else:
				print "Motors Off"
				status = sendCommandToMouseAirAndWait("MOTORSOFF") 
                        	lowername = "Motors On" 
                        	responseData = lowername.title()

	
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData


	else:
		return ""
	# returning a zero length string tells the server that you have not matched 
	# the object and server 
	return ""
示例#22
0
def ExecuteUserObjects(objectType, element):

    # Example Objects

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text
    objectAction = element.find("./OBJECTACTION").text
    objectName = element.find("./OBJECTNAME").text
    objectFlags = element.find("./OBJECTFLAGS").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
#
# check to see if this is a Validate request
#
    validate = Validate.checkForValidate(element)

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

# Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    # blink selected light button

    if (objectServerID == "B-2"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # normal response requested
        answ = "OK"
        #answ = ""
        if (Config.debug()):
            print "In local B-2"
            print("answ = %s" % answ)

        try:
            f = open("/home/pi/LightSwarm/state/LS-1.txt", "r")
            lightSelected = f.read()
            f.close()
            print "lightSelected = ", lightSelected
            lightSelected = int(float(lightSelected))
        except:
            lightSelected = 0

        print "sampling weather"
        sendCommandToLightSwarmAndWait("BLINKLIGHT," + str(lightSelected))

        responseData = "OK"

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

# reset selected
    if (objectServerID == "B-3"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # normal response requested
        answ = "OK"
        #answ = ""
        if (Config.debug()):
            print "In local B-2"
            print("answ = %s" % answ)

        try:
            f = open("/home/pi/LightSwarm/state/LS-1.txt", "r")
            lightSelected = f.read()
            f.close()
            print "lightSelected = ", lightSelected
            lightSelected = int(float(lightSelected))
        except:
            lightSelected = 0

        print "sampling weather"
        sendCommandToLightSwarmAndWait("RESETSELECTED," + str(lightSelected))

        responseData = "OK"

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

#  Reset Swarm

    if (objectServerID == "B-4"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # normal response requested
        answ = "OK"
        #answ = ""
        if (Config.debug()):
            print "In local B-4"
            print("answ = %s" % answ)

        sendCommandToLightSwarmAndWait("RESETSWARM")

        responseData = "OK"

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

# send Server to Swarm
    if (objectServerID == "B-5"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # normal response requested
        answ = "OK"
        #answ = ""
        if (Config.debug()):
            print "In local B-5"
            print("answ = %s" % answ)

        sendCommandToLightSwarmAndWait("SENDSERVER")

        responseData = "OK"

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

# Webview for device status

    if (objectServerID == "W-10"):

        if (Config.debug()):
            print "In local W-10"

    #check for validate request
        # validate allows RasPiConnect to verify this object is here

        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # not validate request, so execute

        # note that python is in the main directory for this call, not the local directory

        # read an HTML template into aw string

        responseData = "<html><head>"
        responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}"
        tempString = ""
        try:
            f = open("/home/pi/RasPiConnectServer/Templates/W-1b.txt", "r")
            tempString = f.read()
            f.close()
        except IOError as e:
            tempString = ""

        responseData += tempString
        responseData += "</style>"

        #responseData += "<META HTTP-EQUIV='CACHE-CONTROL' CONTENT='NO-CACHE'>"
        responseData += "</head>"
        # read in the rest of the css definitions

        responseData += "<body style='font-family:Verdana'>"
        responseData += "<div style='position: relative; left: 0; top: 0;'>\n"
        #responseData += "<img src='http://rfw.wardner.com:9600/static/mainplanfull.png' style='position: relative; top: 0; left: 0;'/>\n"

        # read in the rest of the objects
        tempString = ""
        try:
            f = open("/home/pi/RasPiConnectServer/Templates/W-1a.txt", "r")
            tempString = f.read()
            f.close()
        except IOError as e:
            tempString = ""

        responseData += tempString

        responseData += "</div>"

        responseData += "</body>"

        responseData += "</html>"

        print "responseData =", responseData

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    if (objectServerID == "M-1"):

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

            return outgoingXMLData

        try:
            f = open("/home/pi/LightSwarm/state/LSStatus.txt", "r")
            logString = f.read()
            f.close()
        except:
            logString = ""

        responseData = "%3.2f" % logString.count("PR")
        print "%s = %s" % (objectServerID, responseData)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    if (objectServerID == "M-2"):

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

            return outgoingXMLData

        try:
            f = open("/home/pi/LightSwarm/state/LSStatus.txt", "r")
            logString = f.read()
            f.close()
        except:
            logString = ""

        responseData = "%3.2f" % logString.count("TO")
        print "%s = %s" % (objectServerID, responseData)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

# SS-1 - Server Present
    if (objectServerID == "SS-1"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # normal response requested
        answ = "2"
        #answ = ""
        if (Config.debug()):
            print "In local SS-1"
            print("answ = %s" % answ)
        responseData = answ

        # now setup internal variables

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

#
    if (objectServerID == "BTL-1"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here

        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

# not validate request, so execute
#

#
#
# Execute your code
#
#

        if (Config.debug()):
            print("BTL-1 # %s: Status" % objectServerID)

        responseData = sendCommandToLightSwarmAndWaitReturningValue("STATUS")

        f = open("/home/pi/LightSwarm/state/LSStatus.txt", "w")
        f.write(responseData)
        f.close()

        print "responseData =", responseData

        #
        #
        # Done with your code
        #
        #

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

#
    if (objectServerID == "SL-1"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here

        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

# not validate request, so execute
#

#
#
# Execute your code
#
#

        if (Config.debug()):
            print("SL-1 # %s: Status" % objectServerID)

        responseData = ""

        f = open("/home/pi/LightSwarm/state/LS-1.txt", "w")
        f.write(objectAction)
        f.close()

        print "responseData =", responseData

        #
        #
        # Done with your code
        #
        #

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    else:
        # returning a zero length string tells the server that you have not matched
        # the object and server
        return ""
示例#23
0
def ExecuteUserObjects(objectType, element):

	# Example Objects

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)


	# objects are split up by object types by Interface Constants
	#
	#
	#
	# search for matches to object Type 

	# object Type match
	if (objectType == ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-2 - play a beep on the Raspberry Pi
		if (objectServerID == "B-2"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			# note that python is in the main directory for this call, not the local directory

			output = subprocess.call(["aplay", "sounds/match1.wav"])
			
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		


	else:
		return ""
	# returning a zero length string tells the server that you have not matched 
	# the object and server 
	return ""
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
				
示例#26
0
def ExecuteUserObjects(objectType, element):

	# Example Objects
	global port25
	global port24
	global FMOutput

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)


	# objects are split up by object types by Interface Constants
	#
	#
	#
	# search for matches to object Type 

	# object Type match
	print("+++++++++++OBJECTTYPE %i" % objectType)
	if (objectType == ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-2 - play a beep on the Raspberry Pi
		if (objectServerID == "B-2"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			# note that python is in the main directory for this call, not the local directory

			output = subprocess.call(["aplay", "sounds/match1.wav"])
			
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
	if (objectType == TEXT_DISPLAY_UITYPE):
		
        	if (objectServerID == "LT-1"):	

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

                        	return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
			output = board_revision
			FMOutput += 1000.0
			
			print "VERSION++++++++++++++=%s" % output

			responseData = "%3.2f, %3.2f, %s" % (FMOutput,FMOutput, output,)

	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
                	
        	if (objectServerID == "LT-2"):	

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

                        	return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
			output = board_revision
			FMOutput = 2222.0

			
                        print "VERSION---------=%s" % output



			responseData = "%3.2f, %3.2f, %s" % (output,output, "RPI Version")

	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData

	if (objectType == SINGLE_LED_DISPLAY ):

        	        #check for validate request
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                 	        outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
			if(port25):
			  wiringpi.digitalWrite(25, 0)      # switch on an led
			  port25=False
			  ledColour = 5
			  print "Led off"
			else:
			  wiringpi.digitalWrite(25, 1)      # switch on an led
			  port25=True
			  ledColour=2
			  print "Led on"
			
			responseData = "%i" % (ledColour)


	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData	
	if (objectType == FEEDBACK_ACTION_BUTTON_UITYPE):
        	        #check for validate request
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                 	        outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
			if(port24):
			  wiringpi.digitalWrite(24,0)      # switch on an led
			  port24=False
			  responseData = "Port 24 Led off"
			else:
			  wiringpi.digitalWrite(24, 1)      # switch on an led
			  port24=True
			  responseData = "port 24 Led on"
			
	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
	if( objectType ==VOLTMETER_UITYPE ):
        	        #check for validate request
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                 	        outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			adc_value = (get_adc(0))  # read ADC voltage 
			if adc_value > 511:                 # above half-way on the pot
            			wiringpi.digitalWrite(17, 0)    # motor spins one way
		                pwm = (adc_value - 511) * 2 -1
        		else:                               # below half-way on the pot
            			wiringpi.digitalWrite(17, 1)    # motor spins the other way
            			pwm = adc_value * 2 + 1

        		wiringpi.pwmWrite(18, pwm)          # send PWM value to port 18

			responseData = "%i" % (adc_value)
	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData	
	
	else:
		return ""
	# returning a zero length string tells the server that you have not matched 
	# the object and server 
	return ""
示例#27
0
def ExecuteUserObjects(objectType, element):

    global pictureFileStatus
    # Example Objects

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text
    objectAction = element.find("./OBJECTACTION").text
    objectName = element.find("./OBJECTNAME").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
    #
    # check to see if this is a Validate request
    #
    validate = Validate.checkForValidate(element)

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

    # Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    #
    #

    if objectAction == "SINGLEPUSH":

        if (objectServerID == "B-1"):
            # stop
            #check for validate request
            # validate allows RasPiConnect to verify this object is here

            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute
            #
            # Execute your code
            #
            #
            lego.stop()
            responseData = "OK"  ## send an OK back to the App
            # Done with your code
            #
            #

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-4"):

            # left
            #check for validate request
            # validate allows RasPiConnect to verify this object is here

            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            lego.turnLeft()
            responseData = "OK"  ## send an OK back to the App
            #
            #
            # Done with your code

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-5"):
            # right
            #check for validate request
            # validate allows RasPiConnect to verify this object is here

            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute
            #
            # Execute your code
            #
            #
            lego.turnRight()
            responseData = "OK"  ## send an OK back to the App
            # Done with your code
            #
            #

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-6"):
            # forwards
            #check for validate request
            # validate allows RasPiConnect to verify this object is here

            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            lego.moveForwards()
            responseData = "OK"  ## send an OK back to the App
            # Done with your code
            #
            #

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-7"):
            # backwards
            #check for validate request
            # validate allows RasPiConnect to verify this object is here

            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            lego.moveBackwards()
            responseData = "OK"  ## send an OK back to the App
            # Done with your code
            #
            #

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-8"):
            # shutdown
            #check for validate request
            # validate allows RasPiConnect to verify this object is here

            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute
            #
            # Execute your code
            #
            #
            os.system("sudo shutdown -h now")
            responseData = "OK"  ## send an OK back to the App
            # Done with your code
            #
            #

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-9"):
            #calibrate
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            responseData = "exit"
            print "exit "
            sys.exit()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        elif (objectServerID == "B-10"):
            #calibrate
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            responseData = "ok"
            lego.turn(90)

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        elif (objectServerID == "FB-1"):
            #calibrate
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            responseData = lego.calibrate()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        else:
            # returning a zero length string tells the server that you have not matched
            # the object and server
            print "unknown objectServerID ", objectServerID
            #lego.stop()

    elif (objectServerID == "LT-1"):
        #text box range
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        range = lego.getRange()
        responseData = "%d" % (range)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    elif (objectServerID == "LT-2"):
        #text box heading
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        heading = lego.getHeading()
        responseData = "%d" % (heading, )

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    elif (objectServerID == "SL-1"):
        #adjust speed
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        commandResponse = objectAction
        motorSpeed = float(commandResponse) * 2.5
        if motorSpeed > 250:
            motorSpeed = 250
        newValue = float(lego.setSpeed(
            int(motorSpeed))) / 2.5  # integer 0 to 100
        responseData = "%d" % (newValue)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return 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 = "legoraw.jpg"
        if pictureFileStatus == 0:
            imageName = "RovioImage.jpg"
            useCamera.takePicture("legoraw1.jpg")
            pictureFileStatus = 1
        elif pictureFileStatus == 1:
            imageName = "legoraw1.jpg"
            useCamera.takePicture("legoraw2.jpg")
            pictureFileStatus = 2
        else:
            imageName = "legoraw2.jpg"
            useCamera.takePicture("legoraw1.jpg")
            pictureFileStatus = 1

        responseData = "<html><head>"
        responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
        responseData += "</head>"

        responseData += "<body><img src=\""
        responseData += Config.localURL()
        responseData += "static/"
        responseData += imageName
        responseData += "\" type=\"jpg\" width=\"300\" height=\"300\">"
        responseData += "<BR>Picture<BR>"

        responseData += "</body>"

        responseData += "</html>"

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

        return outgoingXMLData

    else:
        # returning a zero length string tells the server that you have not matched
        # the object and server
        #lego.stop()
        return ""
示例#28
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 Execute_Send_Text(root):

        # find the interface object type

        objectServerID = root.find("./OBJECTSERVERID").text
        objectFlags = root.find("./OBJECTFLAGS").text
        objectAction = root.find("./OBJECTACTION").text

	if (objectAction == None):
		objectAction = ""

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

        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

	# ST-1 writes a file called "ST-1.txt" in the ./local directory with the contents of the text field on RasPiConnect

	if (objectServerID == "ST-1"):	

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

                        return outgoingXMLData
	
		
		responseData = "OK"

		f = open("./local/ST-1.txt", "w")
		f.write( objectAction)      
		f.close()

                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
				
示例#30
0
def ExecuteUserObjects(objectType, element):

	# fetch information from XML for use in user elements
	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)
        if (Config.debug()):
        	print "VALIDATE=%s" % validate

	# Build the header for the response
	outgoingXMLData = BuildResponse.buildHeader(element)

	# objects are split up by object types by Interface Constants
	# search for matches to object Type 

	# object Type match
	if (objectType == ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-2 - play a beep on the Raspberry Pi
		if (objectServerID == "B-2"):	
               		#check for validate request
			# validate allows RasPiConnect to verify this object is here 
        	       	if (validate == "YES"):
                	       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       		outgoingXMLData += BuildResponse.buildFooter()
	                       	return outgoingXMLData
			# not validate request, so execute
			# note that python is in the main directory for this call, not the local directory
			output = subprocess.call(["aplay", "sounds/match1.wav"])
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
	                return outgoingXMLData				
		# B-8 Shutdown
		if (objectServerID == "B-8"):	
              		#check for validate request
			# validate allows RasPiConnect to verify this object is here 
        	       	if (validate == "YES"):
                	       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       		outgoingXMLData += BuildResponse.buildFooter()
	                       	return outgoingXMLData

			# not validate request, so execute
			# note that python is in the main directory for this call, not the local directory
                      	output = subprocess.call(["sudo","shutdown","-a","now"])
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
	                return outgoingXMLData			



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

		tempData = "xx.x C (no i2c enabled)" 
		pressureData = "xxxx.x hPa (no i2c enabled)" 

				

		# read an HTML template into aw string		
		with open ("./Templates/camera.html", "r") as myfile:
    			responseData += myfile.read().replace('\n', '')
	
		# replace the URL so it will point to static
		responseData = responseData.replace("XXX", Config.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)
		outgoingXMLData += BuildResponse.buildResponse(responseData)

        	if (Config.debug()):
			print outgoingXMLData			

		
	# previous camera image
	elif (objectServerID == "W-2"):
	
		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()
			return outgoingXMLData

		imageName = "previous.jpg"	
		responseData =buildImageResponse(imageName)
		outgoingXMLData += BuildResponse.buildResponse(responseData)
		outgoingXMLData += BuildResponse.buildFooter()
		
        	if (Config.debug()):
			print outgoingXMLData	

	# latest camera image
	elif (objectServerID == "W-3"):
	
		#check for validate request
		if (validate == "YES"):
			outgoingXMLData += Validate.buildValidateResponse("YES")
			outgoingXMLData += BuildResponse.buildFooter()
			return outgoingXMLData
			
		imageName = "latest.jpg"
		responseData =buildImageResponse(imageName)	
		outgoingXMLData += BuildResponse.buildResponse(responseData)
		outgoingXMLData += BuildResponse.buildFooter()
		
        	if (Config.debug()):
			print outgoingXMLData	

	        return outgoingXMLData	
	else:
	
		# returning a zero length string tells the server that you have not matched 
		# the object and server 
		return ""
def Execute_Freq_Mod_LED(root):

        # find the interface object type

        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 (Config.debug()):
        	print("objectServerID = %s" % objectServerID)

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

	# L-1 sends back the current second to provide an interesting display 



	if (objectServerID == "BL-1"):	

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

                        return outgoingXMLData

		output = subprocess.check_output(["uptime", ""])
		list = output.split("average:")
		list2 = list[1].split(",")
        	if (Config.debug()):
			print list2
			print list2[0]	
		element = list2[0]

		FMOutput = 1/(float(element)*4.0+0.01)



		responseData = "%3.2f, %3.2f, %s" % (FMOutput, float(element),"CPU Load")


                outgoingXMLData += BuildResponse.buildResponse(responseData)


	else:

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


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

        return outgoingXMLData
示例#32
0
def ExecuteUserObjects(objectType, element):

	#
	# Fetch information from XML for use in user elements
	# objectServerID:	Control Code
	# objectType:		Interface constant (*_UITYPE)
	# objectName:		Display Name of Control
	# objectID:			???
	# objectFlags:		???
	# objectAction:		???
	objectServerID = element.find("./OBJECTSERVERID").text
	#objectType = element.find("./OBJECTTYPE").text
	objectName = element.find("./OBJECTNAME").text
	objectID = element.find("./OBJECTID").text
	objectFlags = element.find("./OBJECTFLAGS").text
	objectAction = element.find("./OBJECTACTION").text

	if LocalDEBUG:
		print("=====================================")
		print("objectServerID\t= %s" % objectServerID)
		print("objectType\t= %s" % objectType)
		print("objectName\t= %s" % objectName)
		print("objectID\t= %s" % objectID)
		print("objectFlags\t= %s" % objectFlags)
		print("objectAction\t= %s" % objectAction)

	#
	# Check if this is a Validate request
	#
	validate = Validate.checkForValidate(element)
	bValidate = False
	if (validate == "YES"):
		bValidate = True

	if LocalDEBUG:
		print("VALIDATE\t= %s" % validate)

	#
	# Run handler and get the response; update activity for the handler
	#
	responseData = ""
	handlers = ObjectServerHandlers.handlers_for_address(objectServerID)
	for handler in handlers:
		if len(handler.args) > 0:
			handler.args[1] = objectName
			handler.args[2] = objectAction
			responseData = handler.callback(handler.args, bValidate)
			ObjectServerHandlers.activity_for_handler(handler.callback)

	#
	# Update the activity metric for all handlers
	#
	ObjectServerHandlers.update_handlers_activity()
	
	if LocalDEBUG:
		print("-------------------------------------")
		for addr, handlers in ObjectServerHandlers._map.items():
			for handler in handlers:
				print("{:8s}()\t: {:4.2f}".format(handler.callback.__name__, ObjectServerHandlers.activity_metric[handler.callback.__name__]))

	# Return a zero length string when no match for the objectServerID was found	
	if len(responseData) == 0:
		return ""
	
	#	
	# Build the header
	#
	outgoingXMLData = BuildResponse.buildHeader(element)

	#
	# Build a valid response
	#			
	if responseData == "VALIDATED":
		# Build VALIDATED response 
		outgoingXMLData += Validate.buildValidateResponse("YES")
	
	else:	
		# Build respose 
		outgoingXMLData += BuildResponse.buildResponse(responseData)

	#
	# Build footer
	#	
	outgoingXMLData += BuildResponse.buildFooter()
	#if LocalDEBUG:
	#	print(outgoingXMLData)

	#
	# Return XML response
	#
	return outgoingXMLData
示例#33
0
def handleCameraStatusUpdate(validate):
  
  global lastFileCount
  
  #check for validate request
  outgoingXMLData =""	
  if (validate == "YES"):
	outgoingXMLData = Validate.buildValidateResponse("YES")
	outgoingXMLData += BuildResponse.buildFooter()
  else:	
	responseData = ""
	fileCount =  readFileCount()			

	# read an HTML template into aw string		
	with open ("./Templates/camera.html", "r") as myfile:
   		responseData += myfile.read().replace('\n', '')
	
	# replace the URL so it will point to static
	responseData = responseData.replace("XXX", Config.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", str(fileCount))	
	responseData = responseData.replace("FFF", str(lastFileCount))	

	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", "wlan0"])	
	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 = "No data"

	responseData = responseData.replace("KKK", sendTextData)
	outgoingXMLData += BuildResponse.buildResponse(responseData)
	outgoingXMLData += BuildResponse.buildFooter()

        if (Config.debug()):
	  print outgoingXMLData	

  return outgoingXMLData
示例#34
0
def ExecuteUserObjects(objectType, element):

	global lastFileCount
	# fetch information from XML for use in user elements
	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)
        if (Config.debug()):
        	print "VALIDATE=%s" % validate

	# Build the header for the response
	outgoingXMLData = BuildResponse.buildHeader(element)

	# objects are split up by object types by Interface Constants
	# search for matches to object Type 
	# object Type match
	if (objectType == ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-2 - play a beep on the Raspberry Pi
		if (objectServerID == "B-2"):	
               		#check for validate request
			# validate allows RasPiConnect to verify this object is here 
        	       	if (validate == "YES"):
                	       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       		outgoingXMLData += BuildResponse.buildFooter()
	                       	return outgoingXMLData
			# not validate request, so execute
			# note that python is in the main directory for this call, not the local directory
			output = subprocess.call(["aplay", "sounds/match1.wav"])
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
	                return outgoingXMLData				
		# B-7 get next image
		elif (objectServerID == "B-7"):	
              		#check for validate request
			# validate allows RasPiConnect to verify this object is here 
        	       	if (validate == "YES"):
                	       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       		outgoingXMLData += BuildResponse.buildFooter()
	                       	return outgoingXMLData

			# not validate request, so execute
			# note that python is in the main directory for this call, not the local directory
                    	# check this is not the first file to be copied
                    	fileCount = readFileCount()
                    	print "lastFileCount = %d" % lastFileCount
                    	if (lastFileCount == -1):
                    		lastFileCount = fileCount
                    		# make sure that a latest file exists - should use excpetions really!
				filename ="/home/pi/imageprocessing/capture-%06d.jpg" %lastFileCount
				subprocess.call("cp %s ~/RasPiConnectServer/static/latest.jpg" %filename, shell=True)
 				subprocess.call("cp %s ~/RasPiConnectServer/static/previous.jpg" %filename, shell=True)
                    	                   	
			if(fileCount !=-1):
	                      	if (lastFileCount < fileCount):
	                      	  lastFileCount+=1
	                      	subprocess.call("mv ~/RasPiConnectServer/static/latest.jpg ~/RasPiConnectServer/static/previous.jpg", shell=True)
				filename ="/home/pi/imageprocessing/capture-%06d.jpg" %lastFileCount
				subprocess.call("cp %s ~/RasPiConnectServer/static/latest.jpg" %filename, shell=True)
                    	print "lastFileCount = %d" % lastFileCount
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
	                return outgoingXMLData			
		# B-8 Shutdown
		elif (objectServerID == "B-8"):	
              		#check for validate request
			# validate allows RasPiConnect to verify this object is here 
        	       	if (validate == "YES"):
                	       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       		outgoingXMLData += BuildResponse.buildFooter()
	                       	return outgoingXMLData

			# not validate request, so execute
			# note that python is in the main directory for this call, not the local directory
                      	output = subprocess.call(["sudo","shutdown","-a","now"])
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
	                return outgoingXMLData		

	elif (objectServerID == "W-1"):
		
		outgoingXMLData +=  handleCameraStatusUpdate(validate)
		return outgoingXMLData
	       
	elif (objectServerID == "W-2"):
	
		outgoingXMLData += handleImageRequest(validate,"previous.jpg")
	        return outgoingXMLData	

	elif (objectServerID == "W-3"):
	
		outgoingXMLData += handleImageRequest(validate, "latest.jpg")
	        return outgoingXMLData	

	# FB-1 next image with text
	elif (objectServerID == "FB-1"):	

	        outgoingXMLData += handleFeedBackButtonRequest(validate)
	        return outgoingXMLData
	else:
	
		# returning a zero length string tells the server that you have not matched 
		# the object and server 
		return ""
示例#35
0
def ExecuteUserObjects(objectType, element):

    # Example Objects

    # fetch information from XML for use in user elements

    # objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text
    # find the interface object type
    objectName = element.find("./OBJECTNAME").text
    objectFlags = element.find("./OBJECTFLAGS").text

    if Config.debug():
        print ("objectServerID = %s" % objectServerID)
    #
    # check to see if this is a Validate request
    #
    validate = Validate.checkForValidate(element)

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

    # Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    # objects are split up by object types by Interface Constants
    #
    #
    #
    # search for matches to object Type

    # object Type match
    if objectType == COMPLEX_LINE_GRAPH_LIVE_UITYPE:

        if Config.debug():
            print "COMPLEX_LINE_GRAPH_LIVE_UITYPE of %s found" % objectServerID

            # CLGL-1 - ultrasonic graph
        if objectServerID == "CLGL-1":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # normal response requested
            try:
                f = open("/home/pi/MouseAir/state/UltrasonicGraph.txt", "r")
                commandresponse = f.read()
                f.close()
            except IOError as e:
                commandresponse = "0^^0||No Data from MouseAir^^"

            outgoingXMLData += BuildResponse.buildResponse(commandresponse)

            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # object Type match
    if objectType == SIMPLE_LINE_GRAPH_LIVE_UITYPE:

        if Config.debug():
            print "SIMPLE_LINE_GRAPH_LIVE_UITYPE of %s found" % objectServerID

            # SLGL-1 - ultrasonic graph
        if objectServerID == "SLGL-1":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # normal response requested
            try:
                f = open("/home/pi/MouseAir/state/UltrasonicGraph.txt", "r")
                commandresponse = f.read()
                f.close()
            except IOError as e:
                commandresponse = "0^^0||No Data from MouseAir^^"

            outgoingXMLData += BuildResponse.buildResponse(commandresponse)

            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # object Type match
    if objectType == PICTURE_REMOTE_WEBVIEW_UITYPE:

        if Config.debug():
            print "PICTURE_REMOTE_WEBVIEW_UITYPE of %s found" % objectServerID

            # W-10 - play a beep on the Raspberry Pi
        if objectServerID == "W-10":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # normal response requested

            imageName = "picamera.jpg"

            responseData = "<html><head>"
            responseData += "<META HTTP-EQUIV='CACHE-CONTROL' CONTENT='NO-CACHE'>"
            responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
            responseData += "</head>"

            responseData += '<body><img src="'
            responseData += Config.localURL()
            responseData += "static/"
            responseData += imageName
            responseData += '" type="jpg" width="585" height="300">'

            responseData += "</body>"

            responseData += "</html>"

            outgoingXMLData += BuildResponse.buildResponse(responseData)

            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # object Type match
    if objectType == ACTION_BUTTON_UITYPE:

        if Config.debug():
            print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

            # B-10 - fire Mouse
        if objectServerID == "B-10":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-10 Fire Mouse"
            status = sendCommandToMouseAirAndWait("FIREMOUSE")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-11 - take picture
        if objectServerID == "B-11":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-11 Take Picture"
            status = sendCommandToMouseAirAndWait("TAKEPICTURE")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-13 - Pan to Mouse watch
        if objectServerID == "B-13":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-13 Pan to Watch Mouse"
            status = sendCommandToMouseAirAndWait("PANTOMOUSE")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-14 - Pan to Cat watch
        if objectServerID == "B-14":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-14 Pan to Watch Cat"
            status = sendCommandToMouseAirAndWait("PANTOCAT")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-15 - Shoot Solenoid
        if objectServerID == "B-15":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-15 Shoot Solenoid "
            status = sendCommandToMouseAirAndWait("SHOOTSOLENOID")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-16 - Pan Left
        if objectServerID == "B-16":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-16 Pan Left"
            status = sendCommandToMouseAirAndWait("PANLEFT")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-17 - Pan Right
        if objectServerID == "B-17":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-17 Pan Right"
            status = sendCommandToMouseAirAndWait("PANRIGHT")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-18 - Tilt Up
        if objectServerID == "B-18":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-18 Tilt Up "
            status = sendCommandToMouseAirAndWait("TILTUP")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # B-19 - Tilt Down
        if objectServerID == "B-19":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            print "set B-19 Tilt Down"
            status = sendCommandToMouseAirAndWait("TILTDOWN")

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # object Type match
    if objectType == FEEDBACK_ACTION_BUTTON_UITYPE:

        if Config.debug():
            print "FEEDBACK_ACTION_BUTTON_UTYPE of %s found" % objectServerID

            # FB-10 -  turn ultrasonics on and off
        if objectServerID == "FB-10":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            responseData = "XXX"

            if objectName is None:
                objectName = "XXX"

            lowername = objectName.lower()

            if lowername == "ultrasonic on":

                status = sendCommandToMouseAirAndWait("ULTRASONICON")
                responseData = "ultrasonic off"
                responseData = responseData.title()

            elif lowername == "ultrasonic off":

                status = sendCommandToMouseAirAndWait("ULTRASONICOFF")
                responseData = "ultrasonic on"
                responseData = responseData.title()

                # defaults to off
            else:
                status = sendCommandToMouseAirAndWait("ULTRASONICOFF")
                lowername = "ultrasonic on"
                responseData = lowername.title()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # FB-11 -  turn RFID on and off
        if objectServerID == "FB-11":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            responseData = "XXX"

            if objectName is None:
                objectName = "XXX"

            lowername = objectName.lower()

            if lowername == "rfid on":

                status = sendCommandToMouseAirAndWait("RFIDON")
                responseData = "RFID off"
                responseData = responseData.title()

            elif lowername == "rfid off":

                status = sendCommandToMouseAirAndWait("RFIDOFF")
                responseData = "RFID on"
                responseData = responseData.title()

                # defaults to off
            else:
                status = sendCommandToMouseAirAndWait("RFIDOFF")
                lowername = "RFID on"
                responseData = lowername.title()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # FB-12 -  turn USECAMERAMOTION on and off
        if objectServerID == "FB-11":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            responseData = "XXX"

            if objectName is None:
                objectName = "XXX"

            lowername = objectName.lower()

            if lowername == "camera motion on":

                status = sendCommandToMouseAirAndWait("CAMERAMOTIONON")
                responseData = "camera motion off"
                responseData = responseData.title()

            elif lowername == "camera motion off":

                status = sendCommandToMouseAirAndWait("CAMERAMOTIONOFF")
                responseData = "camera motion on"
                responseData = responseData.title()

                # defaults to off
            else:
                status = sendCommandToMouseAirAndWait("CAMERAMOTIONOFF")
                lowername = "camera motion on"
                responseData = lowername.title()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # FB-13 -  turn top servo on
        if objectServerID == "FB-13":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            responseData = "XXX"

            if objectName is None:
                objectName = "XXX"

            lowername = objectName.lower()

            print ("lowername =", lowername)

            if lowername == "top servo close":

                print "set top servo close"
                status = sendCommandToMouseAirAndWait("TOPSERVOCLOSE")
                responseData = "top servo open"
                responseData = responseData.title()

            elif lowername == "top servo open":

                print "set top servo open"
                status = sendCommandToMouseAirAndWait("TOPSERVOOPEN")
                responseData = "top servo close"
                responseData = responseData.title()

                # defaults to top servo closed
            else:
                print "set top servo close"
                status = sendCommandToMouseAirAndWait("TOPSERVOCLOSE")
                lowername = "top servo open"
                responseData = lowername.title()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # FB-15 -  turn bottom servo on
        if objectServerID == "FB-15":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            responseData = "XXX"

            if objectName is None:
                objectName = "XXX"

            lowername = objectName.lower()

            print ("lowername =", lowername)

            if lowername == "bottom servo close":

                print "set bottom servo close"
                status = sendCommandToMouseAirAndWait("BOTTOMSERVOCLOSE")
                responseData = "bottom servo open"
                responseData = responseData.title()

            elif lowername == "bottom servo open":

                print "set bottom servo open"
                status = sendCommandToMouseAirAndWait("BOTTOMSERVOOPEN")
                responseData = "bottom servo close"
                responseData = responseData.title()

                # defaults to top servo closed
            else:
                print "set bottom servo close"
                status = sendCommandToMouseAirAndWait("BOTTOMSERVOCLOSE")
                lowername = "bottom servo open"
                responseData = lowername.title()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        # FB-16 -  turn motors on
        if objectServerID == "FB-16":

            # check for validate request
            # validate allows RasPiConnect to verify this object is here
            if validate == "YES":
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

            # not validate request, so execute

            responseData = "XXX"

            if objectName is None:
                objectName = "XXX"

            lowername = objectName.lower()

            if lowername == "motors on":

                print "set Motors On"
                status = sendCommandToMouseAirAndWait("MOTORSON")
                responseData = "motors Off"
                responseData = responseData.title()

            elif lowername == "motors off":

                status = sendCommandToMouseAirAndWait("MOTORSOFF")
                responseData = "Motors On"
                responseData = responseData.title()

                # defaults to Motors off
            else:
                print "Motors Off"
                status = sendCommandToMouseAirAndWait("MOTORSOFF")
                lowername = "Motors On"
                responseData = lowername.title()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

    else:
        return ""
        # returning a zero length string tells the server that you have not matched
        # the object and server
    return ""
示例#36
0
def Execute_Meter(root):

      # find the interface object type


	objectServerID = root.find("./OBJECTSERVERID").text
	objectID = root.find("./OBJECTID").text

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

	validate = Validate.checkForValidate(root)

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

	outgoingXMLData = BuildResponse.buildHeader(root)


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

	# M-1 sends back the power supply voltage 
	# M-2 sends back the number of processes running on the Raspberry Pi 


	# M-1
	if (objectServerID == "M-1"):	


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

			return outgoingXMLData

		import random
		if (Config.debug()):
			print(random.randrange(0,9))
		voltage = 5.0 + (random.randrange(0,9)-5)/10.0
		responseData = "%f" % voltage
		outgoingXMLData += BuildResponse.buildResponse(responseData)

	# M-2
	elif (objectServerID == "M-2"):	

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

			return outgoingXMLData

		p1 = subprocess.Popen(['ps', 'xaf'], stdout=subprocess.PIPE)
		p3 = subprocess.Popen(['wc', '-l'], stdin=p1.stdout,stdout=subprocess.PIPE)
		p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p3 exits.
		output = p3.communicate()[0]
		numberofprocesses = int(output)
		responseData = "%i" % numberofprocesses
		outgoingXMLData += BuildResponse.buildResponse(responseData)
	else:
		# invalid RaspiConnect Code
		outgoingXMLData += Validate.buildValidateResponse("NO")


	outgoingXMLData += BuildResponse.buildFooter()

	return outgoingXMLData
示例#37
0
def ExecuteUserObjects(objectType, element):

    # Example Objects

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
#
# check to see if this is a Validate request
#
    validate = Validate.checkForValidate(element)

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

# Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    # objects are split up by object types by Interface Constants
    #
    #
    #
    # search for matches to object Type

    # object Type match
    if (objectType == ACTION_BUTTON_UITYPE):

        if (Config.debug()):
            print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

        # B-2 - play a beep on the Raspberry Pi
        if (objectServerID == "B-2"):

            #check for validate request
            # validate allows RasPiConnect to verify this object is here
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        # not validate request, so execute

        # note that python is in the main directory for this call, not the local directory

            output = subprocess.call(["aplay", "sounds/match1.wav"])

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

    else:
        return ""
# returning a zero length string tells the server that you have not matched
# the object and server
    return ""
示例#38
0


        			except mdb.Error, e:
		
                			print "Error %d: %s" % (e.args[0],e.args[1])

        			finally:
		
                			cursor.close()
                			db.close()
			
                			del cursor
                			del db
		
                		outgoingXMLData += BuildResponse.buildResponse(responseData)
                		outgoingXMLData += BuildResponse.buildFooter()
                		return outgoingXMLData



		else:
			imageName = "PowerVoltageGraph.png"



              	responseData = "<html><head>"
                responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
		responseData += "<META HTTP-EQUIV='CACHE-CONTROL' CONTENT='NO-CACHE, MUST-REVALIDATE'>"
		responseData += "<META HTTP-EQUIV='PRAGMA' CONTENT='NO-CACHE'>"
                responseData += "</head>"
示例#39
0
def Execute_Meter(root):

      # find the interface object type


        objectServerID = root.find("./OBJECTSERVERID").text
        objectID = root.find("./OBJECTID").text

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

        validate = Validate.checkForValidate(root)

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

        outgoingXMLData = BuildResponse.buildHeader(root)


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

	# M-1 sends back the power supply voltage 
	# M-2 sends back the number of processes running on the Raspberry Pi 


	# M-1
	if (objectServerID == "M-1"):	


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

                        return outgoingXMLData

		import random
        	if (Config.debug()):
	        	print random.randrange(0,9)
		voltage = 5.0 + (random.randrange(0,9)-5)/10.0
		responseData = "%f" % voltage
                outgoingXMLData += BuildResponse.buildResponse(responseData)

	# M-2
	elif (objectServerID == "M-2"):	

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

                        return outgoingXMLData

		p1 = subprocess.Popen(['ps', 'xaf'], stdout=subprocess.PIPE)
		p3 = subprocess.Popen(['wc', '-l'], stdin=p1.stdout,stdout=subprocess.PIPE)
		p1.stdout.close()  # Allow p1 to receive a SIGPIPE if p3 exits.
		output = p3.communicate()[0]
		numberofprocesses = int(output)
		responseData = "%i" % numberofprocesses
                outgoingXMLData += BuildResponse.buildResponse(responseData)
        else:
                # invalid RaspiConnect Code
                outgoingXMLData += Validate.buildValidateResponse("NO")


        outgoingXMLData += BuildResponse.buildFooter()

        return outgoingXMLData




# End of ExecuteMeter.py
				
示例#40
0
文件: Local.py 项目: windy54/RobotPI
def ExecuteUserObjects(objectType, element):

	global led1State
	global led2State
	global forwardState
	global rearState
	global rr

	# Example Objects

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)


	# objects are split up by object types by Interface Constants
	#
	#
	#
	# search for matches to object Type 

	# object Type match
	if (objectType == ACTION_BUTTON_UITYPE):
		#print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-2 - play a beep on the Raspberry Pi
		if (objectServerID == "B-2"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			# note that python is in the main directory for this call, not the local directory

			output = subprocess.call(["aplay", "sounds/match1.wav"])
			
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
		elif (objectServerID == "B-4"):	
	          #print "button B-4"

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

                        return outgoingXMLData

                  if(led1State):
                    led1State=False
		    responseData = "OFF"
		    rr.set_led1(False)
		    rr.stop()
		    #print "led1 true"
		  else:
                    led1State=True
		    responseData = " ON"
		    rr.set_led1(True)
		    rr.right()
		    #print "led1 false"
		  responseData = "OK"
                  outgoingXMLData += BuildResponse.buildResponse(responseData)
      		  outgoingXMLData += BuildResponse.buildFooter()
                  return outgoingXMLData
		elif (objectServerID == "B-5"):	
	          #print "button B-5"

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

                        return outgoingXMLData

                  if(led2State):
                    led2State=False
		    responseData = "OFF"
		    rr.set_led2(False)
		    rr.stop()
		    #print "led2 true"
		  else:
                    led2State=True
		    responseData = " ON"
		    rr.set_led2(True)
		    rr.left()
		    #print "led2 false"
		  responseData = "OK"
                  outgoingXMLData += BuildResponse.buildResponse(responseData)
      		  outgoingXMLData += BuildResponse.buildFooter()
                  return outgoingXMLData		
		elif (objectServerID == "B-6"):	
		  #forwards
	          #print "button B-4"

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

                        return outgoingXMLData

                  if(forwardState):
                    forwardState=False
		    responseData = "OFF"
		    rr.set_led1(False)
		    rr.set_led2(False)
		    rr.stop()
		    #print "forward true"
		  else:
                    forwardState=True
		    responseData = " ON"
		    rr.set_led1(False)
		    rr.set_led2(False)
		    rr.forward()
		    #print "forward false"
		  responseData = "OK"
                  outgoingXMLData += BuildResponse.buildResponse(responseData)
      		  outgoingXMLData += BuildResponse.buildFooter()
                  return outgoingXMLData
		elif (objectServerID == "B-7"):	
		  # rear
	          #print "button B-7"

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

                        return outgoingXMLData

                  if(rearState):
                    rearState=False
		    responseData = "OFF"
		    rr.set_led1(False)
		    rr.set_led2(False)
		    rr.stop()
		    #print "led2 true"
		  else:
                    rearState=True
		    responseData = " ON"
		    rr.set_led1(True)
		    rr.set_led2(True)
		    rr.reverse()
		    #print "led2 false"
		  responseData = "OK"
                  outgoingXMLData += BuildResponse.buildResponse(responseData)
      		  outgoingXMLData += BuildResponse.buildFooter()
                  return outgoingXMLData	
		elif (objectServerID == "B-8"):	
		  # rear
	          #print "button B-8"

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

                        return outgoingXMLData
		  rr.stop()
		  os.system("sudo shutdown -h now")
		  responseData = "OK"
                  outgoingXMLData += BuildResponse.buildResponse(responseData)
      		  outgoingXMLData += BuildResponse.buildFooter()
                  return outgoingXMLData	

	elif (objectServerID == "W-2"):
			if (validate == "YES"):
				outgoingXMLData += Validate.buildValidateResponse("YES")
				outgoingXMLData += BuildResponse.buildFooter()
				return outgoingXMLData
			
			os.system("raspistill -o static/camImage.jpg -t 0")	
			imageName = "camImage.jpg"	

			responseData = "<html><head>"
			responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}</style>"
			responseData += "</head>"	
			responseData += "<body><img src=\""
 			responseData += Config.localURL()
 			responseData += "static/"
			responseData += imageName
			responseData += "\" type=\"jpg\" width=\"300\" height=\"300\">"
			responseData += "<BR>Picture<BR>"
			responseData +="</body>static"		
			responseData += "</html>"		
			outgoingXMLData += BuildResponse.buildResponse(responseData)
      		  	outgoingXMLData += BuildResponse.buildFooter()
	                return outgoingXMLData			

        		if (Config.debug()):
				print outgoingXMLData	
	elif (objectServerID == "FB-1"):	
		# do a toggle
		print "FB-1"

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


		responseData = "False"
		if (rr.sw1_closed()):
		  responseData = "True "

	
                outgoingXMLData += BuildResponse.buildResponse(responseData)
 	  	outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData	
	else:
		return ""
	# returning a zero length string tells the server that you have not matched 
	# the object and server 
	return ""
示例#41
0
def ExecuteUserObjects(objectType, element):

	# Example Objects
	global port25
	global port24

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)


	# objects are split up by object types by Interface Constants
	#
	#
	#
	# search for matches to object Type 

	# object Type match
	print("+++++++++++OBJECTTYPE %i" % objectType)
	if (objectType == ACTION_BUTTON_UITYPE):

		if (Config.debug()):
			print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

		# B-2 - play a beep on the Raspberry Pi
		if (objectServerID == "B-2"):	

                	#check for validate request
			# validate allows RasPiConnect to verify this object is here 
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                        	outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData

			# not validate request, so execute

			# note that python is in the main directory for this call, not the local directory

			output = subprocess.call(["aplay", "sounds/match1.wav"])
			
			responseData = "OK"
                	outgoingXMLData += BuildResponse.buildResponse(responseData)
      			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
	if (objectType == TEXT_DISPLAY_UITYPE):
		
        	if (objectServerID == "LT-1"):	

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

                        	return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
			output = GPIO.VERSION
			FMOutput = 1000.0
			
			print "VERSION++++++++++++++=%s" % output

			responseData = "%3.2f, %3.2f, %s" % (FMOutput,FMOutput, output,)

	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
                	
        	if (objectServerID == "LT-2"):	

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

                        	return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
			output = GPIO.RPI_REVISION
			FMOutput = 2222.0

			
                        print "VERSION---------=%s" % output



			responseData = "%3.2f, %3.2f, %s" % (output,output, "RPI Version")

	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData

	if (objectType == SINGLE_LED_DISPLAY ):

        	        #check for validate request
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                 	        outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
			if(port25):
			  GPIO.output(25,0)
			  port25=False
			  ledColour = 5
			  print "Led off"
			else:
			  GPIO.output(25,1)
			  port25=True
			  ledColour=2
			  print "Led on"
			
			responseData = "%i" % (ledColour)


	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData	
	if (objectType == FEEDBACK_ACTION_BUTTON_UITYPE):
        	        #check for validate request
                	if (validate == "YES"):
                        	outgoingXMLData += Validate.buildValidateResponse("YES")
                 	        outgoingXMLData += BuildResponse.buildFooter()
                        	return outgoingXMLData
			if(port24):
			  GPIO.output(24,0)
			  port24=False
			  responseData = "Port 24 Led off"
			else:
			  GPIO.output(24,1)
			  port24=True
			  responseData = "port 24 Led on"
			
	                outgoingXMLData += BuildResponse.buildResponse(responseData)
     			outgoingXMLData += BuildResponse.buildFooter()
                	return outgoingXMLData
	else:
		return ""
	# returning a zero length string tells the server that you have not matched 
	# the object and server 
	return ""
示例#42
0
def ExecuteUserObjects(objectType, element):

    global pictureFileStatus
    # Example Objects

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID       = element.find("./OBJECTID").text
    objectAction   = element.find("./OBJECTACTION").text
    objectName     = element.find("./OBJECTNAME").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
    # 
    # check to see if this is a Validate request
    #
    validate = Validate.checkForValidate(element)

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

        
    # Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    #
    #
    
    if objectAction=="SINGLEPUSH":
        
        if (objectServerID == "B-1"):
                # stop
                #check for validate request
                # validate allows RasPiConnect to verify this object is here 

                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # not validate request, so execute
                #
                # Execute your code
                #
                #
                lego.stop()
                responseData = "OK" ## send an OK back to the App
                # Done with your code
                #
                #

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        elif (objectServerID == "B-4"): 

                # left
                #check for validate request
                # validate allows RasPiConnect to verify this object is here 

                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # not validate request, so execute

                lego.turnLeft()
                responseData = "OK" ## send an OK back to the App
                #
                #
                # Done with your code

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
                


        elif (objectServerID == "B-5"):
                # right
                #check for validate request
                # validate allows RasPiConnect to verify this object is here 

                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # not validate request, so execute
                #
                # Execute your code
                #
                #
                lego.turnRight()
                responseData = "OK" ## send an OK back to the App
                # Done with your code
                #
                #

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        elif (objectServerID == "B-6"):
                # forwards
                #check for validate request
                # validate allows RasPiConnect to verify this object is here 

                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # not validate request, so execute

                lego.moveForwards()
                responseData = "OK" ## send an OK back to the App
                # Done with your code
                #
                #

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

                
        elif (objectServerID == "B-7"):
                # backwards
                #check for validate request
                # validate allows RasPiConnect to verify this object is here 

                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # not validate request, so execute

                lego.moveBackwards()
                responseData = "OK" ## send an OK back to the App
                # Done with your code
                #
                #

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

                
        elif (objectServerID == "B-8"):
                # shutdown
                #check for validate request
                # validate allows RasPiConnect to verify this object is here 

                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # not validate request, so execute
                #
                # Execute your code
                #
                #
                os.system("sudo shutdown -h now")
                responseData = "OK" ## send an OK back to the App
                # Done with your code
                #
                #

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        elif (objectServerID == "B-9"):
                #calibrate
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData
                
                responseData = "exit"
                print "exit "
                sys.exit()

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData  

        elif (objectServerID == "B-10"):
                #calibrate
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData
                
                responseData = "ok"
                lego.turn(90)

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
        elif (objectServerID == "FB-1"):
            #calibrate
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
        
            responseData = lego.calibrate()

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData


        else:
                # returning a zero length string tells the server that you have not matched 
                # the object and server 
                print "unknown objectServerID ",objectServerID
                #lego.stop()
                                
    elif (objectServerID == "LT-1"):
        #text box range
        if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
        range = lego.getRange()
        responseData = "%d" % (range)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData
        
    elif (objectServerID == "LT-2"):
        #text box heading
        if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
        heading = lego.getHeading()
        responseData = "%d" % (heading,)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData


    elif (objectServerID == "SL-1"):
        #adjust speed
        if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
        
        commandResponse = objectAction
        motorSpeed = float(commandResponse) * 2.5
        if  motorSpeed > 250:
            motorSpeed = 250
        newValue =  float(lego.setSpeed( int(motorSpeed) ) ) / 2.5 # integer 0 to 100
        responseData = "%d" % (newValue)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return 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 = "legoraw.jpg"
        if pictureFileStatus == 0:
            imageName = "RovioImage.jpg"
            useCamera.takePicture("legoraw1.jpg")
            pictureFileStatus = 1
        elif pictureFileStatus == 1:
            imageName = "legoraw1.jpg"
            useCamera.takePicture("legoraw2.jpg")
            pictureFileStatus = 2
        else:
            imageName = "legoraw2.jpg"
            useCamera.takePicture("legoraw1.jpg")
            pictureFileStatus = 1
        

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

        responseData +="</body>"
        
        responseData += "</html>"
    
        
        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        if (Config.debug()):
            print outgoingXMLData

        return outgoingXMLData  

    else:
        # returning a zero length string tells the server that you have not matched 
        # the object and server 
        #lego.stop()
        return ""
示例#43
0
def ExecuteUserObjects(objectType, element):


	# Example Objects

	# fetch information from XML for use in user elements

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text
	objectAction = element.find(".OBJECTACTION").text	
	objectName = element.find("./OBJECTNAME").text
        objectFlags = element.find("./OBJECTFLAGS").text


        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)

	# SS-1 - Server Present 
        if (objectServerID == "SS-1"):

                #check for validate request
                # validate allows RasPiConnect to verify this object is here
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		answ = "2"
		#answ = ""
		if (Config.debug()):
			print "In local SS-1"
			print("answ = %s" % answ)
		responseData = answ
		print "sampling weather"
		sendCommandToWeatherPiAndWait("SAMPLEBOTH")

		# now setup internal variables

		setupWeatherStats()
		setupSunAirPlusStats()

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
		


	# B-1 - Sample Both and Do All Graphs 
        if (objectServerID == "B-1"):

                #check for validate request
                # validate allows RasPiConnect to verify this object is here
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		answ = "OK"
		#answ = ""
		if (Config.debug()):
			print "In local B-1"
			print("answ = %s" % answ)

		print "sampling weather"
		sendCommandToWeatherPiAndWait("SAMPLEBOTHGRAPHS")

		# now setup internal variables

		setupWeatherStats()
		setupSunAirPlusStats()

		responseData = "OK"

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
		
	# FB-2 - Graph Selection Feedback
        if (objectServerID == "FB-2"):

                #check for validate request
                # validate allows RasPiConnect to verify this object is here
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		responseData = "XXX"
		if (objectName is None):
			objectName = "XXX"
		
		lowername = objectName.lower()
		
		if (lowername == "wind graph"):

			responseData = "temp / hum graph"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()

		elif (lowername == "temp / hum graph"):

			responseData = "baro graph"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()

		elif (lowername == "baro graph"):

			responseData = "voltage graph"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()

		elif (lowername == "voltage graph"):

			responseData = "system logs"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()
		
		elif (lowername == "system logs"):

			responseData = "current graph"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()

		elif (lowername == "current graphs"):

			responseData = "wind graph"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()

		else: 
			# default value
			responseData = "temp / hum graph"
			responseData = responseData.title()	
               		f = open("./local/GraphSelect.txt", "w")
               		f.write(lowername)
               		f.close()




		if (Config.debug()):
			print "In local FB-2"
			print("responseData = %s" % responseData)

                outgoingXMLData += BuildResponse.buildResponse(responseData)
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
		
	# W-1 - Graph View 
        if (objectServerID == "W-1"):

                #check for validate request
                # validate allows RasPiConnect to verify this object is here
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		#answ = ""
		if (Config.debug()):
			print "In local W-1"


		lowername = "voltage graph"

		try:
              		f = open("./local/GraphSelect.txt", "r")
               		tempString = f.read()
               		f.close()
			lowername = tempString 		

		except IOError as e:
			print "I/O error({0}): {1}".format(e.errno, e.strerror)

                
		print "lowername=", lowername	
		if (lowername == "voltage graph"):

			imageName = "PowerVoltageGraph.png"

		elif (lowername == "current graph"):

			imageName = "PowerCurrentGraph.png"
		
		elif (lowername == "baro graph"):

			imageName = "BarometerLightningGraph.png"

		elif (lowername == "temp / hum graph"):

			imageName = "TemperatureHumidityGraph.png"
		
		elif (lowername == "system logs"):

				# grab the system logs
				with open ("./Templates/W-16-SL.html", "r") as myfile:
					import time
					responseData = "System Time: "
					responseData +=  time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
					responseData += "<BR>\n"
    					responseData += myfile.read().replace('\n', '')
		
		        	try:
                			print("trying database")
					DATABASEPASSWORD = "******"
                			db = mdb.connect('localhost', 'root', DATABASEPASSWORD, 'WeatherPi');
		
                			cursor = db.cursor()


					query = "SELECT TimeStamp, Level, Source, Message FROM systemlog ORDER BY ID DESC LIMIT 30"
                			cursor.execute(query)

					rows = cursor.fetchall()
					CRITICAL=50
					ERROR=40
					WARNING=30
					INFO=20
					DEBUG=10
					NOTSET=0

					for row in rows:
						level = row[1]	
						levelName = "NONE"
						if (level == DEBUG):
							levelName = "DEBUG"
						if (level == INFO):
							levelName = "INFO"
						if (level == WARNING):
							levelName = "WARNING"
						if (level == ERROR):
							levelName = "ERROR"
						if (level == CRITICAL):
							levelName = "CRITICAL"

						logline = "%s:%s:%s:%s" % (row[0], levelName, row[2], row[3] )
						line = logline+"<BR>\n<!--INSERTLOGS-->"	

						responseData = responseData.replace("<!--INSERTLOGS-->", line)	



        			except mdb.Error, e:
		
                			print "Error %d: %s" % (e.args[0],e.args[1])

        			finally:
示例#44
0
def ExecuteUserObjects(objectType, element):

    # fetch information from XML for use in user elements
    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
#
# check to see if this is a Validate request
#
    validate = Validate.checkForValidate(element)
    if (Config.debug()):
        print "VALIDATE=%s" % validate

# Build the header for the response
    outgoingXMLData = BuildResponse.buildHeader(element)

    # objects are split up by object types by Interface Constants
    # search for matches to object Type

    # object Type match
    if (objectType == ACTION_BUTTON_UITYPE):

        if (Config.debug()):
            print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

        # B-2 - play a beep on the Raspberry Pi
        if (objectServerID == "B-2"):
            #check for validate request
            # validate allows RasPiConnect to verify this object is here
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData
        # not validate request, so execute
        # note that python is in the main directory for this call, not the local directory
            output = subprocess.call(["aplay", "sounds/match1.wav"])
            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        # B-8 Shutdown
        if (objectServerID == "B-8"):
            #check for validate request
            # validate allows RasPiConnect to verify this object is here
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        # not validate request, so execute
        # note that python is in the main directory for this call, not the local directory
            output = subprocess.call(["sudo", "shutdown", "-a", "now"])
            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

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

        tempData = "xx.x C (no i2c enabled)"
        pressureData = "xxxx.x hPa (no i2c enabled)"

        # read an HTML template into aw string
        with open("./Templates/camera.html", "r") as myfile:
            responseData += myfile.read().replace('\n', '')

        # replace the URL so it will point to static
        responseData = responseData.replace("XXX", Config.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)
        outgoingXMLData += BuildResponse.buildResponse(responseData)

        if (Config.debug()):
            print outgoingXMLData

# previous camera image
    elif (objectServerID == "W-2"):

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

        imageName = "previous.jpg"
        responseData = buildImageResponse(imageName)
        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()

        if (Config.debug()):
            print outgoingXMLData

# latest camera image
    elif (objectServerID == "W-3"):

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

        imageName = "latest.jpg"
        responseData = buildImageResponse(imageName)
        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()

        if (Config.debug()):
            print outgoingXMLData

        return outgoingXMLData
    else:

        # returning a zero length string tells the server that you have not matched
        # the object and server
        return ""
示例#45
0
def ExecuteUserObjects(objectType, element):

    # Example Objects
    global port25
    global port24

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
    #
    # check to see if this is a Validate request
    #
    validate = Validate.checkForValidate(element)

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

    # Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    # objects are split up by object types by Interface Constants
    #
    #
    #
    # search for matches to object Type

    # object Type match
    print("+++++++++++OBJECTTYPE %i" % objectType)
    if (objectType == ACTION_BUTTON_UITYPE):

        if (Config.debug()):
            print "ACTION_BUTTON_UTYPE of %s found" % objectServerID

        # B-2 - play a beep on the Raspberry Pi
        if (objectServerID == "B-2"):

            #check for validate request
            # validate allows RasPiConnect to verify this object is here
            if (validate == "YES"):
                outgoingXMLData += Validate.buildValidateResponse("YES")
                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData

        # not validate request, so execute

        # note that python is in the main directory for this call, not the local directory

            output = subprocess.call(["aplay", "sounds/match1.wav"])

            responseData = "OK"
            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
    if (objectType == TEXT_DISPLAY_UITYPE):

        if (objectServerID == "LT-1"):

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

                return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
            output = GPIO.VERSION
            FMOutput = 1000.0

            print "VERSION++++++++++++++=%s" % output

            responseData = "%3.2f, %3.2f, %s" % (
                FMOutput,
                FMOutput,
                output,
            )

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

        if (objectServerID == "LT-2"):

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

                return outgoingXMLData

#			output = subprocess.check_output(["cat", "/sys/class/thermal/thermal_zone0/temp"])
            output = GPIO.RPI_REVISION
            FMOutput = 2222.0

            print "VERSION---------=%s" % output

            responseData = "%3.2f, %3.2f, %s" % (output, output, "RPI Version")

            outgoingXMLData += BuildResponse.buildResponse(responseData)
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

    if (objectType == SINGLE_LED_DISPLAY):

        #check for validate request
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        if (port25):
            GPIO.output(25, 0)
            port25 = False
            ledColour = 5
            print "Led off"
        else:
            GPIO.output(25, 1)
            port25 = True
            ledColour = 2
            print "Led on"

        responseData = "%i" % (ledColour)

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData
    if (objectType == FEEDBACK_ACTION_BUTTON_UITYPE):
        #check for validate request
        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData
        if (port24):
            GPIO.output(24, 0)
            port24 = False
            responseData = "Port 24 Led off"
        else:
            GPIO.output(24, 1)
            port24 = True
            responseData = "port 24 Led on"

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData
    else:
        return ""
    # returning a zero length string tells the server that you have not matched
    # the object and server
    return ""
def Execute_Send_Text(root):

	# find the interface object type

	objectServerID = root.find("./OBJECTSERVERID").text
	objectFlags = root.find("./OBJECTFLAGS").text
	objectAction = root.find("./OBJECTACTION").text

	if (objectAction == None):
		objectAction = ""

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

	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

	# ST-1 writes a file called "ST-1.txt" in the ./local directory with the contents of the text field on RasPiConnect

	if (objectServerID == "ST-1"):	

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

			return outgoingXMLData
	
		
		responseData = "OK"

		f = open("./local/ST-1.txt", "w")
		f.write( objectAction)      
		f.close()

		outgoingXMLData += BuildResponse.buildResponse(responseData)



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



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

	return outgoingXMLData
示例#47
0
def ExecuteUserObjects(objectType, element):

    # Example Objects

    # fetch information from XML for use in user elements

    #objectServerID is the RasPiConnect ID from the RasPiConnect App

    objectServerID = element.find("./OBJECTSERVERID").text
    objectID = element.find("./OBJECTID").text

    if (Config.debug()):
        print("objectServerID = %s" % objectServerID)
#
# check to see if this is a Validate request
#
    validate = Validate.checkForValidate(element)

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

# Build the header for the response

    outgoingXMLData = BuildResponse.buildHeader(element)

    #
    # B-1 Flashes LED on GPIO
    if (objectServerID == "B-1"):

        #check for validate request
        # validate allows RasPiConnect to verify this object is here

        if (validate == "YES"):
            outgoingXMLData += Validate.buildValidateResponse("YES")
            outgoingXMLData += BuildResponse.buildFooter()
            return outgoingXMLData

# not validate request, so execute
#

#
#
# Execute your code
#
#

# To put an LED on GPIO Pin 7 on your pi read this:
#		http://www.thirdeyevis.com/pi-page-2.php
#
        if (Config.debug()):
            print("Button # %s: Blinking GPIO pin 7" % objectServerID)

        GPIO.output(7, True)  ## Turn on GPIO pin 7
        time.sleep(1)  ## sleep 1 second
        GPIO.output(7, False)  ## Turn off GPIO pin 7
        responseData = "OK"  ## send an OK back to the App

        print "responseData =", responseData

        #
        #
        # Done with your code
        #
        #

        outgoingXMLData += BuildResponse.buildResponse(responseData)
        outgoingXMLData += BuildResponse.buildFooter()
        return outgoingXMLData

    else:
        # returning a zero length string tells the server that you have not matched
        # the object and server
        return ""
def ExecuteUserObjects(objectType, element):

	# Example Objects

	# fetch information from XML for use in user elements

	#objectServerID is the RasPiConnect ID from the RasPiConnect App

        objectServerID = element.find("./OBJECTSERVERID").text
        objectID = element.find("./OBJECTID").text
        objectAction = element.find("./OBJECTACTION").text
        objectName = element.find("./OBJECTNAME").text

        if (Config.debug()):
        	print("objectServerID = %s" % objectServerID)
	# 
	# check to see if this is a Validate request
	#
        validate = Validate.checkForValidate(element)

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

        
	# Build the header for the response

	outgoingXMLData = BuildResponse.buildHeader(element)

	#
	# W-10 Main plan  Web page screen 
	if (objectServerID == "W-10"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 

               	if (validate == "YES"):
                       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       	outgoingXMLData += BuildResponse.buildFooter()
                       	return outgoingXMLData

		# not validate request, so execute

		# note that python is in the main directory for this call, not the local directory

		# read an HTML template into aw string

		
		responseData = "<html><head>"
              	responseData += "<title></title><style>body,html,iframe{margin:0;padding:0;}"
		tempString = ""
		try:
       			f = open("/home/pi/RasPiConnectServer/Templates/W-1b.txt", "r")
              		tempString = f.read()
               		f.close()
		except IOError as e:
			tempString = ""	

		responseData += tempString
 		responseData += "</style>"

		#responseData += "<META HTTP-EQUIV='CACHE-CONTROL' CONTENT='NO-CACHE'>"
             	responseData += "</head>"
		# read in the rest of the css definitions 

              	responseData += "<body>"

         	responseData += "<div style='position: relative; left: 0; top: 0;'>\n"
               	responseData += "<img src='http://rfw.wardner.com:9600/static/mainplanfull.png' style='position: relative; top: 0; left: 0;'/>\n"

		# read in the rest of the objects
		tempString = ""
		try:
       			f = open("/home/pi/RasPiConnectServer/Templates/W-1a.txt", "r")
              		tempString = f.read()
               		f.close()
		except IOError as e:
			tempString = ""	

		responseData += tempString


               	responseData += "</div>"


               	responseData +="</body>"

              	responseData += "</html>"

		print "responseData =", responseData

               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData
		

	#
	# BTL-1 Bubble Log
	if (objectServerID == "BTL-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 

               	if (validate == "YES"):
                       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       	outgoingXMLData += BuildResponse.buildFooter()
                       	return outgoingXMLData

		responseData =""
		# not validate request, so execute

		# note that python is in the main directory for this call, not the local directory
		try:
       			f = open("/home/pi/BeaconAir/state/bubblelog.txt", "r")
              		tempString = f.read()
              		f.close()
			os.remove("/home/pi/BeaconAir/state/bubblelog.txt")
		except IOError as e:
			tempString = ""	

		responseData = tempString


		print "responseData =", responseData

               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData
		


	# DSPL-1 Dynamic Spark Line event driven 
	if (objectServerID == "DSPL-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 

               	if (validate == "YES"):
                       	outgoingXMLData += Validate.buildValidateResponse("YES")
                       	outgoingXMLData += BuildResponse.buildFooter()
                       	return outgoingXMLData

		responseData =""
		# not validate request, so execute

		# note that python is in the main directory for this call, not the local directory
		try:
       			f = open("/home/pi/BeaconAir/state/distancejitter.txt", "r")
              		tempString = f.read()
              		f.close()
			os.remove("/home/pi/BeaconAir/state/distancejitter.txt")
		except IOError as e:
			tempString = ""	

		responseData = tempString


		print "responseData =", responseData

               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData
		
	# SLGL-1 - Beacon count
	if (objectServerID == "SLGL-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		try:
        		f = open("/home/pi/BeaconAir/state/iBeaconCountGraph.txt", "r")
        		commandresponse = f.read()
        		f.close()	
		except IOError as e:
			commandresponse = "0^^0||No Data from BeaconAir^^"			

                outgoingXMLData += BuildResponse.buildResponse(commandresponse)


                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData	

	# SL-1 - Sensitivity in meters 
	if (objectServerID == "SL-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		commandresponse = objectAction	
	
		if (float(commandresponse) < 0.15):
                	try:
       	                 	f = open("/home/pi/BeaconAir/state/distanceSensitivity.txt", "r")
       	                 	commandresponse = f.read()
       	                 	f.close()
       	         	except:
                        	commandresponse = "2.0"
	
    		f = open("/home/pi/BeaconAir/state/distanceSensitivity.txt", "w")
        	f.write(commandresponse)
        	f.close()
		status = sendCommandToBeaconAirAndWait("UPDATESENSITIVITIES")
		# Not LIVE values, just send "" back
		
		commandresponse = ""
		
                outgoingXMLData += BuildResponse.buildResponse(commandresponse)


                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData	

	# SL-2 - Brightness Sensitivity in meters 
	if (objectServerID == "SL-2"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		commandresponse = objectAction	
		if (float(commandresponse) < 0.15):
                	try:
                        	f = open("/home/pi/BeaconAir/state/brightnessSensitivity.txt", "r")
                        	commandresponse = f.read()
                        	f.close()
                	except:
                        	commandresponse = "2.0" 

    		f = open("/home/pi/BeaconAir/state/brightnessSensitivity.txt", "w")
        	f.write(commandresponse)
        	f.close()
		status = sendCommandToBeaconAirAndWait("UPDATESENSITIVITIES")
		# Not LIVE values, just send "" back
		
		commandresponse = ""
		
                outgoingXMLData += BuildResponse.buildResponse(commandresponse)


                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData	

	# LT-1 - display beacon count 
	if (objectServerID == "LT-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
                if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

                # normal response requested
		
		try:
       			f = open("/home/pi/BeaconAir/state/beaconCount.txt", "r")
              		tempString = f.read()
               		f.close()
		except IOError as e:
			tempString = "no count"	
		
		commandresponse = tempString + ", "+ tempString + ", iBeacon Count "

 
		
                outgoingXMLData += BuildResponse.buildResponse(commandresponse)


                outgoingXMLData += BuildResponse.buildFooter()
                return outgoingXMLData	


	# FB-5 -  turn beacon reception on / off 
	if (objectServerID == "FB-5"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
               	if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

		# not validate request, so execute

                responseData = "XXX"
 

                if (objectName is None):
                        objectName = "XXX"

               	lowername = objectName.lower()


               	if (lowername == "enable beacons"):

			status = sendCommandToBeaconAirAndWait("BEACONON") 
                       	responseData = "disable beacons" 
                       	responseData = responseData.title()


               	elif (lowername == "disable beacons"):

			status = sendCommandToBeaconAirAndWait("BEACONOFF")
                       	responseData = "enable beacons" 
                       	responseData = responseData.title()


		 # defaults to on 
               	else:
			status = sendCommandToBeaconAirAndWait("BEACONON") 
                       	lowername = "disable beacons" 
                       	responseData = lowername.title()


               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData





	# FB-1 -  turns display beacons on or off
	if (objectServerID == "FB-1"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
               	if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

		# not validate request, so execute

                responseData = "XXX"
 

                if (objectName is None):
                        objectName = "XXX"

               	lowername = objectName.lower()


               	if (lowername == "display beacons on"):

			status = sendCommandToBeaconAirAndWait("DISPLAYBEACONON") 
                       	responseData = "display beacons off" 
                       	responseData = responseData.title()


               	elif (lowername == "display beacons off"):

			status = sendCommandToBeaconAirAndWait("DISPLAYBEACONOFF")
                       	responseData = "display beacons on" 
                       	responseData = responseData.title()


		 # defaults to on 
               	else:
			status = sendCommandToBeaconAirAndWait("DISPLAYBEACONON") 
                       	lowername = "display beacons off" 
                       	responseData = lowername.title()


               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData


	# FB-4 -  turns display beacons on or off
	if (objectServerID == "FB-4"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
               	if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

		# not validate request, so execute

                responseData = "XXX"
 

                if (objectName is None):
                        objectName = "XXX"

               	lowername = objectName.lower()


               	if (lowername == "display lights on"):

			status = sendCommandToBeaconAirAndWait("DISPLAYLIGHTSON") 
                       	responseData = "display beacons off" 
                       	responseData = responseData.title()


               	elif (lowername == "display lights off"):

			status = sendCommandToBeaconAirAndWait("DISPLAYLIGHTSOFF")
                       	responseData = "display beacons on" 
                       	responseData = responseData.title()


		 # defaults to on 
               	else:
			status = sendCommandToBeaconAirAndWait("DISPLAYLIGHTSON") 
                       	lowername = "display lights off" 
                       	responseData = lowername.title()


               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData


	# FB-2 -  turns display beacons on or off
	if (objectServerID == "FB-2"):	

               	#check for validate request
		# validate allows RasPiConnect to verify this object is here 
               	if (validate == "YES"):
                        outgoingXMLData += Validate.buildValidateResponse("YES")
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

		# not validate request, so execute

                responseData = "XXX"
 

                if (objectName is None):
                        objectName = "XXX"

               	lowername = objectName.lower()


               	if (lowername == "all lights on"):

			status = sendCommandToBeaconAirAndWait("ALLLIGHTSON") 
                       	responseData = "all lights off" 
                       	responseData = responseData.title()


               	elif (lowername == "all lights off"):

			status = sendCommandToBeaconAirAndWait("ALLLIGHTSOFF")
                       	responseData = "all lights on" 
                       	responseData = responseData.title()


		 # defaults to on 
               	else:
			status = sendCommandToBeaconAirAndWait("ALLLIGHTSON") 
                       	lowername = "all lights off" 
                       	responseData = lowername.title()


               	outgoingXMLData += BuildResponse.buildResponse(responseData)
      		outgoingXMLData += BuildResponse.buildFooter()
               	return outgoingXMLData



	else:
		return ""
	# returning a zero length string tells the server that you have not matched 
	# the object and server 
	return ""