RasPiConnect Server

From RasPiConnect/ArduinoConnect
Jump to: navigation, search

RasPiConnect Home

Contents

RasPiConnectServer Files

Description of directories and files in the RasPiConnectServer package:

  • ReadMe - RasPiConnectServer information
  • startserver.sh - script for use in rc.local startup script - see below
  • config - contains user configurable values (the configuration file itself is Config.py - note the capital "C")
  • ClientXMLConfigFiles - example and user configuration files for the iPad Client RasPiConnect
  • ExecuteFiles - contains control execution files for RasPiConnectServer.py
  • local - user execution files
  • RasPiConnectServer.py - RasPiConnectServer python file
  • RasPilib - contains support files for RasPiConnect
  • Adafruit - contains files for Adafruit example I2C sensors
  • static - contains image and static files that are served by RasPiConnectServer
  • sounds - example Rasberry Pi sounds
  • Templates - Template HTML pages for RasPiConnect

startserver.sh - script to start the server

(Note: You may wish to change the amixer command in the script. The command form is: sudo amixer cset numid=3 <n>. Substituting <n> for the desired mode: 0=auto, 1=headphones, 2=hdmi. For example, to force the Raspberry Pi to use the analog output: sudo amixer cset numid=3 1)

The Architecture of the RasPiConnect Server

The RasPiConnect Server is based on the Python web.py server library. The main server pages and top level functions are in the RasPiConnectServer.py file in the top directory.

The Version Page

This page is used to determine the current version of the RasPiConnect Server and to test the installation without a RasPiConnect App installed on your iPad.

It will return the current Version of RasPiConnect to a browser (see the Testing Section).

The RasPi Page

This page is where all the work gets done regarding sending Raspberry Pi data back to the RasPiConnect App.

The following occurs in this page:

  • The incoming XML from the RasPiConnect App is parsed.
  • Each individual control request for refresh is parsed and evaluated.
  • The incoming XML is authenticated.
  • The Control Object Type and the RasPiConnect ID are retrieved from the incoming XML requests.
  • Then the user defined "Local" Execute file is called. The Local.py file is in the Local Directory (see below). This is the file where user RasPiConnect IDs should be defined.
  • RasPiConnect predefined objects are defined in the rest of the file.
  • The combined set of responses are constructed, finalized and then sent back to the RasPiConnect App as a well formed XML file.

Latest Changes

RasPiConnectServer 2.9 contains the following changes:

  • Fixed default implementation of Bar Meter


RasPiConnectServer 2.8 contains the following changes:

  • Added support for Bar Meter


RasPiConnectServer 2.7 contains the following changes:

  • Removed additional i2c dependencies


RasPiConnectServer 2.6 contains the following changes:

  • Now prints out server IP address after server start
  • supports /version as well as /Version


RasPiConnectServer 2.5 contains the following changes:

  • Addition of support for the Feedback Action Button
  • Bug fix for No I2C mode

Constructing Your Own RasPiConnect Responses (The Magic!)

Building your own responses is easy. You can select virtually any data to send back to the RasPiConnect App and display it in a number of different ways.

Your own RasPiConnect ID responses are built in the Local.py file (located in the local subdirectory). An example Local file (LocalExample.py) is located in the local directory. If you build your own Local.py file, it replaces this file in RasPiConnectServer.py.

Local.py will never be overwritten in a future release of RasPiConnectServer, so it is best to put your changes in the Local.py file.

Using the RasPiConnectServer Libraries, it is easy to construct a properly formed response to send to the RasPiConnect App.

The LocalExample.py file gives an example of how to form a response to the RasPiConnect App.


#!/usr/bin/python
# Filename: local.py
# MiloCreek BP MiloCreek
# Version 3.0 6/11/2014
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
 
# system imports
import sys
import subprocess
import os
import time
# RasPiConnectImports
 
import Config
import Validate
import BuildResponse
 
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
 
# To put an LED on GPIO Pin 7 on your pi read this:
#               http://www.thirdeyevis.com/pi-page-2.php
#
 
 
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 ""


The meaning of each part of the file is given below:

The Header

This section sets up the needed imports, defines the RasPiConnect constants and includes the RasPiConnect support modules.

#!/usr/bin/python
# Filename: local.py
# MiloCreek BP MiloCreek
# Version 3.0 6/11/2014
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
 
# system imports
import sys
import subprocess
import os
import time
# RasPiConnectImports
 
