Multicam file uploads - LUA Scripting - CHDK Forum supplierdeeply

Multicam file uploads

  • 7 Replies
  • 6519 Views
Multicam file uploads
« on: 09 / April / 2015, 17:58:12 »
Advertisements
I'm working on building a small (~14 camera) rig. The forums have been very useful in developing and troubleshooting so far. I've run into an issue though and I'm stumped. I have a settings file that runs a local LUA script on each camera and does a bunch of button clicks to change settings on the camera (turn off sounds, change how long the screen should stay on for, etc). I want to be able to update the script on all the cameras via the cli. Here is what I think should work:

Code: [Select]
!mc=require('multicam')
!mc:connect({list=true})
!mc:start()
!mc:cmdwait('u -nolua settings.lua chdk/scripts/')
!mc:cmd('exit')

I have all the files in the correct locations, and when I run the upload line ("u -nolua settings.lua chdk/scripts/") in interactive chdkptp it runs just fine.

*

Offline reyalp

  • ******
  • 14121
Re: Multicam file uploads
« Reply #1 on: 09 / April / 2015, 21:48:26 »
Code: [Select]
!mc=require('multicam')
!mc:connect({list=true})
!mc:start()
!mc:cmdwait('u -nolua settings.lua chdk/scripts/')
!mc:cmd('exit')

I have all the files in the correct locations, and when I run the upload line ("u -nolua settings.lua chdk/scripts/") in interactive chdkptp it runs just fine.
The reason this doesn't work is that multicam "commands" are not the same as CLI commands. Multicam commands are messages sent to the multicam script on each camera, CLI commands are code that executes in chdkptp. The CLI is only aware of a single current connection.

The multicam code currently supports download but not upload. For a simple upload, you can use the approach described in http://chdk.setepontos.com/index.php?topic=11478.msg112611#msg112611 (note that discussion is about download, which is now implemented directly in multicam, but you should be able to do with equivalent with upload)

Something like this (untested)
Code: [Select]
!for lcon in mc:icams() do con=lcon cli:print_status(cli:execute('u -nolua settings.lua chdk/scripts/')) end
edit:
correct icams usage
« Last Edit: 10 / April / 2015, 21:27:39 by reyalp »
Don't forget what the H stands for.

