README.rst 4.6 KB

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