ONVIF 事件--订阅推送告警

系列文章目录

ONVIF 事件–能力集


前言

onvif协议里的事件推送主要是为了让客户端知道前端设备产生了什么事件,事件的获取大致分为两种:
(1)BaseNotification,基本推送类型(2)PullPoint,拉点推送类型,这两种也是接下来要详细介绍的。

一、BaseNotification

客户端会发送给设备一个地址,这个地址是专门负责接收告警事件的,设备端触发告警事件后,就将告警事件发送到这个地址上即可。其实就是客户端上启了一个服务。

1.流程图

在这里插入图片描述
在订阅事件完成之后,客户端开启端口在有效期内一直接收设备推送的告警事件,设备端当产生告警之后就推送到客户端上。这种也是比较常用的推送告警方式,目前海康NVR上支持的事件推送就是使用的这种类型,有兴趣的同学可以自行测试一下。

2.事件属性状态

onvif官方文档上有写,事件推送分为三种属性状态:Initialized, Changed,Deleted。
在这里插入图片描述
先说一下这三种属性状态的作用吧:

  • Initialized
    当设置了智能分析配置之后,这里使用区域检测作为举例说明该属性,当移动的物体进入到场景画面中后,会触发该属性状态,将目标标记为Initialized状态,说白了就是有物体进入到视频画面中,但未进入检测区域时,需要上报该事件,将目标标记为Initialized状态。
  • Changed
    当物体进入到检测区域后,需要将该告警事件置为Changed状态,表示该物体被检测到从Initialized状态转为Changed状态。
  • Deleted
    当物体离开检测区域后,将告警事件置为Deleted状态,表示被检测的物体离开的检测区域。

举例说明:(这是拉点推送的例子,组包格式都是一致的)

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" <SOAP-ENV:Header><wsa:MessageID>urn:uuid:5ccbd63e-63e8-4ab2-a69d-e04be021b462</wsa:MessageID><wsa:ReplyTo SOAP-ENV:mustUnderstand="true">		<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
	</wsa:ReplyTo>
	<wsa:To SOAP-ENV:mustUnderstand="true">http://172.16.33.195:80/onvif/device_service?session=587138610</wsa:To>
	<wsa:Action SOAP-ENV:mustUnderstand="true">http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesRequest</wsa:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
	<tev:PullMessages>
		<tev:Timeout>PT00H01M00S</tev:Timeout>
		<tev:MessageLimit>100</tev:MessageLimit>
	</tev:PullMessages>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

//回复
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 2122
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tt="http://www.onvif.org/ver10/schema">
    <SOAP-ENV:Header>
        <wsa5:Action>http://www.onvif.org/ver10/events/wsdl/PullPointSubscription/PullMessagesResponse</wsa5:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <tev:PullMessagesResponse>
            <wsnt:NotificationMessage>
                <wsnt:Topic Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">tns1:RuleEngine/CellMotionDetector/Motion</wsnt:Topic>
                <wsnt:Message>
                    <tt:Message UtcTime="1970-01-01T00:00:00Z" PropertyOperation="Changed">
                        <tt:Source>
                            <tt:SimpleItem Name="Window" Value="0" />
                            <tt:SimpleItem Name="Source" Value="0000" />
                            <tt:SimpleItem Name="VideoSourceConfigurationToken" Value="VideoSourceToken" />
                            <tt:SimpleItem Name="VideoAnalyticsConfigurationToken" Value="VideoAnalyticsToken" />
                            <tt:SimpleItem Name="Rule" Value="MyMotionDetectorRule" />
                        </tt:Source>
                        <tt:Data>
                            <tt:SimpleItem Name="IsMotion" Value="false" />
                            <tt:SimpleItem Name="State" Value="false" />
                        </tt:Data>
                    </tt:Message>
                </wsnt:Message>
            </wsnt:NotificationMessage>
            <tev:CurrentTime>2022-01-08T09:47:29Z</tev:CurrentTime>
            <tev:TerminationTime>2022-01-08T09:48:29Z</tev:TerminationTime>
        </tev:PullMessagesResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

3,订阅报文

POST /onvif/device_service HTTP/1.1
HOST: 172.16.3.19
User-Agent: HTTP_USER_AGENT
Accept: text/html,application/xhtml+xml,application/xml
Accept-Language: ZH-cn;zh;q=0.5
Accept-Charset: gb2312,utf8;q=0.7,*;q=0.7
Content-Type: application/soap+xml; charset="utf-8"
Content-Length: 1745
Connection: Keep-Alive

<?xml version="1.0" encoding="UTF-8" ?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tns1="http://www.onvif.org/ver10/topics">
<soap:Header>
<wsa:Action soap:mustUnderstand="1">http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeRequest</wsa:Action>
<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken  wsu:Id="UsernameToken-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>admin</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">sS/TFWPH8ZrPga3ugijCPdrUU5U=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">WqxxOT70QYeujZaDP2RU3g==</wsse:Nonce>
<wsu:Created>2022-01-10T12:43:24Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<wsa:To soap:mustUnderstand="1">http://172.16.33.195/onvif/device_service</wsa:To>
</soap:Header>
<soap:Body>
<wsnt:Subscribe>
<wsnt:ConsumerReference>
<wsa:Address>http://172.16.33.172:30960/c32110ac_80</wsa:Address>
</wsnt:ConsumerReference>
<wsnt:Filter>
<wsnt:TopicExpression Dialect="http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet">tns1:RuleEngine/CellMotionDetector/Motion|tns1:Device/Trigger/DigitalInput</wsnt:TopicExpression>
</wsnt:Filter>
<wsnt:InitialTerminationTime>PT60S</wsnt:InitialTerminationTime>
</wsnt:Subscribe>
</soap:Body>
</soap:Envelope>HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 956
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex">
    <SOAP-ENV:Header>
        <wsa5:Action>http://docs.oasis-open.org/wsn/bw-2/NotificationProducer/SubscribeResponse</wsa5:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <wsnt:SubscribeResponse>
            <wsnt:SubscriptionReference>
                <wsa5:Address>http://172.16.3.19:80/onvif/device_service?session=1832752807</wsa5:Address>
            </wsnt:SubscriptionReference>
            <wsnt:CurrentTime>2022-01-10T12:43:25Z</wsnt:CurrentTime>
            <wsnt:TerminationTime>2022-01-10T12:44:25Z</wsnt:TerminationTime>
        </wsnt:SubscribeResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

二、Real-time Pull-Point

该接口提供防火墙友好的通知接口,支持实时轮询并发起所有客户端通信。

1,客户端使用CreatePullPointSubscriptionRequest消息向设备请求一个拉点。

2,设备评估订阅请求并返回CreatePullPointSubscriptionResponse或其中一个Fault代码。

3,如果订阅被接受,则响应包含对实例化的拉取点的WS-EndpointReference。这个WS-Endpoint提供了一个PullMessages操作,客户机使用它来检索通知。此外,它还提供基本订阅管理器接口的更新和取消订阅操作。
4,设备立即响应代表客户端聚合的通知。如果没有聚合通知,设备将等待响应,直到为客户端生成通知或超过指定的超时时间。在任何情况下,响应最多包含由MessageLimit参数指定的通知数量。当客户端在每个PullMessagesResponse之后立即启动一个新的PullMessagesRequest时,可以实时轮询通知。

1.流程图

在这里插入图片描述
上面的流程图是官方文档上写的,简单理解就是客户端那边订阅成功后,不断的请求设备告警事件,如果设备端有告警事件触发,就进行回复具体的告警内容。同时协议里规定了最大事件数量和超时时间等属性。

2.事件属性状态

通基本推送一致。

3.订阅报文

POST /onvif/device_service HTTP/1.1
Host: 172.16.3.19
User-Agent: gSOAP/2.8
Content-Type: application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionRequest"
Content-Length: 2666
Connection: close
Authorization: Digest algorithm=MD5, realm="Baidu-D01", username="admin", nonce="14wrmhapshc5pgfhnldh08k05osi4p4t", uri="/onvif/device_service", qop="auth", nc=00000001, cnonce="61d8edace2a3e2a4e2a5e2a658a5934c", response="209db9c9b59e7035a31dcf256a2aadff"
SOAPAction: "http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionRequest"

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"<SOAP-ENV:Header><wsa:MessageID>urn:uuid:78955929-2ce5-4d0a-9a28-fe23f9aabac0</wsa:MessageID><wsa:ReplyTo SOAP-ENV:mustUnderstand="true"><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
</wsa:ReplyTo>
<wsa:To SOAP-ENV:mustUnderstand="true">http://172.16.33.195:80/onvif/device_service</wsa:To>
<wsa:Action SOAP-ENV:mustUnderstand="true">http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionRequest</wsa:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tev:CreatePullPointSubscription>
<tev:InitialTerminationTime>PT60S</tev:InitialTerminationTime>
</tev:CreatePullPointSubscription>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 1053
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2">
    <SOAP-ENV:Header>
        <wsa5:Action>http://www.onvif.org/ver10/events/wsdl/EventPortType/CreatePullPointSubscriptionResponse</wsa5:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <tev:CreatePullPointSubscriptionResponse>
            <tev:SubscriptionReference>
                <wsa5:Address>http://172.16.33.195:80/onvif/device_service?session=1707405651</wsa5:Address>
            </tev:SubscriptionReference>
            <wsnt:CurrentTime>2022-01-08T01:49:31Z</wsnt:CurrentTime>
            <wsnt:TerminationTime>2022-01-08T01:50:31Z</wsnt:TerminationTime>
        </tev:CreatePullPointSubscriptionResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

总结

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

烫手的热山药

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值