当前位置: 首页 > news >正文

Elixir通过Onvif协议控制ip摄像机,扩展ExOnvif的获取预置位列表GetPresets

ExOnvif官方文档

扩展ExOnvif 调用指定预置位GotoPreset请参考此文章。

在使用 Elixir 进行 IPdome 控制时,可以使用 ExOnvif 库。
ExOnvif官方文档中未给出预置位调用命令,自己按照onvif协议 Onvif协议 扩展的此项功能;

Onvif协议获取预置位内容:
请添加图片描述
由以上协议可以看出,获取摄像机所有预置位,只需要一个参数 profile_token,返回值为:此摄像机已设置的所有预置位

步骤如下:

  • 初始化device设备
  • 获取device的profile_token
  • 获取设备的预置位表
  • 将返回值格式化
  # 初始化device设备defp get_device(uri) when not is_nil(uri) do%{host: host, userinfo: userinfo} =  URI.parse(uri)[user, pw] = String.split(userinfo, ":")Device.new("http://" <> host, user, pw);enddefp get_device(uri) do:errorend# 获取设备的 main streamprofile_tokendefp get_main_stream_profile_token(device) doprofiles = Media2.get_profiles(device)case profiles do{:ok, list} -> {:ok, hd(list).reference_token}_ -> "something went wrong"endend# 获取设备所有的预置位defp get_presets(device, profile_token) dobody = element("tptz:GetPresets", element("tptz:ProfileToken", profile_token))ptz_request(device, "GetPresets", body, fn _ -> :ok end)end注意:提前导入需要的模块

完整文件onvif.action.ex文件

defmodule Onvif.Action do@moduledoc """自定义的Onvif的部分协议获取当前状态(exonvifabsolute move调用摄像头到指定位置,continuous move摄像头连续移动调用指定预置位停止运动"""alias ExOnvif.Devicealias ExOnvif.Media2import ExOnvif.Utils.ApiClient, only: [ptz_request: 4]defp get_device(uri) when not is_nil(uri) do%{host: host, userinfo: userinfo} =  URI.parse(uri)[user, pw] = String.split(userinfo, ":")Device.new("http://" <> host, user, pw);enddefp get_device(uri) do:errorenddefp get_main_stream_profile_token(device) doprofiles = Media2.get_profiles(device)case profiles do{:ok, list} -> {:ok, hd(list).reference_token}_ -> "something went wrong"endend# 获取设备所有的预置位defp get_presets(device, profile_token) dobody = element("tptz:GetPresets", element("tptz:ProfileToken", profile_token))ptz_request(device, "GetPresets", body, fn _ -> :ok end)# 解析presets# endend# 获取所有预置位对外调用def get_presets(uri) dowith {:ok, device} <- get_device(ip, username, password),{:ok, profile_token} <- get_main_stream_profile_token(device) doendget_presets(device, profile_token)end
获取预置位列表的标准xml文件: GetPresets
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"xmlns:wsdl="http://www.onvif.org/ver20/ptz/wsdl"xmlns:sch="http://www.onvif.org/ver10/schema"><SOAP-ENV:Header><!-- 安全认证头(根据设备要求) --><Security SOAP-ENV:mustUnderstand="true"xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><UsernameToken><Username>您的用户名</Username><Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"><!-- 密码需按ONVIF标准加密 --></Password><Nonce>随机数</Nonce><Created>当前时间戳</Created></UsernameToken></Security></SOAP-ENV:Header><SOAP-ENV:Body><wsdl:GetPresets><!-- 必填参数:设备配置集Token --><wsdl:ProfileToken>主码流配置Token</wsdl:ProfileToken></wsdl:GetPresets></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
http://www.dtcms.com/a/367131.html

相关文章:

  • 《A Study of Probabilistic Password Models》(IEEE SP 2014)——论文阅读
  • 移动端固定资产盘点如何落地?系统操作全指南
  • 工业控制的“智慧大脑”:数字孪生技术如何预判生产风险?
  • 2025国赛B题保姆级教程思路分析 碳化硅外延层厚度的确定
  • 蔚来8月狂卖3.1万辆,反超理想引热议!
  • 【面试题】介绍一下BERT和GPT的训练方式区别?
  • 阿瓦隆 A1146 Pro 63T:性能与设计详解,探索区块链挖矿新高度
  • 渲染是否伤电脑?从根源减少损伤的技巧
  • 小白也能看懂,HTTP中的文件上传与下载到底发生了什么?
  • Ansible Playbook自动化运维全攻略
  • 小程序缓存数据字典
  • Web详解
  • testng.xml
  • 目标检测系列-Yolov5下载及运行
  • 微软出品!这个免费开源工具集获得了GitHub 123k程序员点赞
  • 链表三连击:面试官最爱考的三个单链表问题,你真的会吗?
  • 记录mat使用排查内存泄漏
  • 常见的相机模型针孔/鱼眼(Pinhole,Mei,K
  • 在线视频教育平台|基于Springboot的在线视频教育平台系统设计与实现(源码+数据库+文档)
  • MIT6.5840-Spring 2025-lab3~4 Debug 记录
  • @Percona XtraBackup 进行 MySQL 备份恢复
  • Redis 数据结构全面解析:从底层编码到实战应用
  • 借助 TX Text Control:在 .NET C# 中使用 PDF/A-3b 创建可信文档容器
  • 无需Python:Shell脚本如何成为你的自动化爬虫引擎?
  • Python--运算符概述
  • PyTorch 学习率调度器(LR Scheduler)
  • 深度学习篇---SENet
  • Java面试宝典:Redis的设计、实现
  • 十、网络与信息安全基础知识
  • Nano-banana 模型对接教程:最懂创作者的 AI 模型,比GPT-4o还强!