README.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. python-onvif-zeep
  2. ============
  3. ONVIF Client Implementation in Python
  4. Dependencies
  5. ------------
  6. `zeep <http://docs.python-zeep.org>`_ >= 3.0.0
  7. Install python-onvif-zeep
  8. -------------------------
  9. **From Source**
  10. You should clone this repository and run setup.py::
  11. cd python-onvif-zeep && python setup.py install
  12. Alternatively, you can run::
  13. pip install --upgrade onvif_zeep
  14. Getting Started
  15. ---------------
  16. Initialize an ONVIFCamera instance
  17. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. ::
  19. from onvif import ONVIFCamera
  20. mycam = ONVIFCamera('192.168.0.2', 80, 'user', 'passwd', '/etc/onvif/wsdl/')
  21. Now, an ONVIFCamera instance is available. By default, a devicemgmt service is also available if everything is OK.
  22. So, all operations defined in the WSDL document::
  23. /etc/onvif/wsdl/devicemgmt.wsdl
  24. are available.
  25. Get information from your camera
  26. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. ::
  28. # Get Hostname
  29. resp = mycam.devicemgmt.GetHostname()
  30. print 'My camera`s hostname: ' + str(resp.Name)
  31. # Get system date and time
  32. dt = mycam.devicemgmt.GetSystemDateAndTime()
  33. tz = dt.TimeZone
  34. year = dt.UTCDateTime.Date.Year
  35. hour = dt.UTCDateTime.Time.Hour
  36. Configure (Control) your camera
  37. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. To configure your camera, there are two ways to pass parameters to service methods.
  39. **Dict**
  40. This is the simpler way::
  41. params = {'Name': 'NewHostName'}
  42. device_service.SetHostname(params)
  43. **Type Instance**
  44. This is the recommended way. Type instance will raise an
  45. exception if you set an invalid (or non-existent) parameter.
  46. ::
  47. params = mycam.devicemgmt.create_type('SetHostname')
  48. params.Hostname = 'NewHostName'
  49. mycam.devicemgmt.SetHostname(params)
  50. time_params = mycam.devicemgmt.create_type('SetSystemDateAndTime')
  51. time_params.DateTimeType = 'Manual'
  52. time_params.DaylightSavings = True
  53. time_params.TimeZone.TZ = 'CST-8:00:00'
  54. time_params.UTCDateTime.Date.Year = 2014
  55. time_params.UTCDateTime.Date.Month = 12
  56. time_params.UTCDateTime.Date.Day = 3
  57. time_params.UTCDateTime.Time.Hour = 9
  58. time_params.UTCDateTime.Time.Minute = 36
  59. time_params.UTCDateTime.Time.Second = 11
  60. mycam.devicemgmt.SetSystemDateAndTime(time_params)
  61. Use other services
  62. ~~~~~~~~~~~~~~~~~~
  63. ONVIF protocol has defined many services.
  64. You can find all the services and operations `here <http://www.onvif.org/onvif/ver20/util/operationIndex.html>`_.
  65. ONVIFCamera has support methods to create new services::
  66. # Create ptz service
  67. ptz_service = mycam.create_ptz_service()
  68. # Get ptz configuration
  69. mycam.ptz.GetConfiguration()
  70. # Another way
  71. # ptz_service.GetConfiguration()
  72. Or create an unofficial service::
  73. xaddr = 'http://192.168.0.3:8888/onvif/yourservice'
  74. yourservice = mycam.create_onvif_service('service.wsdl', xaddr, 'yourservice')
  75. yourservice.SomeOperation()
  76. # Another way
  77. # mycam.yourservice.SomeOperation()
  78. ONVIF CLI
  79. ---------
  80. python-onvif also provides a command line interactive interface: onvif-cli.
  81. onvif-cli is installed automatically.
  82. Single command example
  83. ~~~~~~~~~~~~~~~~~~~~~~
  84. ::
  85. $ onvif-cli devicemgmt GetHostname --user 'admin' --password '12345' --host '192.168.0.112' --port 80
  86. True: {'FromDHCP': True, 'Name': hision}
  87. $ onvif-cli devicemgmt SetHostname "{'Name': 'NewerHostname'}" --user 'admin' --password '12345' --host '192.168.0.112' --port 80
  88. True: {}
  89. Interactive mode
  90. ~~~~~~~~~~~~~~~~
  91. ::
  92. $ onvif-cli -u 'admin' -a '12345' --host '192.168.0.112' --port 80 --wsdl /etc/onvif/wsdl/
  93. ONVIF >>> cmd
  94. analytics devicemgmt events imaging media ptz
  95. ONVIF >>> cmd devicemgmt GetWsdlUrl
  96. True: http://www.onvif.org/
  97. ONVIF >>> cmd devicemgmt SetHostname {'Name': 'NewHostname'}
  98. ONVIF >>> cmd devicemgmt GetHostname
  99. True: {'Name': 'NewHostName'}
  100. ONVIF >>> cmd devicemgmt SomeOperation
  101. False: No Operation: SomeOperation
  102. NOTE: Tab completion is supported for interactive mode.
  103. Batch mode
  104. ~~~~~~~~~~
  105. ::
  106. $ vim batchcmds
  107. $ cat batchcmds
  108. cmd devicemgmt GetWsdlUrl
  109. cmd devicemgmt SetHostname {'Name': 'NewHostname', 'FromDHCP': True}
  110. cmd devicemgmt GetHostname
  111. $ onvif-cli --host 192.168.0.112 -u admin -a 12345 -w /etc/onvif/wsdl/ < batchcmds
  112. ONVIF >>> True: http://www.onvif.org/
  113. ONVIF >>> True: {}
  114. ONVIF >>> True: {'FromDHCP': False, 'Name': NewHostname}
  115. References
  116. ----------
  117. * `ONVIF Offical Website <http://www.onvif.com>`_
  118. * `Operations Index <http://www.onvif.org/onvif/ver20/util/operationIndex.html>`_
  119. * `ONVIF Develop Documents <http://www.onvif.org/specs/DocMap-2.4.2.html>`_
  120. * `Foscam Python Lib <http://github.com/quatanium/foscam-python-lib>`_