Krontalk

Chronos => Chronos User Discussion => Topic started by: stephanschulz on March 28, 2018, 03:19:26 PM

Title: transfer video to computer via code
Post by: stephanschulz on March 28, 2018, 03:19:26 PM
Hi.

This camera looks amazing.
I was wondering how easy it is to connect my app running on OS X to the camera, so that I can trigger a slow motion recording and then download the file to the OS X machine, all via code.
I guess this could be done via ethernet connection or somehow copy over usb directly to computer?

I see this note at the bottom of the homepage.
"*These features are fully supported in hardware, but not yet in software. They will be added in a future free software update"
thanks for any advice.
Stephan, from Montreal.
Title: Re: transfer video to computer via code
Post by: tesla500 on March 28, 2018, 08:31:00 PM
Hi Stephan,

We currently are working on full Ethernet remote control, but there are some limited functions you can do remotely right now. With the v0.2.5 beta software or newer, you can set the camera to automatically save after a trigger. This will get a file onto a local storage device like an SD card. Then, with the camera connected via USB (behaves as a USB to Ethernet bridge), you can then run a script we have that will monitor the card for new files. When it finds one, the file is SCP'd over network to the PC and then deleted from the SD card.

Would this be of interest?

David

EDIT:
Here's the script as it stands. It requires a few libraries and needs to be run on a computer connected to the camera via USB.

The libraries it needs are: plumbum, paramiko

Preparation
Open the script in a text editor and make a change or two:
1. Set localdir to the destination on your computer where you want the files to be copied to
2. The script will look on the SD card by default.  If you want to change this, replace all 4 occurences of mmcblk1p1 in the script with the mount point of the partition that is selected on the camera. This can be checked on the Save Setting screen, accessible from the Play screen. If saving to a USB stick, sda1 is probably the one to use, though sda or sda2 may sometimes be required.
Usage
Open a terminal or command prompt and run the script using:
python2 get_latest_video.py
Troubleshooting
If having the error "paramiko.ssh_exception.SSHException: Server '192.168.12.1' not found in known_hosts," try the solution posted by rvcFS here: http://forum.krontech.ca/index.php?topic=149.msg2717#msg2717
Title: Re: transfer video to computer via code
Post by: mh on April 05, 2018, 09:37:15 AM
If you already have template code for doing this, it would be highly appreciated!
Title: Re: transfer video to computer via code
Post by: pstest on April 11, 2018, 01:38:01 PM
David,
Can you also provide me with the script that monitors card for file update and then transfers file through network to PC?
Thank you,
pstest
Title: Re: transfer video to computer via code
Post by: Willem on July 11, 2018, 02:31:47 AM
you can then run a script we have that will monitor the card for new files. When it finds one, the file is SCP'd over network to the PC and then deleted from the SD card.

Would this be of interest?

David

Hi David,
would it be possible that I could get the script also?

Thank you very much,
Ulrike
Title: Re: transfer video to computer via code
Post by: SamL on July 11, 2018, 05:33:24 PM
Hi David,
I'm interested in the script. Could you please send me a copy?
thx.
Title: Re: transfer video to computer via code
Post by: SamL on July 28, 2018, 08:24:11 AM
Hi Stephan,

We currently are working on full Etherent remote control, but there are some limited functions you can do remotely right now. With the v0.2.5 beta software, you can set the camera to automatically save after a trigger. This will get a file onto a local storage device like an SD card. Then, with the camera connected via USB (behaves as a USB to Ethernet bridge), you can then run a script we have that will monitor the card for new files. When it finds one, the file is SCP'd over network to the PC and then deleted from the SD card.

Would this be of interest?

David

HI David,

Can you send the script to test? thx.
Title: Re: transfer video to computer via code
Post by: Loial on July 31, 2018, 07:35:44 PM
Here's the script as it stands. It requires a few libraries and needs to be run on a computer connected to the camera via USB.

The libraries it needs are: plumbum, parimoko

EDIT: This is now obsolete, use the script attached to the 2nd post in this thread.
Title: Re: transfer video to computer via code
Post by: yliu on August 14, 2018, 12:21:00 PM
Hi David,
    I am wondering if there is any additional setup I should perform to successfully connect to the camera via USB. I got the following error when trying to run the script. I am able to ping the IP (192.168.12.21 in my case). I am using software 0.3.0-RC1. The camera is Chronos 1.4, Moochrome, 32 GB.
    Any suggestions will be appreciated!