Re: Multicam file uploads
« Reply #2 on: 10 / April / 2015, 12:13:55 »
Thanks reyalp!
Minor modification to your posted code for anyone else finding this, this is what works.
Code: [Select]
!for i,lcon in ipairs(mc.cams) do con=lcon cli:print_status(cli:execute('u -nolua settings.lua chdk/scripts/')) endA follow-up question. I have all the cameras set to run my setting script on startup (pushing buttons on the camera I found to be very temperamental - especially if you don't know the exact state the camera is in when you start). Launching the settings script on boot has proven to be very consistent. I'd love for them to reboot after I've uploaded the updated settings script. I've tried
Code: [Select]
!for i,lcon in ipairs(mc.cams) do con=lcon cli:print_status(cli:execute('reboot')) end but it ends up just crashing the cameras (sometimes I have to pull the battery before they'll turn on again). I had previously scripted a "wrapper" in c# that cycled through each camera and ran this:
Code: [Select]
c -s=xxxserialxxx
killscript
u settings.lu" chdk/scripts/
reboot -wait=15000
dis
which worked, but took forever (it was doing them serially - so 15 seconds x 14 cameras...).

Any thoughts or suggestions?

Re: Multicam file uploads
« Reply #3 on: 10 / April / 2015, 14:22:27 »
I'm stumped.
I know what you mean gchaprnka. For a long time so was I - still am with a lot of the code and logic.

I haven't done any practical experimentation with multicam.lua yet but have found reyalp's post here http://chdk.setepontos.com/index.php?topic=11817.msg115652#msg115652 very helpful.

I hope the following, very brief, description is useful (i'm sure reyalp will comment if my description is wrong/misleading).

Once you are connected to your favourite list of cams, then

Code: [Select]
mc:start() transmits (and starts) a script on the cameras, containing the code at the end of multicam.lua starting @:

Code: [Select]
mc={
mode_sw_timeout=1000,
...ending @
until mc.done
end
(along with some other code from source file "util.lua")

How? for each camera via:
Code: [Select]
function mc:start_single(lcon,opts)
...
lcon:exec('mc.run('..util.serialize(opts)..')',{libs='multicam'})
[for detail of exec, please see source file file chdku.lua, function con_methods:exec(code,opts_in)]

Now that this script is running on the camera(s), the camera script function:

Quote
function mc.run(opts)
   extend_table(mc,opts)
   set_yield(-1,-1)
   repeat
      local msg=read_usb_msg(mc.msg_timeout)
      if msg then
         mc.cmd,mc.args=string.match(msg,'^([%w_]+)%s*(.*)')
         if type(cmds[mc.cmd]) == 'function' then
            cmds[mc.cmd]()
         else
            write_status(false,'unknown')
         end
      else
         mc.idle()
      end
   until mc.done

is looking (via msg=read_usb_msg(mc.msg_timeout ), in a loop (until "exit"), for messages sent from "multicam.lua":

Code: [Select]
function mc:cmd(cmd,opts) => lcon:write_msg_pcall(sendcmd)
to decide which of the functions of the camera script to run e.g shoot, getlastimg [by cmds[mc.cmd]()].

As reyalp said, the upload funnction is not yet in the camera script file yet (i.e, the text at the end of multicam.lua).

Thanks for posting your mod.

Apologies for a non-programers description  ::)


*

Offline reyalp

  • ******
  • 14121
Re: Multicam file uploads
« Reply #4 on: 10 / April / 2015, 16:03:44 »
Minor modification to your posted code for anyone else finding this, this is what works.
Oops, for mc:icams, it should be
Code: [Select]
for lcon in mc:icams() ...
The reason to use icams is that it respects selecting subsets of cameras, where ipairs(mc.cams) will iterate over all connected cameras. This may not matter for your application.

Quote
A follow-up question. I have all the cameras set to run my setting script on startup (pushing buttons on the camera I found to be very temperamental - especially if you don't know the exact state the camera is in when you start).
Yes, button pushing sub-optimal in the best of times. You may be interested in: http://chdk.setepontos.com/index.php?topic=10624.0 as a more reproducible way of setting some cameras settings.
Quote
Launching the settings script on boot has proven to be very consistent. I'd love for them to reboot after I've uploaded the updated settings script. I've tried
Code: [Select]
!for i,lcon in ipairs(mc.cams) do con=lcon cli:print_status(cli:execute('reboot')) end but it ends up just crashing the cameras (sometimes I have to pull the battery before they'll turn on again).
I'm not entirely sure why it would crash, but by default, the cli reboot command waits for the camera the camera to reboot and then tries to re-connect to the same camera. This may well have problems if you have 14 identical cameras.

If you haven't already, you could try -norecon, which should just fire off the reboot request and continue. You would need to reset the multicam connections later. mc:connect();mc:start() might do it, but I'm not completely sure off the top of my head.

An alternative would be call reboot() from multicam. With one camera, the following seems to work
Code: [Select]
!mc:cmd('call reboot()')
... wait for camera to reboot ...
!mc:connect()
note this uses mc:cmd rather than mc:cmdwait, since the status return will never be sent.
Don't forget what the H stands for.

Re: Multicam file uploads
« Reply #5 on: 10 / April / 2015, 18:16:58 »
Again, thanks for the help. I've made some progress, and am having a different issue.

Oops, for mc:icams, it should be
Code: [Select]
for lcon in mc:icams() ...
The reason to use icams is that it respects selecting subsets of cameras, where ipairs(mc.cams) will iterate over all connected cameras. This may not matter for your application.
It doesn't matter right now, but it may in the future. Thanks for the correction! It works great now (although I haven't tested applying things to subsets of cameras yet)

Quote
Yes, button pushing sub-optimal in the best of times. You may be interested in: http://chdk.setepontos.com/index.php?topic=10624.0 as a more reproducible way of setting some cameras settings.
I'll look into the more reproducible method next week.

Quote
Quote
Launching the settings script on boot has proven to be very consistent. I'd love for them to reboot after I've uploaded the updated settings script. I've tried
Code: [Select]
!for i,lcon in ipairs(mc.cams) do con=lcon cli:print_status(cli:execute('reboot')) end but it ends up just crashing the cameras (sometimes I have to pull the battery before they'll turn on again).
I'm not entirely sure why it would crash, but by default, the cli reboot command waits for the camera the camera to reboot and then tries to re-connect to the same camera. This may well have problems if you have 14 identical cameras.

If you haven't already, you could try -norecon, which should just fire off the reboot request and continue. You would need to reset the multicam connections later. mc:connect();mc:start() might do it, but I'm not completely sure off the top of my head.

An alternative would be call reboot() from multicam. With one camera, the following seems to work
Code: [Select]
!mc:cmd('call reboot()')
... wait for camera to reboot ...
!mc:connect()
note this uses mc:cmd rather than mc:cmdwait, since the status return will never be sent.

Ok - so the only method that seems to work is the
Code: [Select]
!mc:cmd('call reboot()') one, and that only works when I'm in an interactive console. If I try to run chdkptp with the r="settingsUpdate.lua" :
Code: [Select]
!mc=require('multicam')
!mc:connect({list=true})
!for lcon in mc:icams() do con=lcon cli:print_status(cli:execute('u -nolua settings.lua chdk/scripts/')) end
!mc:start()
!mc:cmd('call reboot()')
It crashes the cameras. I think it has to do with the fact that it tries to disconnect from them when the script ends - where the interactive console sits there and waits for the next command. Is there a lua "sleep" command I can add to the end of my script that will keep it from trying to disconnect instantly after sending the reboot command?

*

Offline reyalp

  • ******
  • 14121
Re: Multicam file uploads
« Reply #6 on: 10 / April / 2015, 21:27:00 »
It crashes the cameras. I think it has to do with the fact that it tries to disconnect from them when the script ends - where the interactive console sits there and waits for the next command. Is there a lua "sleep" command I can add to the end of my script that will keep it from trying to disconnect instantly after sending the reboot command?
In chdkptp lua (! commands) sys.sleep(n) will wait n milliseconds. There is some documention of the chdkptp APIs at https://www.assembla.com/spaces/chdkptp/wiki/Scripting_Guide but it doesn't include this function.

I'm would not be surprised if disconnecting in the middle of rebooting confuses things.

An alternate approach might be something like:
Code: [Select]
!mc:cmd('call sleep(10000) reboot()')
!for lcon in self:icams() do lcon:disconnect() end
The idea is to send all the cameras a command to reboot after 10 seconds, and then disconnect all the multicam connections before they do it. I haven't tried it.

Don't forget what the H stands for.

Re: Multicam file uploads
« Reply #7 on: 13 / April / 2015, 12:03:05 »
In chdkptp lua (! commands) sys.sleep(n) will wait n milliseconds. There is some documention of the chdkptp APIs at https://www.assembla.com/spaces/chdkptp/wiki/Scripting_Guide but it doesn't include this function.

I'm would not be surprised if disconnecting in the middle of rebooting confuses things.

An alternate approach might be something like:
Code: [Select]
!mc:cmd('call sleep(10000) reboot()')
!for lcon in self:icams() do lcon:disconnect() end
The idea is to send all the cameras a command to reboot after 10 seconds, and then disconnect all the multicam connections before they do it. I haven't tried it.

I tried the second option first - I'd rather not sleep a script waiting for things to end. As it turns out, the cameras crashed. However, they didn't seem to mind when I took out the disconnect for loop, and just used:
Code: [Select]
!mc:cmd('call sleep(10000) reboot()')

So that's working! For the sake of anyone who finds this in the future, my whole script for uploading a settings file that's set to run on reboot, and then automatically rebooting all the cameras is this:
Code: [Select]
!mc=require('multicam')
!mc:connect({list=true})
!for lcon in mc:icams() do con=lcon cli:print_status(cli:execute('u -nolua settings.lua chdk/scripts/')) end
!mc:start()
!mc:cmd('call sleep(10000) reboot()')
and my settings file is attached. I dynamically comment out the section for switching to JPEG + Raw before uploading it. So far, its been very consistent at setting things for my cameras (Powershot S110). It's not the fastest, but you only need to run it if a camera gets screwed up or you want to change something like the white balance, how long the screen stays on, etc.

Thanks reyalp for the help!


 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal