Binding Request: Synology Surveillance Station

Hi Pav,

as a workaround I created a new dummy item for the URL and then created a rule which does the string replacement. The basically does:
Cam_Dome_Snapshot_Live.postUpdate( Cam_Dome_Snapshot_Live_Uri_Mjpeg_Http.state.toString.replaceAll("\"", "" ) )

But later I also got the problem with leading 0 where this doesn’t work anymore. So I was further searching for a solution and maybe found (script from here https://forum.iobroker.net/viewtopic.php?t=4101&start=20#p46159) some good one which maybe could also be applied to your solution. The idea is to have a php script which does the authentification inside so the url is somehow static.

<?php
// Configuration
$user = "display";  // Synology user
$pass = "somepassword";  // Password
$ip = "192.168.10.64";  
$port = "5000";  
$cameraID = $_GET["CamID"];  // ID for the camera
$cameraStream = $_GET["stream"];
// You can change the stream by adding ?stream=0/1/2 to the url. For example: www.yourdomain.com/snapshot.php?stream=2
// 0: Live stream | 1: Recording stream | 2: Mobile stream
// Default value is stream 0
if ($cameraStream == NULL) {
        $cameraStream = "0";
}

// Authentification and get SID
$json = file_get_contents('http://'.$ip.':'.$port.'/webapi/auth.cgi?api=SYNO.API.Auth&method=Login&version=3&account='.$user.'&passwd='.$pass.'&session=SurveillanceStation&format=sid');
$obj = json_decode($json, true);
@$sid = $obj["data"]["sid"];

$Cam_Stream_URL = 'http://'.$ip.':'.$port.'/webapi/SurveillanceStation/videoStreaming.cgi?api=SYNO.SurveillanceStation.VideoStream&version=1&method=Stream&cameraId='.$cameraID.'&format=mjpeg&_sid='.$sid;
//set_time_limit(30);
ob_implicit_flush(1);

$fp =  fopen($Cam_Stream_URL, "r");
foreach ($http_response_header as $header) {
    header($header);
}
while($str = fgets($fp, 4096))
{
    echo $str;
}
?>

Maybe it’s possible also for you to get the SID and deliver a static URL without the StrKey?

Regards,
Michel

Nice idea! As you’re already there, you might just try it yourself. With following replacement in your rule you would convert the static snapshot URI (Surveillance_Snapshot_Uri_Static) into a new dummy item (Surveillance_Snapshot_Live_Uri_Static):

Surveillance_Snapshot_Live_Uri_Static.postUpdate(
  Surveillance_Snapshot_Uri_Static.state.toString.replace("entry.cgi", "SurveillanceStation/videoStreaming.cgi").replace(".Camera", ".VideoStream").replace("version=8", "version=1").replace("GetSnapshot", "Stream&format=mjpeg")
)

I’m looking forward to your feedback.

Hi Pav,

thanks for this workaround. It’s working fine:

Regards,
Michel

In my openhab.log I see such message:

2018-11-04 11:41:38.276 [WARN ] [.core.thing.binding.BaseThingHandler] - Handler SynoBridgeHandler of thing synologysurveillancestation:station:1630mqn415001 tried checking if channel homemode is linked although the handler was already disposed

Any idea what is causing this?

Glad it worked!
Your warning I haven’t seen yet though. Is your HomeMode channel linked/enabled? If yes, is it functioning properly? Can you see anything wrong at all? When do you receive this message? Every X seconds/minutes, on every Binding/openHab start, on configuration change?

You have handler disposed in this thread:
https://community.openhab.org/t/handler-disposed/49168?u=tnemrap

/Mike

This binding works perfect! Nice job!

@Pavion
Yes, this is actually from me.
I don’t use HomeMode yet.
Is this mandatory?

I added some camera’s, but the camera’s with PTZ are giving me an error, any ideas?

2018-11-22 09:48:32.707 [WARN ] [ome.core.thing.internal.ThingManager] - Initializing handler for thing ‘synologysurveillancestation:camera:42f5d3bc:8’ takes more than 5000ms.
2018-11-22 09:48:35.545 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.initialize()’ on ‘org.openhab.binding.synologysurveillancestation.handler.SynoCameraHandler@4ec48’: null
java.lang.NullPointerException: null
at org.openhab.binding.synologysurveillancestation.handler.SynoCameraHandler.updatePatrols(SynoCameraHandler.java:339) [224:org.openhab.binding.synologysurveillancestation:2.4.0.a30]
at org.openhab.binding.synologysurveillancestation.handler.SynoCameraHandler.initialize(SynoCameraHandler.java:191) [224:org.openhab.binding.synologysurveillancestation:2.4.0.a30]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [101:org.eclipse.smarthome.core:0.10.0.oh230]
at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [101:org.eclipse.smarthome.core:0.10.0.oh230]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]

What is your exact question? HomeMode can be used but is not mandatory for anything. Although there are some obscure warnings I couldn’t reproduce, it still should work as intended.

@dafdegiraf could it be that you have no patrols defined? Please try to run this URL (using your IP and your camera ID as shown in camera properties in the binding):

http://your-DS:5000/webapi/entry.cgi?api=SYNO.SurveillanceStation.PTZ&method=ListPatrol&version=1&cameraId=1 

If you have any patrols defined, you should see their list. If not, you will get an error with code 400 (execution failed). In that case you have to disable the corresponding channel for the binding to work.

Indeed, i have no patrols defined.
error
How do i disable the corresponding channel?
I tried it to unlink it in habmin, but it doesn’t do anything

Actually it should… you’d need to unlink or delete altogether this “Run patrol” item, so it doesn’t there anymore. I would recommend using PaperUI, which is more user friendly in my opinion.

I was able to reproduce your issue: turning Run patrol on put the Thing offline, turning off brings it online back again.
image

In any case, the binding going down in this case is an obvious error and I thank you for pointing this out! I’ll try to make a hotfix today or this weekend.

Thanks for your quick response.

I was actually wondering if HomeMode is a Must and if not used if it could cause the „Handler disposed“ issue.

But obviously not - according to your response .
So, thanks again :blush::+1:t2:

@NCO @michelm_de @dafdegiraf
I’ve tried to address your issues, please check the latest release and its notes for more details.
Thanks for reporting, feedback is appreciated!

how long ago did you start this binding? a while now! I’m still several versions back and rock solid.
Keep up the good work @Pavion

1 Like

I have installed the latest release, but i still have the error for my PTZ camera.
My other camera’s are working fine.
I also observed that after installing the binding my openhab is very slow. I can’t even connect remotely to myopenhab.org, it gives me a gateway timeout…

  1. Please ensure that you’re running the latest release only. You can check it in your Karaf by typing bundle:list | grep Syno. There should be but one line with Running state and version a31. Any other / older revisions are to be uninstalled.

  2. In any case you should unlink the channels you’re not using. Even with the new release, linking Patrol channel with no patrols defined will spam your openhab.log with errors, which should not affect the binding functionality anymore though.

  3. Installing and updating the binding could take some time (see 1 above) but running it should not affect the overall performance of openHAB. To keep the load low you should keep your camera Thing’s timeouts reasonable: 10 seconds for snapshots and 3 seconds for events should suffice.

  4. Nothing happening in openHAB should affect the connection to myopenhab. If you’re encountering issues with it, please check the URL in a normal browser first. Sometimes myopenhab.org is just down or overloaded.

  5. As you see, all I can do is to guess wildly. I ask you to provide some corresponding logs and some more information for me to pinpoint your issues.

  6. If you’re also on GitHub I ask you to create an issue there. Otherwise you’re welcome to send me a PM. Let’s try to keep this forum tidy.

  7. Thank you for your patience :slight_smile:

  1. thank you for the binding :slight_smile:

Thanks a lot!
I will give it a try!

EDIT:
I just installed the latest version and will report back with the outcome.

However, I had issues starting the binding:

openhab> bundle:list | grep Syno
245 x Installed x  80 x 2.4.0.a31              x SynologySurveillanceStation Binding
openhab> bundle:start 245
Error executing command: Error executing command on bundles:
    Error starting bundle 245: Could not resolve module: org.openhab.binding.synologysurveillancestation [245]
  Unresolved requirement: Import-Package: org.eclipse.jdt.annotation; resolution:="optional"
  Unresolved requirement: Import-Package: org.jupnp.model.meta

and needed to install the following additional features:

openhab> feature:install openhab-transport-serial
openhab> feature:install esh-io-transport-upnp

How to ensure that these are installed persistently?