Code: [Select]
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py", line 2878, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-f07cba69afd6>", line 1, in <module>
    runfile('C:/Users/PG_silver/Downloads/get_latest_video.py', wdir='C:/Users/PG_silver/Downloads')
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\helpers\pydev\_pydev_bundle\pydev_umd.py", line 194, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:/Users/PG_silver/Downloads/get_latest_video.py", line 7, in <module>
    cam = ParamikoMachine(host=host, user='root', password='')
  File "C:\Users\PG_silver\AppData\Roaming\Python\Python27\site-packages\plumbum\machines\paramiko_machine.py", line 245, in __init__
    self._client.connect(host, **kwargs)
  File "C:\Users\PG_silver\AppData\Roaming\Python\Python27\site-packages\paramiko\client.py", line 357, in connect
    raise NoValidConnectionsError(errors)
NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 192.168.12.21

Here's the script as it stands. It requires a few libraries and needs to be run on a computer connected to the camera via USB.

The libraries it needs are: plumbum, parimoko
Title: Re: transfer video to computer via code
Post by: NiNeff on August 15, 2018, 10:16:23 AM
The error basically means the connection to the camera failed on port 22.

Can you try to use ssh to connect to the camera? PuTTY is a great windows tool for that. Or use BASH directly if you're on windows 10.
From there on troubleshooting is much easier.
Title: Re: transfer video to computer via code
Post by: yliu on August 15, 2018, 02:56:39 PM
I tried to ssh to the camera using Putty and it failed to open the connection. The error message is attached. Any thoughts? Thank you!
Title: Re: transfer video to computer via code
Post by: tesla500 on August 22, 2018, 04:17:04 PM
I tried to ssh to the camera using Putty and it failed to open the connection. The error message is attached. Any thoughts? Thank you!

Try the following to connect to the camera via SSH and see if this works. If this doesn't, you may need to use an older version of Linux on your PC or investigate the encryption methods supported on your distro. The old Arago Linux build on the camera doesn't support modern crypto, and most systems today by default disallow the insecure modes supported by the camera

ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 root@192.168.12.1

Title: Re: transfer video to computer via code
Post by: yliu on August 28, 2018, 09:32:25 AM
Thank you for the suggestions. I tried to ssh to the camera using Ubuntu on Windows, and it still refuses the connection. Please see the screenshot attached.
Title: Re: transfer video to computer via code
Post by: skronstein on August 28, 2018, 12:02:10 PM
The last number in the IP address should be 1, not 21. So, the whole address should be 192.168.12.1
Title: Re: transfer video to computer via code
Post by: yliu on August 28, 2018, 12:05:42 PM
Sorry, my bad. I was trying to use the ip address from ipconfig

With the correct ip address, the camera complains about "no matching cipher found".

Based on a hint from another thread in Soft Dev board, I used winscp which allows the connection after ignoring some security warning. So far, all is well. Thanks everyone for the help.
The last number in the IP address should be 1, not 21. So, the whole address should be 192.168.12.1
Title: Re: transfer video to computer via code
Post by: DDR on September 06, 2018, 10:31:11 PM
On linux, ssh1 may be able to connect where ssh cannot. We hope this issue - and the security warnings - will be solved by the upcoming 0.4.x update.
Title: Re: transfer video to computer via code
Post by: Oracle on August 13, 2019, 02:14:47 AM
The error basically means the connection to the camera failed on port 22.

Can you try to use ssh to connect to the camera? PuTTY is a great windows tool for that. Or use BASH directly if you're on windows 10.
From there on troubleshooting is much easier.
Good day. I had the same problem as a user above. Now I connected to camera via SSH as a root. What can/should I do now in order to enable the script provided above to work? (The main task for me is to get the images/videos from the camera when I need via python script, if this information is necessary)
Title: Re: transfer video to computer via code
Post by: skronstein on August 13, 2019, 12:10:05 PM
The error basically means the connection to the camera failed on port 22.

Can you try to use ssh to connect to the camera? PuTTY is a great windows tool for that. Or use BASH directly if you're on windows 10.
From there on troubleshooting is much easier.
Good day. I had the same problem as a user above. Now I connected to camera via SSH as a root. What can/should I do now in order to enable the script provided above to work? (The main task for me is to get the images/videos from the camera when I need via python script, if this information is necessary)

Run the script on the computer, not the camera. You don't have to log in via SSH separately.  The script will do that for you.
Logging in via ssh might be useful as a debugging step if the script isn't working.
Title: Re: transfer video to computer via code
Post by: Oracle on August 13, 2019, 01:59:01 PM
The problem is that the script is not working :) Therefore I tried to connect by SSH, but now I don't know how to use it to solve initial problem.
Title: Re: transfer video to computer via code
Post by: skronstein on August 14, 2019, 11:53:38 AM
What happens when you try to run the script?
Title: Re: transfer video to computer via code
Post by: Oracle on August 15, 2019, 02:11:15 AM
Traceback (most recent call last):
  File "get_latest_video.py", line 7, in <module>
    cam = ParamikoMachine(host=host, user='root', password='')
  File "/home/martin/anaconda3/envs/camera/lib/python3.7/site-packages/plumbum/machines/paramiko_machine.py", line 245, in __init__
    self._client.connect(host, **kwargs)
  File "/home/martin/anaconda3/envs/camera/lib/python3.7/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/home/martin/anaconda3/envs/camera/lib/python3.7/site-packages/paramiko/client.py", line 824, in missing_host_key
    "Server {!r} not found in known_hosts".format(hostname)
paramiko.ssh_exception.SSHException: Server '192.168.12.21' not found in known_hosts
Title: Re: transfer video to computer via code
Post by: Oracle on August 15, 2019, 10:16:25 PM
What happens when you try to run the script?
Also, this is the only way I was able to connect to camera via SSH:
ssh root@192.168.12.1 -o Kexalgorithms=+diffie-hellman-group1-sha1 -o Ciphers=+aes128-cbc
Title: Re: transfer video to computer via code
Post by: skronstein on August 16, 2019, 06:00:22 PM
The script is trying to connect to connect to '192.168.12.21' instead of '192.168.12.1'.
Was your script edited to use 21 instead of 1 for the last number?
Title: Re: transfer video to computer via code
Post by: Oracle on August 17, 2019, 05:54:42 AM
I just noticed it) After changing IP to 192.168.12.1 there occured another error:
copying latest video to host
Traceback (most recent call last):
  File "get_latest_video.py", line 37, in <module>
    copy_video(cam, serial, localdir)
NameError: name 'serial' is not defined

How should I define that serial?
Title: Re: transfer video to computer via code
Post by: skronstein on August 19, 2019, 04:03:10 PM
serial should just be removed from the script.  Open the script in a text editor and change the line containing the world 'serial' to:
copy_video(cam, localdir)
Title: Re: transfer video to computer via code
Post by: rvcFS on September 09, 2019, 06:05:12 AM
Hey guys,

I downloaded the get_latest_video.py script and installed all the dependencies (paramiko and plumbum), however I am not able to connect to the camera.
I did the following steps but I keep getting timed out.
Connect the Camera to the PC using (eSATA / USB) port
Connected a ethernet LAN cable from my pc network adapter to the cameras network adapter (blinking with lights)
Changed my pc network adapter ip to a static ip of 192.168.12.10
Tried to ping the camera on 192.168.12.1, destination host unreachable / request timed out
I tried running the script, gave me a no response error.

Would appreciate any advise on what I did wrong. :-[
Title: Re: transfer video to computer via code
Post by: rvcFS on September 09, 2019, 09:07:15 AM
Sorry guys, it was my mistake, I missed the point where the USB acts as a Ethernet bridge.

I managed to connect using winSCP, however when I try to run the python script, I get the following errors:

Code: [Select]
File "C:\Program Files (x86)\Python36-32\lib\site-packages\plumbum\machines\paramiko_machine.py", line 245, in __init__
    self._client.connect(host, **kwargs)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\paramiko\client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\paramiko\client.py", line 824, in missing_host_key
    "Server {!r} not found in known_hosts".format(hostname)
paramiko.ssh_exception.SSHException: Server '192.168.12.1' not found in known_hosts

Im running this on Python 3.6.5 on a Windows 10 OS;
Title: Re: transfer video to computer via code
Post by: NiNeff on September 09, 2019, 10:47:11 AM
have you tried ssh1 instead of winscp?
can you edid you known_hosts file and add the required key?
if you're on win10 you can install bash and use native linux tools which might be easier.
Title: Re: transfer video to computer via code
Post by: rvcFS on September 09, 2019, 12:16:30 PM
have you tried ssh1 instead of winscp?
can you edid you known_hosts file and add the required key?
if you're on win10 you can install bash and use native linux tools which might be easier.

@NiNeff thanks for the reply, I managed to solve the issue.
 
Apparently windows does not automatically add unknown hosts when SSHing (no .ssh host file exists) for security reasons. I added the following parameter to the ParmaikoMachine() initalizer:
Code: [Select]
cam = ParamikoMachine(host=host, user='root', password='', missing_host_policy=paramiko.AutoAddPolicy()) since the default value is set to "None" which rejects any unknown hosts.

Furthermore, copying the video introduced another issue, the following line:
Code: [Select]
latest = cam['/bin/ls -t -1 /media/mmcblk1p1']().split()[0] returns the first index of the standard out which in my case was "System" and caused a (File does not exist) error when attempting to copy the file.

Changing it to the following solves the issue:
Code: [Select]
latest = cam['/bin/ls -t -1 /media/mmcblk1p1']().split()[3] which is the 3rd index of the sorted list. This returned the latest video in my case.

Sharing in case anyone encounters similar issues.

Cheers!