import Config
import Validate
import BuildResponse
 
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(7, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
 
# To put an LED on GPIO Pin 7 on your pi read this:
#               http://www.thirdeyevis.com/pi-page-2.php
#

Module Function Definition

ExecuteUserObjects is used in the RasPiConnectServer to call user defined objects.

  • objectType is one of the above RasPiConnect interface constants.
  • element is a well formed XML expression containing the RasPiConnect App refresh data request (sent from the RasPiConnect App).
def ExecuteUserObjects(objectType, element):

Parse XML and check to see if this request is a Validate request

       # 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)

A Validate request is sent from the RasPiConnect App to check to see if the RasPiConnect ID is actually implemented in the RasPiConnectServer. It does not perform the function intended but just returns a "Hey, I am here and ready to do work!".

This statement checks to see if the request is a Validate request.

       validate = Validate.checkForValidate(element)

The software then starts building the Outgoing XML Data by building the header for the response.


        outgoingXMLData = BuildResponse.buildHeader(element)


The Work Part of Response

First the code checks for the RasPiConnect ID (objectServerID) and then either sends a validation response back or does the work of the function.

          #
        # 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


First check for the appropriate RasPiConnect ID (set in the RasPiConnect App).

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

Next look for a Validate request. If it is, build the Validate response, the footer and return the data to the RasPiConnect Server.

                #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

User Defined Response Code

In this section of the code, we do something or report something on the Raspberry Pi. In this case, we are blinking an LED on GPIO 7.

Check the files in the ExecuteFiles directories for many more examples. All of the responses are formed in the same way.

  • Get the data or perform the action
  • Build the responseData ("OK" in this case, since it is an action button - but it varies according to the control type)
  • Finish building the XML response and finish off with the XML footer.
                # 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

That's it!

The Error or Not Found Return

The last part of the program returns a zero length string to tell RasPiConnectServer that the request has not been executed by the Local.py file.

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

Button and Alarm User Defined Response Code Example

This code (in Local.py) uses a file to store the state of the alarm in a file. (in this case we trigger the alarm with a button. In a real program, your Pi or Arduino would select some criteria to set off an alarm).

                 # B-11 -  Trigger Alarm SU-1
                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
 
                        #format =    titletext, alarmtext, alarmstate, soundvalue, how often in seconds, how many times
                        f = open("/home/pi/ProjectCuracao/main/state/SU-1.txt", "w")
                        f.write("alarm 1, Reason1-1,YES, 1005, 1, 10")
                        f.close()
 
                        responseData = "OK"
                        outgoingXMLData += BuildResponse.buildResponse(responseData)
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData
 
                # B-12 -  Clear Alarm SU-1
                if (objectServerID == "B-12"):
 
                        #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
 
 
                        f = open("/home/pi/ProjectCuracao/main/state/SU-1.txt", "w")
                        #format =    titletext, alarmtext, alarmstate, soundvalue, how often in seconds, how many times
                        f.write("alarm 1, Reason1-1,NO, 1005, 1, 10")
                        f.close()
 
                        responseData = "OK"
                        outgoingXMLData += BuildResponse.buildResponse(responseData)
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

And the alarm code itself:

     # object Type match
                # SU-1 Alarm 1
                if (objectServerID == "SU-1"):
 
                        #check for validate request
                        if (validate == "YES"):
                                outgoingXMLData += Validate.buildValidateResponse("YES")
                                outgoingXMLData += BuildResponse.buildFooter()
 
                                return outgoingXMLData
 
 
 
                        try:
                                f = open("/home/pi/ProjectCuracao/main/state/SU-1.txt", "r")
                                responseData = f.read()
                                f.close()
 
                        except IOError as e:
                                toggleTemp = 0
                                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                                responseData = ""
 
 
 
                        outgoingXMLData += BuildResponse.buildResponse(responseData)
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

DEPRECATED VERSION -- Constructing Your Own RasPiConnect Responses (The Magic!)

This section has been deprecated by a simpler version of Local.py. Detecting the ObjectType was redundant and just made things more complicated.


Building your own responses is easy. You can select virtually any data to send back to the RasPiConnect App and display it in a number of different ways.

Your own RasPiConnect ID responses are built in the Local.py file (located in the local subdirectory). An example Local file (LocalExample.py) is located in the local directory. If you build your own Local.py file, it replaces this file in RasPiConnectServer.py.

Local.py will never be overwritten in a future release of RasPiConnectServer, so it is best to put your changes in the Local.py file.

Using the RasPiConnectServer Libraries, it is easy to construct a properly formed response to send to the RasPiConnect App.

The LocalExample.py file gives an example of how to form a response to the RasPiConnect App.


#!/usr/bin/python
# Filename: LocalExample.py
# Version 1.1 4/8/13
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
# RasPiConnectServer interface constants
 
REMOTE_WEBVIEW_UITYPE = 1
ACTION_BUTTON_UITYPE = 16
SINGLE_LED_DISPLAY = 32
SPEEDOMETER_UITYPE = 64
VOLTMETER_UITYPE = 128
SERVER_STATUS_UITYPE = 256
PICTURE_REMOTE_WEBVIEW_UITYPE = 512
LABEL_UITYPE = 1024
FM_BLINK_LED_UITYPE = 2048
TEXT_DISPLAY_UITYPE = 4096
TOGGLE_SWITCH_UITYPE = 33
SEND_TEXT_UITYPE = 34
 
# system imports
import sys
import subprocess
 
# RasPiConnectImports
 
import Config
import Validate
import BuildResponse
 
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


The meaning of each part of the file is given below:

The Header

This section sets up the needed imports, defines the RasPiConnect constants and includes the RasPiConnect support modules.

#!/usr/bin/python
# Filename: LocalExample.py
# Version 1.1 4/8/13
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
# RasPiConnectServer interface constants
 
REMOTE_WEBVIEW_UITYPE = 1
ACTION_BUTTON_UITYPE = 16
SINGLE_LED_DISPLAY = 32
SPEEDOMETER_UITYPE = 64
VOLTMETER_UITYPE = 128
SERVER_STATUS_UITYPE = 256
PICTURE_REMOTE_WEBVIEW_UITYPE = 512
LABEL_UITYPE = 1024
FM_BLINK_LED_UITYPE = 2048
TEXT_DISPLAY_UITYPE = 4096
TOGGLE_SWITCH_UITYPE = 33
SEND_TEXT_UITYPE = 34
 
# system imports
import sys
import subprocess
 
# RasPiConnectImports
 
import Config
import Validate
import BuildResponse

Module Function Definition

ExecuteUserObjects is used in the RasPiConnectServer to call user defined objects.

  • objectType is one of the above RasPiConnect interface constants.
  • element is a well formed XML expression containing the RasPiConnect App refresh data request (sent from the RasPiConnect App).
def ExecuteUserObjects(objectType, element):

Parse XML and check to see if this request is a Validate request

       # 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)

A Validate request is sent from the RasPiConnect App to check to see if the RasPiConnect ID is actually implemented in the RasPiConnectServer. It does not perform the function intended but just returns a "Hey, I am here and ready to do work!".

This statement checks to see if the request is a Validate request.

       validate = Validate.checkForValidate(element)

The software then starts building the Outgoing XML Data by building the header for the response.


        outgoingXMLData = BuildResponse.buildHeader(element)


Check for RasPiConnect Interface Type

Check to see if it is a valid RasPiConnect InterfaceType (this allows the RasPiConnect App to be upgraded in the future).

        # 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


The Work Part of Response

First the code checks for the RasPiConnect ID (objectServerID) and then either sends a validation response back or does the work of the function.

             # 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


First check for the appropriate RasPiConnect ID (set in the RasPiConnect App).

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

Next look for a Validate request. If it is, build the Validate response, the footer and return the data to the RasPiConnect Server.

                        #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

User Defined Response Code

In this section of the code, we do something or report something on the Raspberry Pi. In this case, we are playing a sound.

Check the files in the ExecuteFiles directories for many more examples. All of the responses are formed in the same way.

  • Get the data or perform the action
  • Build the responseData ("OK" in this case, since it is an action button - but it varies according to the control type)
  • Finish building the XML response and finish off with the XML footer.
                       # 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

That's it!

The Error or Not Found Return

The last part of the program returns a zero length string to tell RasPiConnectServer that the request has not been executed by the Local.py file.

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

Button and Alarm User Defined Response Code Example

This code (in Local.py) uses a file to store the state of the alarm in a file. (in this case we trigger the alarm with a button. In a real program, your Pi or Arduino would select some criteria to set off an alarm).

      # object Type match
        if (objectType == ACTION_BUTTON_UITYPE):
 
                if (Config.debug()):
                        print "ACTION_BUTTON_UTYPE of %s found" % objectServerID
 
                # B-11 -  Trigger Alarm SU-1
                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
 
                        #format =    titletext, alarmtext, alarmstate, soundvalue, how often in seconds, how many times
                        f = open("/home/pi/ProjectCuracao/main/state/SU-1.txt", "w")
                        f.write("alarm 1, Reason1-1,YES, 1005, 1, 10")
                        f.close()
 
                        responseData = "OK"
                        outgoingXMLData += BuildResponse.buildResponse(responseData)
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData
 
                # B-12 -  Clear Alarm SU-1
                if (objectServerID == "B-12"):
 
                        #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
 
 
                        f = open("/home/pi/ProjectCuracao/main/state/SU-1.txt", "w")
                        #format =    titletext, alarmtext, alarmstate, soundvalue, how often in seconds, how many times
                        f.write("alarm 1, Reason1-1,NO, 1005, 1, 10")
                        f.close()
 
                        responseData = "OK"
                        outgoingXMLData += BuildResponse.buildResponse(responseData)
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData

And the alarm code itself:

     # object Type match
        if (objectType == SOUND_ALARM_UITYPE):
                if (Config.debug()):
                        print "SOUND_ALARM_UITYPE of %s found" % objectServerID
 
                # SU-1 Alarm 1
                if (objectServerID == "SU-1"):
 
                        #check for validate request
                        if (validate == "YES"):
                                outgoingXMLData += Validate.buildValidateResponse("YES")
                                outgoingXMLData += BuildResponse.buildFooter()
 
                                return outgoingXMLData
 
 
 
                        try:
                                f = open("/home/pi/ProjectCuracao/main/state/SU-1.txt", "r")
                                responseData = f.read()
                                f.close()
 
                        except IOError as e:
                                toggleTemp = 0
                                print "I/O error({0}): {1}".format(e.errno, e.strerror)
                                responseData = ""
 
 
 
                        outgoingXMLData += BuildResponse.buildResponse(responseData)
                        outgoingXMLData += BuildResponse.buildFooter()
                        return outgoingXMLData
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox