[Technical Tutorial] HIKSDK/RTSP/Ehome video platform EasyCVR, how to add alarms through GB28181 protocol?

As a new function in the construction of security video cloud services, the alarm function has played a role in more and more security scenarios. With the successful use of the alarm function in the national standard GB28181 protocol video platform EasyGBS developed by TSINGSEE Qingxi Video, we plan to gradually use the alarm function in more platforms.

88.png

Therefore, in the new version of EasyCVR, we have added the calling interface of the alarm function. Currently, the alarm function we develop is mainly received through the GB28181 protocol. Therefore, the alarm function in EasyCVR is roughly the same as the development of the alarm in EasyGBS. EasyCVR receives the alarm message in the national standard message, and then displays it through the interface.

GBS warning.png

Add the following method to the message:

case "alarm":
 
		deviceId := ""
		if el := doc.Root().SelectElement("DeviceID"); el != nil {
			deviceId = el.Text()
		}
 
		limiter := Limiter.GetLimiter(fmt.Sprintf("%s:%s", serial, deviceId))
		if !limiter.Allow() {
			return
		}
 
		alarmPriority := ""
		if el := doc.Root().SelectElement("AlarmPriority"); el != nil {
			alarmPriority = el.Text()
		}
		alarmMethod := ""
		if el := doc.Root().SelectElement("AlarmMethod"); el != nil {
			alarmMethod = el.Text()
		}
		alarmType := ""
		if el := doc.Root().SelectElement("Info").SelectElement("AlarmType"); el != nil {
			alarmType = el.Text()
		}
		alarmTime := ""
		if el := doc.Root().SelectElement("AlarmTime"); el != nil {
			alarmTime = el.Text()
		}
		body := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>\r
<Response>\r
<CmdType>Alarm</CmdType>\r
<SN>%s</SN>\r
<DeviceID>%s</DeviceID>\r
<Result>OK</Result>\r
</Response>\r`, sn, deviceId)
		c.Req.MakeResponse().EnsureToTag().SetHeader("Content-Type", "Application/MANSCDP+xml")
		c.Req.MakeResponse().EnsureToTag().SetBody(body)
		channels := models.GetChannel(deviceId, serial)
		if channels == nil {
			log.Println("alarm find channel is nil")
			return
		}
 

Through the above interface call to view, you can get the alarm list, and meet the requirements after the test.

26.png

The new version of EasyCVR will be launched in the near future. You can download and try it out. If you want to learn more about EasyCVR, you can follow us. In addition, TSINGSEE Green Rhino Video has also developed a variety of security video clouds with different protocols. The service platforms, including EasyNVR, EasyGBS, EasyDSS, etc., can be downloaded and tried, please consult.

Guess you like

Origin blog.csdn.net/EasyNVS/article/details/111311687