how to reboot cams in multicam setup? - LUA Scripting - CHDK Forum supplierdeeply

how to reboot cams in multicam setup?

  • 70 Replies
  • 10267 Views
*

Offline Mlapse

  • *****
  • 583
  • S95 S110
how to reboot cams in multicam setup?
« on: 11 / July / 2022, 11:00:51 »
Advertisements
Well, thought i knew enough to solve this, but no  :(

i want to create a loop that enables multicam to reboot periodically. either from the cam (21 days exceeded) or from the pc script (possibly daily with a setclock)
the calculations are no problem, the call for reboot is.

but i couldn't get the lua exec syntax right from the pc-side in multicam. and i did not find examples in any of the ptp lua scripts i looked at.

calling self:cmd('reboot_cam') for a new created function cam side:
function cmds.reboot_cam() did not work, it just wrote reboot_cam in the terminal....checked the spelling, maybe i'm getting dyslectic, but it seemed ok. so i'm missing something pc side.

then i tried from the cam side, autotrigger a reboot: i could not get the autostart to stick(still no after a boot) so i'm confused there too  :blink: ...i would at least have expected it to work and hand me an error, like missing id for multicam in line33

how can i make either or both work?
« Last Edit: 11 / July / 2022, 13:58:21 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14080
Re: how to reboot cams in multicam setup?
« Reply #1 on: 11 / July / 2022, 18:50:46 »
but i couldn't get the lua exec syntax right from the pc-side in multicam. and i did not find examples in any of the ptp lua scripts i looked at.

calling self:cmd('reboot_cam') for a new created function cam side:
function cmds.reboot_cam() did not work, it just wrote reboot_cam in the terminal....checked the spelling, maybe i'm getting dyslectic, but it seemed ok. so i'm missing something pc side.
Adding the function to cmds in the camera side could should be all you need to add a command, so I'd suggest there is a bug somewhere else in your code. What were the contents of reboot_cam?

If you don't think your camera side code is getting called, you can add some prints to check. If the cameras don't reboot, you can also check for a status response, either using mc:cmdwait instead of  cmd mc:wait_status_msg

Of course, for an actual reboot you don't want to use cmdwait, since the connection will be broken.

Quote
then i tried from the cam side, autotrigger a reboot: i could not get the autostart to stick(still no after a boot) so i'm confused there too  :blink: ...i would at least have expected it to work and hand me an error, like missing id for multicam in line33
I don't understand. Are you saying the autostart option isn't being saved? Are you setting it in the menu, or set_config_value? Also, the multicam is sent when you run mc:start, so I'm not clear what you're trying to autostart, or how you expect to get an error related to multicam.
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: how to reboot cams in multicam setup?
« Reply #2 on: 12 / July / 2022, 01:38:10 »
Adding the function to cmds in the camera side could should be all you need to add a command, so I'd suggest there is a bug somewhere else in your code. What were the contents of reboot_cam?

pc side call in script
Code: [Select]
self:cmd('reboot_cam')
cam side function in script
Code: [Select]
function cmds.reboot_cam()
switch_mode_usb(0)        -- move to play
wait_timeout( get_mode, false, 10000, "ERROR: no switch to playback mode")
set_autostart(2)               -- autostart once
reboot()
end
this isn't the complete reboot sequence i need, but as long as this doesn't work i felt it was no use extending it.

i first let multicam take a few shots and then call reboot_cam. it prints reboot_cam in the terminal (only once with 2 cams connected), both cams go to play and multicam.lua is no longer active. (on both cams: last image visible, no other osd info, menu button goes to canon menu)...it has to be the wait_timeout or the set_autostart.

fwiw, the s110 usually has no trouble rebooting with a cam side script.
Quote
I don't understand. Are you saying the autostart option isn't being saved? Are you setting it in the menu, or set_config_value? Also, the multicam is sent when you run mc:start, so I'm not clear what you're trying to autostart, or how you expect to get an error related to multicam.
because i did not know what went wrong, i tried setting autostart in the chdk menu while i made a copy of the cam side script only and loaded that on the cam.
no pc connected.
the error i was expecting was when autostarted (and starting mc.run cam side without a mc:start() from the pc) without a pc to give it an id, it would halt on not having that id....something i'll have to fix later as soon as it reboots.

but since it did not autostart it stopped there.
« Last Edit: 12 / July / 2022, 06:56:17 by Mlapse »
frustration is a key ingredient in progress

*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: how to reboot cams in multicam setup?
« Reply #3 on: 12 / July / 2022, 11:58:42 »
Yup, it was the wait_timeout, should have thought of that before.
replaced it with a 10 second sleep and the cam booted as expected and gave me the error i was expecting in chdku.rlibs.register, called a few lines below from focus:init()
this is since it activated the cam side script i placed on the cam with autostart)
not as nice as the wait but better results :)

this means i can finish the pc side reboot and tinker with how to send the specific data the cam side script needs. where it will be stored and in case of a reboot without pc read when the script is activated.
hopefully that will stay an unlikely event, but if possible i would like to include this.
« Last Edit: 12 / July / 2022, 12:09:10 by Mlapse »
frustration is a key ingredient in progress


*

Offline reyalp

  • ******
  • 14080
Re: how to reboot cams in multicam setup?
« Reply #4 on: 12 / July / 2022, 21:45:54 »
Code: [Select]
wait_timeout( get_mode, false, 10000, "ERROR: no switch to playback mode")
I'm not sure what version of wait_timeout you are using, but if it's based on wait_timeout_write_status in the multicam module, the signature is
Code: [Select]
-- wait, sleeping <wait> ms until <func> returns <value> or timeout hit, write status message
function wait_timeout_write_status(func,value,wait,timeout,msg)
Where wait is the polling interval, and timeout the maximum total time to wait before an error is generated.

rlibs also includes a wait_timeout, but the function is called rlib_wait_timeout and the signature is totally different, with the options passed in a table.

Quote
because i did not know what went wrong, i tried setting autostart in the chdk menu while i made a copy of the cam side script only and loaded that on the cam.
no pc connected.
FWIW, if you do this, at a minimum you need to include all the rlib library code referenced in the depend= line (I guess your next post is referring to this), as well as all everything referenced in their own depend lines.

You can use rlib to put it all together, like
Code: [Select]
mc=require'multicam'
mccode=chdku.rlibs:code({'multicam'})
fsutil.writefile('mccam.lua',mccode .. 'mc.run()')
mccam.lua should now contain your camera side script, but note I have definitely NOT tested that multicam will actually work like this.

Also note that you will want to add a script header to mccam.lua with chdk_version 1.4 or greater, otherwise the CHDK 1.3 compatibility code will be loaded, which could break the multicam code.
Don't forget what the H stands for.

*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: how to reboot cams in multicam setup?
« Reply #5 on: 13 / July / 2022, 05:50:35 »
FWIW, if you do this, at a minimum you need to include all the rlib library code referenced in the depend= line (I guess your next post is referring to this), as well as all everything referenced in their own depend lines.

You can use rlib to put it all together, like
Code: [Select]
mc=require'multicam'
mccode=chdku.rlibs:code({'multicam'})
fsutil.writefile('mccam.lua',mccode .. 'mc.run()')
mccam.lua should now contain your camera side script, but note I have definitely NOT tested that multicam will actually work like this.

Also note that you will want to add a script header to mccam.lua with chdk_version 1.4 or greater, otherwise the CHDK 1.3 compatibility code will be loaded, which could break the multicam code.

well it wasn't my next question, i'm first trying to make the top priority things work and then the loose ends....and for me rebooting without the pc means a few things have definatly gone wrong.
but it would have come up, i'm sure.....

although the code reads logical and i would like to test if i could make multicam work like this.
at this moment i can't quite follow...i executed the code (!) but can't find mccam.lua...bet it's me, not your code.

so i'm going back to work on the pc side call for a reboot of the cams: to pick up after the reboot. should i do that with something like self:cmd('connect({list='/home/myname/chdkptp/camlist/listfile'})') or reconnect secondly see if i can get something like download_images(getlastimg) in the interval shoot loop.
« Last Edit: 13 / July / 2022, 13:13:01 by Mlapse »
frustration is a key ingredient in progress

*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: how to reboot cams in multicam setup?
« Reply #6 on: 14 / July / 2022, 08:26:27 »
Code: [Select]
                self:cmd('reboot_cam')
                self:cmd('exit')
                self:cmd('disconnect')
                ts=25
                repeat
                   ts=ts-1
                       sys.sleep(1000)
                until ts==0
                self:connect()
                self:start()
                self:cmdwait('rec')
                self:init_sync()
                self:setclock()

this is my code so far for the pc side of the reboot, i tried some other variations on this theme, with reconnect or trying to get the list file used again.
but this is the only one i came up with that did not halt and resumed shooting

however, sometimes i get an error while (re)booting, so i suppose the cams need some more sleep moments i guess.....have no clue what else could be causing this, file enclosed that started with a message timeout and continued with one picture per reboot until it lost all.

btw. the message timeout at startup going to record wasn't something i had before today. and i have made no changes to the regular startup code.
but it seems to be persistant at this moment. i have changed cables but to no avail.
tested the unmodified version of multicam and by now both my cams have that message timeout when moving to record.
who has a clue what could be causing this?...and possibly how to solve this.
« Last Edit: 15 / July / 2022, 07:56:04 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14080
Re: how to reboot cams in multicam setup?
« Reply #7 on: 14 / July / 2022, 20:42:23 »
although the code reads logical and i would like to test if i could make multicam work like this.
at this moment i can't quite follow...i executed the code (!) but can't find mccam.lua...bet it's me, not your code.
The file should be created in whatever the current directory of the chdkptp program is, normally where you started it from. Of course, you can specify a full path if you want. I would expect an error message if there is an error creating the file. As always, you can debug by checking that each step does the expected thing: That chdku.rlibs:code({'multicam'}) returns a string, and that fsutil.writefile(filename, contents) creates a file.

Code: [Select]
                self:cmd('reboot_cam')
                self:cmd('exit')
                self:cmd('disconnect')
I'm not sure if it explains the problems you encountered, but there are a few issues I would note here:
1) mc:cmd('exit') ends the camera side script. So in your code above, it should be unnecessary, since the camera will reboot before it happens. If the camera managed to start rebooting by the time it was sent, it would cause a connection error.
2) 'disconnect' isn't a camera side script command. Unknown commands just return an error status (with write_usb_msg), which you won't notice with mc:cmd() (as opposed to cmdwait). To disconnect, you want mc:disconnect()
3) You want to disconnect before the reboot happens, so the PC side can clearly close its connection. That means your reboot_cam command should include something like
Code: [Select]
sleep(1000)
reboot()
In the code you posted previously, the switch to playback might provide enough time, but I'd suggest doing it explicitly.
Don't forget what the H stands for.


*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: how to reboot cams in multicam setup?
« Reply #8 on: 15 / July / 2022, 02:02:32 »
The file should be created in whatever the current directory of the chdkptp program is, normally where you started it from. Of course, you can specify a full path if you want. I would expect an error message if there is an error creating the file. As always, you can debug by checking that each step does the expected thing: That chdku.rlibs:code({'multicam'}) returns a string, and that fsutil.writefile(filename, contents) creates a file.
tried again in the chdkptp terminal (so with ! before each line) it did not give any error or other feedback and there is no file in the chdkptp folder.
Quote
I'm not sure if it explains the problems you encountered, but there are a few issues I would note here:
1) mc:cmd('exit') ends the camera side script. So in your code above, it should be unnecessary, since the camera will reboot before it happens. If the camera managed to start rebooting by the time it was sent, it would cause a connection error.
2) 'disconnect' isn't a camera side script command. Unknown commands just return an error status (with write_usb_msg), which you won't notice with mc:cmd() (as opposed to cmdwait). To disconnect, you want mc:disconnect()
3) You want to disconnect before the reboot happens, so the PC side can clearly close its connection. That means your reboot_cam command should include something like
Code: [Select]
sleep(1000)
reboot()
In the code you posted previously, the switch to playback might provide enough time, but I'd suggest doing it explicitly.

1) i am assuming the switch to playback with the sleep would give it enough time to prevent that error. however, the cam still performed the reboot after the exit suggesting it had not ending the cam side script. i guess because during the sleep it does not process a new cmd...
2) right, disconnect call same as connect, should have thought of that myself...code adapted, exit out, (dis)connect written in there properly.
3) cam side already includes a 12 sec sleep after moving to play and before actual reboot. is that explicitly enough? or should it also wait for a message 'disconnect'.

