faithoflifedev / easy_onvif_workspace

This package works with a variety of ONVIF compatible devices allowing for IP Cameras and NVRs (network video recorders) to be integrated into Dart and Flutter applications.
33 stars 21 forks source link

DioError Connection closed while receiving data #30

Closed DongsubShin closed 1 year ago

DongsubShin commented 1 year ago
스크린샷 2023-01-03 오전 11 16 29

always thank you about wonderful package

I've used this package very well but since last week onvif.media.getProfile doesn't work suddenly

initialize, onvif.connect, everything worked well execpt get profile what should i do?

Thank you in advance

faithoflifedev commented 1 year ago

Hello @DongsubShin,

Can you let me know which version of the package you are using?

Also, if you enable debugging, and provide the debug info, that could also provide a clue as to the problem.

final onvif = await Onvif.connect(
      host: config['host'],
      username: config['username'],
      password: config['password'],
      logOptions: const LogOptions(
        LogLevel.debug,
        stackTraceLevel: LogLevel.error,
      )); 

"also is there any workaround to get profile token from cctv hardward directly?" - I'm not aware of any method to do this.

Based on the error info that you've provided, it looks like the device is having a problem responding to the request. Having the debug log could help trace the issue.

DongsubShin commented 1 year ago

/flutter (14197): 🐛 00:52:10.542713 DEBUG UI Loggy - Media - getProfiles I/flutter (14197): 🐛 00:52:10.550331 DEBUG UI Loggy - Onvif - URI: http://183.107.70.232:9440/onvif/device_service I/flutter (14197): 🐛 00:52:10.550574 DEBUG UI Loggy - Onvif - REQUEST: I/flutter (14197): <?xml version="1.0" encoding="UTF-8"?>admin8LeatWstS9/fkkdL8lALcyyJeas=8VTbbC7+J+2TWvgKMgUEHQ==2023-01-03T16:20:54.207102Z</s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSc

/flutter (14197): ‼️ 00:52:10.612952 ERROR UI Loggy - Onvif - ERROR: I/flutter (14197): DioError [DioErrorType.other]: HttpException: Connection closed while receiving data, uri = http://183.107.70.232:9440/onvif/device_service

I've tested camera with other onvif apps(like Onvier). and it works well on those apps.

Flutter (Channel stable, 3.3.9, on macOS 12.3.1 21E258 darwin-arm, locale ko-KR) easy_onvif: ^2.0.13+7

Thanks :)

faithoflifedev commented 1 year ago

Hi @DongsubShin,

This looks like it might be a network related issue, but it's difficult to say with the limited information.

I recommend installing the cli utility with the command:

dart pub global activate easy_onvif

Further instructions are available in the README - https://github.com/faithoflifedev/easy_onvif/tree/main/bin#readme quick start section.

Then check to see if the results of the onvif device-management get-services command give the same IP address that you are using to connect to your Onvif device. The results of the command will look something like:

[
  {
    "Namespace": "http://www.onvif.org/ver10/device/wsdl",
    "XAddr": "http://192.168.1.182/onvif/device_service",
    "Version": {
      "Major": 16,
      "Minor": 12
    },
    "Capabilities": null
  },
  ...

If the value for "XAddr" (in the section with "Namespace": "http://www.onvif.org/ver10/device/wsdl") is different in terms of IP address, port or if it doesn't end in "/onvif/device_service" this could be the problem.

LODYZ commented 1 year ago

Hello,

I am getting a similar error during Onvif.connect or calling (onvif device-management get-device-information --log-level debug). I hope that it can be useful. Thank you

👻 14:13:50.294820 INFO UI Loggy - Onvif - initializing ... 🐛 14:13:50.297588 DEBUG UI Loggy - DeviceManagement - getSystemDateAndTime 🐛 14:13:50.313086 DEBUG UI Loggy - Onvif - URI: http://192.168.0.25/onvif/device_service 🐛 14:13:50.313162 DEBUG UI Loggy - Onvif - REQUEST: <?xml version="1.0" encoding="UTF-8"?></s:Body></s:Envelope> 🐛 14:13:50.555788 DEBUG UI Loggy - Onvif - RESPONSE: <?xml version="1.0" encoding="UTF-8"?>

NTPfalse131350202318131350202318 🐛 14:13:51.353807 DEBUG UI Loggy - DeviceManagement - getServices 🐛 14:13:51.359715 DEBUG UI Loggy - Onvif - URI: http://192.168.0.25/onvif/device_service 🐛 14:13:51.359803 DEBUG UI Loggy - Onvif - REQUEST: adminQdmgYLPlVkBOTJG2iJtH6c58VkI=MM8ww9A45bnJiu0lcqIMpg==2023-01-08T13:13:50.001088Ztrue 🐛 14:13:51.509302 DEBUG UI Loggy - Onvif - RESPONSE: http://www.onvif.org/ver10/device/wsdlhttp://192.168.0.25:80/onvif/device_service250http://www.onvif.org/ver10/media/wsdlhttp://192.168.0.25:80/onvif/device_service250http://www.onvif.org/ver10/events/wsdlhttp://192.168.0.25:80/onvif/device_service250http://www.onvif.org/ver20/imaging/wsdlhttp://192.168.0.25:80/onvif/device_service250http://www.onvif.org/ver10/deviceIO/wsdlhttp://192.168.0.25:80/onvif/device_service250http://www.onvif.org/ver20/analytics/wsdlhttp://192.168.0.25:80/onvif/device_service"false""true"250http://www.onvif.org/ver20/ptz/wsdlhttp://192.168.0.25:80/onvif/device_service250 🐛 14:13:51.530899 DEBUG UI Loggy - DeviceManagement - getCapabilities 🐛 14:13:51.531366 DEBUG UI Loggy - Onvif - URI: http://192.168.0.25/onvif/device_service 🐛 14:13:51.531394 DEBUG UI Loggy - Onvif - REQUEST: All ‼️ 14:13:51.720128 ERROR UI Loggy - Onvif - ERROR: DioError [DioErrorType.other]: HttpException: Connection closed while receiving data, uri = http://192.168.0.25/onvif/device_service Unhandled exception: Exception: DioError [DioErrorType.other]: HttpException: Connection closed while receiving data, uri = http://192.168.0.25/onvif/device_service Source stack: #0 DioMixin.fetch (package:dio/src/dio_mixin.dart:488:35) #1 DioMixin.request (package:dio/src/dio_mixin.dart:483:12) #2 DioMixin.post (package:dio/src/dio_mixin.dart:97:12) #3 Soap.send (package:easy_onvif/src/soap.dart:29:30) #4 Soap.retrieveEnvelope (package:easy_onvif/src/soap.dart:59:37) #5 DeviceManagement.getCapabilities (package:easy_onvif/src/device_management.dart:32:33) #6 Onvif.initialize (package:easy_onvif/src/onvif_base.dart:124:51) #7 Onvif.connect (package:easy_onvif/src/onvif_base.dart:87:5) #8 OnvifHelperCommand.initializeOnvif (package:easy_onvif/cmd/onvif_helper_command.dart:28:14) #9 OnvifGetDeviceInformationResponseDeviceManagementCommand.run (package:easy_onvif/cmd/onvif_device_management_command.dart:68:5) #10 CommandRunner.runCommand (package:args/command_runner.dart:209:13) #0 Soap.send (package:easy_onvif/src/soap.dart:47:7) #1 Soap.retrieveEnvelope (package:easy_onvif/src/soap.dart:59:26) #2 DeviceManagement.getCapabilities (package:easy_onvif/src/device_management.dart:32:22) #3 Onvif.initialize (package:easy_onvif/src/onvif_base.dart:124:28) #4 Onvif.connect (package:easy_onvif/src/onvif_base.dart:87:5) #5 OnvifHelperCommand.initializeOnvif (package:easy_onvif/cmd/onvif_helper_command.dart:28:14) #6 OnvifGetDeviceInformationResponseDeviceManagementCommand.run (package:easy_onvif/cmd/onvif_device_management_command.dart:68:5) #7 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
faithoflifedev commented 1 year ago

@DongsubShin, @LODYZ, are you using "Onvif Rtsp Server for Android"?

If so, issue #3 covers the problem you're experiencing.

If not, I recommend testing if other Onvif libraries work with your device (preferably open source) and let me know which works, so I can look at how others have solved the problem.

The error you're seeing in this case is a network issue where the device is dropping the connection, at this point I think I could only offer additional help if I have access to a device that allows me to recreate the problem.

LODYZ commented 1 year ago

Hello @faithoflifedev, no i am not using "Onvif Rtsp Server for Android".

At the Moment i have only tried the camera with onvier (an app) and It works. I Will try other libraries and update you.

Thank you for all the support!

faithoflifedev commented 1 year ago

@LODYZ are you running your code in the Android emulator? If so, this solution might help - https://learnflutter.co/flutter-connection-closed-while-receiving-data/

LODYZ commented 1 year ago

Hello @faithoflifedev, I'm glad to inform you that I was able to resolve the device connection problems.

I encountered 3 problems:

  1. "DioError Connection closed while receiving data" -> Solved using deviceManagement.getServices()
  2. Envelope header null -> I edited envelope.dart and envelope.g.dart (I know I shouldn't do it manually)
  3. Multicast null during getProfiles-> I edited audio_encoder (I know I shouldn't do it manually)

If you want I created a fork where you can see the changes. https://github.com/LODYZ/easy_onvif

Sorry if maybe that's not entirely correct but I'm new to the world of dart and onvif.

faithoflifedev commented 1 year ago

Hi @LODYZ,

Thanks for this. It's helped me identify a couple of bugs. It looks like there's a Media2 profile - https://www.onvif.org/ver20/media/wsdl/media.wsdl - supported by some cameras that I was unaware of, so the current code doesn't support it. I'll work on adding support in the coming days.

In digging in to this I found that all three of DeviceManagement, Media and Media2 use a GetServiceCapabilitiesResponse, which returns three different Capabilities objects. I'm currently only properly returning the Capabilities for DeviceManagement. So I'll try to correct this as well.

faithoflifedev commented 1 year ago

Hi @LODYZ, as an fyi, after a major overhaul of the code base, I've been able to create a new release that includes Media2 support, and fixes a number of bugs that I found in the original code base. I've published a pre-release version at easy_onvif v2.1.0-dev.3, I'd appreciate any feedback that you could offer.

LODYZ commented 1 year ago

Hi @faithoflifedev , thank you so much for all the work you are doing. I'll try the new release as soon as possibile.

faithoflifedev commented 1 year ago

https://github.com/faithoflifedev/easy_onvif/issues/32#issuecomment-1493346568 also deals with this issue.