I have an ezviz h8c camera. I'm trying to access this camera from my flutter app to get the stream and control the movement of the camera. I have been able to get the stream with a RTSP url with vlc_player package. For control the movement of the camera I was trying out easy_onvif package from pub.dev. But when I try to connect with the onvif.connect command its showing DioException error. This is the code I have been trying to connect with the camera to control the movement.
Future<void> connect({required String ip}) async {
try {
onvif = await Onvif.connect(
host: ip,
username: 'admin', // Replace with your username
password: 'password', // Replace with your password
);
log(' ✅ OnVIFService: connected to $ip');
await getToken(); // Fetch token after successful connection
} catch (error) {
log(' ✅ OnVIFService: connection error: $error');
}
}
From here I was calling the function
onPressed: () async {
await onvifService
.connect(ip: '192.168.0.103')
.then((value) => onvifService.moveLeft());
debugPrint("working");
onvifService.getToken();
}
But when I'm trying to connect the camera the following error is showing.
I/flutter ( 6295): ‼️ 13:20:06.161941 ERROR UI Loggy - LoggingInterceptors - ERROR: I/flutter ( 6295): DioException [connection timeout]: The request connection took longer than 0:00:20.000000 and it was aborted. To get rid of this exception, try raising the RequestOptions.connectTimeout above the duration of 0:00:20.000000 or improve the response time of the server. I/flutter ( 6295): working [log] ✅ OnVIFService: connection error: Exception: DioException [connection timeout]: The request connection took longer than 0:00:20.000000 and it was aborted. To get rid of this exception, try raising the RequestOptions.connectTimeout above the duration of 0:00:20.000000 or improve the response time of the server. [log] OnVIFService: token is not set [log] OnVIFService: got token null
Can anyone suggest to me how to fix this error and connect with my camera to control the ptz with easy_onvif package? Thank you If it helps below there I give the code to get the stream which works fine.
import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';
import '../widgets/onvif_button.dart';
/// Stateful widget to fetch and then display video content.
class VideoApp extends StatefulWidget {
const VideoApp({super.key});
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
late VlcPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VlcPlayerController.network(
"rtsp://admin:[email protected]/H.264",
autoPlay: true)
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Column(
children: [
SizedBox(
height: MediaQuery.sizeOf(context).height * 0.3,
child: VlcPlayer(
controller: _controller,
aspectRatio: 16 / 9, // Adjust aspect ratio as needed
placeholder: const Center(
child:
CircularProgressIndicator()), // Optional loading indicator
),
),
SizedBox(
height: MediaQuery.sizeOf(context).height * 0.1,
child: OnvifButton(),
)
],
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
With a nmap scan I found out ezviz h8c camera has 554, 8000, 9010 port is open.
I also had the same problem and my solution was to configure my IP My camera is a Tapo C310 and this is the IP http://ip_here:2020/onvif/device_service