just yet both cams had no timeout message at start.

cam side reboot function:
Code: [Select]
function cmds.reboot_cam()
switch_mode_usb(0)
ts=12
repeat
ts=ts-1
sleep(1000)
until ts==0
reboot()
end

pc-side
Code: [Select]
                self:cmd('reboot_cam')
                self:disconnect()
                ts=25
                repeat
            ts=ts-1
                    sys.sleep(1000)
                until ts==0
self:connect()
                self:start()
                self:cmdwait('rec')
                self:init_sync()
                self:setclock()


included another file, with the new code it only made one attempt to reboot before a halt:
making the disconnect work leads to a fault with init_sync()
Quote
WARNING: init_sync_single_send /home/me/chdkptp/lua/multicam.lua:559: attempt to perform arithmetic on a boolean value (local 'rt0')

for my diversion of this i think i'm going to solder a set of lm2596s together for the cams. that is at least straight forward for me ;)
« Last Edit: 15 / July / 2022, 10:53:10 by Mlapse »
frustration is a key ingredient in progress

*

Offline reyalp

  • ******
  • 14080
Re: how to reboot cams in multicam setup?
« Reply #9 on: 15 / July / 2022, 18:08:50 »
tried again in the chdkptp terminal (so with ! before each line) it did not give any error or other feedback and there is no file in the chdkptp folder.
As always, you can debug by checking that each step does the expected thing: That chdku.rlibs:code({'multicam'}) returns a string, and that fsutil.writefile(filename, contents) creates a file.

To be more specific:
If you do !return chdku.rlibs:code({'multicam'})  does it print a whole bunch of code?

If you do !fsutil.writefile('test.txt','test') does it create a file named test.txt? If not, what happens if you use a full path to a directory you know you can write to?

Quote
1) i am assuming the switch to playback with the sleep would give it enough time to prevent that error. however, the cam still performed the reboot after the exit suggesting it had not ending the cam side script. i guess because during the sleep it does not process a new cmd...
Correct. The multicam script sits in a loop reading messages (in mc.run). When it receives a message, it checks if it starts with a string of non-whitespace characters identifying a command in cmds. If so, it calls it, and no more messages are processed until the command function returns.
If no matching command is found, it writes a status message with message text 'unknown'.

If the PC sends messages before the command completes, they are queued (in the camera side C code) until the script calls read_usb_msg again.

Quote
3) cam side already includes a 12 sec sleep after moving to play and before actual reboot. is that explicitly enough? or should it also wait for a message 'disconnect'.
12 sec should be plenty, you just need time for mc:cmd to complete sending to all cameras and the disconnect to complete, which should be a small fraction of the a second with only a few cameras.

Quote
included another file, with the new code it only made one attempt to reboot before a halt:
I don't understand what this refers to.
Quote
making the disconnect work leads to a fault with init_sync()
Code: [Select]
WARNING: init_sync_single_send /home/me/chdkptp/lua/multicam.lua:559: attempt to perform arithmetic on a boolean value (local 'rt0')
So
init_sync_cam sends a 'tick' message, waits for a response, passes the result to init_sync_single, passing the message status value (which should be the result of the 'tick' command in rt0
init_sync_single then calls init_sync_single_send with the same value as rt0.

The error says rt0 was a boolean when should be a number, presumably in the line
Code: [Select]
local expect = rt0 + diff
That implies that either the response to the 'tick' command was a boolean, or there was somehow a different, stale message waiting. I don't see an obvious way either of these would happen in the code you posted, but a first step to debugging would be see what's in the message, for example by printing it like
Code: [Select]
function mc:init_sync_cam(lcon,count)
local t0=ticktime.get()
lcon:write_msg('tick')
local msg=lcon:wait_msg({
mtype='user',
msubtype='table',
munserialize=true,
})
-- added
printf('%d: %s\n',lcon.mc_id,util.serialize(msg))
self:init_sync_single(lcon,t0,msg.status,count)
end
The message from 'tick' should look like:
Code: [Select]
1: {
 status=81670,
 cmd="tick"
}
Note that it includes the name of the command the message is a response to, specifically to aid debugging mixed up messages ;)
Don't forget what the H stands for.

 

Related Topics