Esempio n. 1
0
    def startListener (self, UDPSock = None):
        
        self.computername = self.validInstance(self.computername)

        while UDPSock :
            readable, writeable, errored = select.select([UDPSock],[],[],60)
    
            if len(readable) == 1 :
                data,addr = UDPSock.recvfrom(self.message_buffer)
                messageArray = data.splitlines()
               
                # logLineHeader = "\nFULL XPL MESSAGE FOLOWING:\n"
                # logLineFooter = "\nEND XPL MESSAGE\n\n"

                try:
                    for msgLine in messageArray:
                        if msgLine == '{':
                            messageArray.remove(msgLine)
                        elif msgLine == '}':
                            messageArray.remove(msgLine)
                except:
                    print "No Curly Braces To Remove"
            
                # xplmsglog = open("xplmsglog.log", "a")
                # xplmsglog.write(logLineHeader)
                # xplmsglog.write(str(messageArray))
                # xplmsglog.write(logLineFooter)
                # xplmsglog.close()

                xplMsg = xplMessage(messageArray)
                xplMsg.parseMessage()
                        
                zDen = Zone()
                zDen.getZoneByName('den')
                zDen.getLinkedSensors()
        
                if xplMsg.type == "xpl-trig":
                    if xplMsg.statusDict['command'] == 'alert':               
                        zDen.sensors[xplMsg.statusDict['sensorHexId']].setStatus(zDen.sensors[xplMsg.statusDict['sensorHexId']].id,'alert')
                        self.xplToJSON('den')
                        print "Sensor (Type:" + xplMsg.statusDict['sensorType'] + ", ID: " + xplMsg.statusDict['sensorHexId'] + ") is reporting status: ALERT"
                    if xplMsg.statusDict['command'] == 'normal':
                        zDen.sensors[xplMsg.statusDict['sensorHexId']].setStatus(zDen.sensors[xplMsg.statusDict['sensorHexId']].id,'normal')
                        self.xplToJSON('den')
                        print "Sensor (Type:" + xplMsg.statusDict['sensorType'] + ", ID: " + xplMsg.statusDict['sensorHexId'] + ") is reporting status: NORMAL"
Esempio n. 2
0
    def xplToJSON (self, zoneName = None):
        
        if zoneName != None:
            i = 0

            zone = Zone()
            zone.getZoneByName(zoneName)
            zone.getLinkedSensors()
            zone.isReady()

            jsonRequest = {'zone':{}}

            if zone.statusReady == True:
                jsonRequest['zone']['isReady'] = "true"
            elif zone.statusReady == False:
                jsonRequest['zone']['isReady'] = "false"
            else:
                jsonRequest['zone']['isReady'] = "NOSTATUS"

            # Hardcoded isArmed - FALSE Status until I figure out arming
            jsonRequest['zone']['isArmed'] = "false"

            jsonRequest['zone']['id'] = zone.id
            jsonRequest['zone']['name'] = zone.name

            for sensor in zone.sensors:
                jsonRequest['zone']['sensor' + str(i)] = {}
                jsonRequest['zone']['sensor' + str(i)]['id'] = zone.sensors[sensor].id
                jsonRequest['zone']['sensor' + str(i)]['hexid'] = zone.sensors[sensor].hexid
                jsonRequest['zone']['sensor' + str(i)]['name'] = zone.sensors[sensor].name
                jsonRequest['zone']['sensor' + str(i)]['type'] = zone.sensors[sensor].type
                jsonRequest['zone']['sensor' + str(i)]['status'] = zone.sensors[sensor].status
                i = i + 1

            #http-post
            #print "PARAMS: " + str(jsonRequest)
            params = urllib.urlencode(jsonRequest)
            request = urllib.urlopen("http://localhost/cgi-bin/acceptJSON.cgi", params)
        else:
            print "You must pass the Zone object"