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

Cannot connect on Windows #31

Closed TheDizzyEgg closed 1 year ago

TheDizzyEgg commented 1 year ago

Although the Onvif device manager allows me to log in and view the camera, using the easy_onvif lib I can never connect, I always get back:

ERROR:flutter/runtime/dart_vm_initializer.cc(41) Unhandled Exception: Exception: Error code: Code: Value: SOAP-ENV:Sender, Subcode: Value: NotAuthorized, Reason: Sender not authorized, Detail: Text: The action requested requires authorization and the sender is not authorized

Although I'm calling connect with the correct IP, username and password (Onvif admin user).

Any ideas!?

faithoflifedev commented 1 year ago

Hello @TheDizzyEgg,

Do you have some sample code for the onvif operations you are doing?

TheDizzyEgg commented 1 year ago

This is the most basic example:

void main(List arguments) async { Onvif testOnvif = await Onvif.connect(host: '192.168.0.40', username: 'admin', password: 'password');

print('Hello world: ${dart_onvif.calculate()}!'); }

Throws the following errors:

`‼️ 15:41:44.174242 ERROR UI Loggy - Onvif - ERROR: DioError [DioErrorType.response]: Http status error [500] ‼️ 15:41:44.207244 ERROR UI Loggy - Onvif - ERROR: DioError [DioErrorType.response]: Http status error [400] Unhandled exception: Exception: Error code: {Code: {Value: {$: SOAP-ENV:Sender}, Subcode: {Value: {$: ter:NotAuthorized}}}, Reason: {Text: {@xml:lang: en, $: Sender not authorized}}, Detail: {Text: {$: The action requested requires authorization and the sender is not authorized}}}

0 Soap.send (package:easy_onvif/src/soap.dart:43:11)

#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 main (file:///C:/Users/dizzy.egg/Dart/dart_onvif/bin/dart_onvif.dart:6:21) `
faithoflifedev commented 1 year ago

Sorry @TheDizzyEgg , the sample you've given doesn't make sense. Try something like:

void main(List<String> arguments) async {
  // get connection information from the config.yaml file
  final config = loadYaml(File('example/config.yaml').readAsStringSync());

  // configure device connection
  final onvif = await Onvif.connect(
      host: config['host'],
      username: config['username'],
      password: config['password'],
      logOptions: const LogOptions(
        LogLevel.all,
        stackTraceLevel: LogLevel.error,
      ),
      printer: const PrettyPrinter(
        showColors: true,
      ));

  // get device info
  var deviceInfo = await onvif.deviceManagement.getDeviceInformation();

  print('Manufacturer: ${deviceInfo.manufacturer}');
  print('Model: ${deviceInfo.model}');
}