class Events_Test:
    def __init__(self, ip, port, user, passw):
        self.ip = ip
        self.port = port
        self.user = user
        self.passw = passw
        self.cam = ONVIFCamera(self.ip, self.port, self.user, self.passw)

    def GetEventProperties(self):
        event_service = self.cam.create_events_service()
        properties = event_service.GetEventProperties()
        if (len(properties) > 0):
            return 'GetEventProperties works', properties
        else:
            return 'GetEventProperties does not work', properties

    def CreatePullPointSubscription(self):
        event_service = self.cam.create_events_service()
        subs = event_service.CreatePullPointSubscription()
        curr = subs.CurrentTime
        term = subs.TerminationTime
        delt = int((term - curr).total_seconds())
        if ((len(subs) > 0) & (delt >= 10)):
            return 'CreatePullPointSubscription works', subs
        else:
            return 'CreatePullPointSubscription does not work', subs

    def GetServiceCapabilities(self):
        event_service = self.cam.create_events_service()
        capabilities = event_service.GetServiceCapabilities()
        if (len(capabilities) > 0):
            return 'GetServiceCapabilities works', capabilities
        else:
            return 'GetServiceCapabilities does not work', capabilities

    def PullMessages(self):
        self.cam.create_pullpoint_service()
        service = self.cam.pullpoint.zeep_client._get_service('EventService')
        port = self.cam.pullpoint.zeep_client._get_port(
            service, 'PullPointSubscription')
        port.binding_options['address'] = onvif_camera.xaddrs[
            'http://www.onvif.org/ver10/events/wsdl/PullPointSubscription']
        plp = onvif_camera.pullpoint.zeep_client.bind('EventService',
                                                      'PullPointSubscription')
        print plp.PullMessages(Timeout=timedelta(seconds=20), MessageLimit=100)
Exemple #2
0
# -*- coding: utf-8 -*-
from onvif import ONVIFCamera

__author__ = 'vahid'

if __name__ == '__main__':
    mycam = ONVIFCamera('192.168.1.108', 80, 'admin',
                        'C0nc3ll0M4r1n')  #, no_cache=True)
    event_service = mycam.create_events_service()
    print(event_service.GetEventProperties())

    pullpoint = mycam.create_pullpoint_service()
    req = pullpoint.create_type('PullMessages')
    req.MessageLimit = 100
    print(pullpoint.PullMessages(req))
Exemple #3
0
    def _Loop(self):
        self._IsReady = False
        self._log('i', "Initializing...")
        cam = ONVIFCamera(self._Host,
                          self._Port,
                          self._User,
                          self._Pwd,
                          './wsdl/',
                          transport=self)
        if self._SnapshotUri is None:
            self._log('i', "Getting Snapshot Uri...")
            self._SnapshotUri = self.getSnapshotUri(cam).Uri
        self._log('i', "Creating PullPoint Service...")
        pullpoint = cam.create_pullpoint_service()
        self._log('i', "The operation completed successfully!")
        self._IsReady = True
        while (True):
            # Pull message!
            pullpoint.PullMessages({
                "Timeout": self._PullMsgTimeout,
                "MessageLimit": self._PullMsgLimit
            })

            # Convert response message into a dictionary!
            msg = xmltodict.parse(cam.transport.response.text)

            # Get Envelope node!
            nodeEnvelope = msg.get("env:Envelope")
            if nodeEnvelope is None:
                self._log('e', "ONVIF service response invalid data!")
                raise Exception('env:Envelope not found!')

            # Get Body node!
            nodeBody = nodeEnvelope.get("env:Body")
            if nodeBody is None:
                continue

            # Get PullMessagesResponse node!
            nodePullMessagesResponse = nodeBody.get("tev:PullMessagesResponse")
            if nodePullMessagesResponse is None:
                continue

            # Get NotificationMessage node!
            nodeNotificationMessage = nodePullMessagesResponse.get(
                "wsnt:NotificationMessage")
            if nodeNotificationMessage is None:
                continue

            # Get Message node!
            nodeMessage = nodeNotificationMessage.get("wsnt:Message")
            if nodeMessage is None:
                continue
            nodeMessage = nodeMessage.get("tt:Message")
            if nodeMessage is None:
                continue

            # Get Data node!
            nodeData = nodeMessage.get("tt:Data")
            if nodeData is None:
                continue

            # Get SimpleItem node!
            nodeSimpleItem = nodeData.get("tt:SimpleItem")
            if nodeSimpleItem is None:
                continue

            # Get SimpleItem's name!
            simpleItemName = nodeSimpleItem.get("@Name")
            if simpleItemName != "IsMotion":
                continue

            # Get SimpleItems's value!
            simpleItemValue = nodeSimpleItem.get("@Value")
            if simpleItemValue is None:
                continue

            # Update self.IsMotion
            motionStatus = "true" == simpleItemValue
            if motionStatus != self._IsMotion:
                self._IsMotion = motionStatus
                self._LastChanged = datetime.datetime.now()
Exemple #4
0
# -*- coding: utf-8 -*-
from onvif import ONVIFCamera
__author__ = 'vahid'


if __name__ == '__main__':
    mycam = ONVIFCamera('192.168.1.10', 8899, 'admin', 'admin') #, no_cache=True)
    event_service = mycam.create_events_service()
    print(event_service.GetEventProperties())
    
    pullpoint = mycam.create_pullpoint_service()
    req = pullpoint.create_type('PullMessages')
    req.MessageLimit=100
    print(pullpoint.PullMessages(req))