supplierdeeply

Lua command examples for CHDKPTP CLI?

  • 16 Replies
  • 1140 Views
Lua command examples for CHDKPTP CLI?
« on: 03 / November / 2015, 15:37:44 »
Advertisements
Hello - I am hoping someone could post some examples of how to execute individual commands in CHDKPTP CLI. I am having a hard time figuring out the syntax to execute individual commands.

For instance how do I execute:

get_zoom_steps

or

set_zoom

or

get_vbatt


I'm sure this is painfully simple, thank you for your patience :)


Re: Lua command examples for CHDKPTP CLI?
« Reply #1 on: 03 / November / 2015, 15:48:37 »
Please don't post the same question twice.  There are only a few people who answer questions here and they read all posts.  And tend to get grumpy when you do that.  A response might take 24 hours.
Ported : A1200  SD940  G10  Powershot N  G16*

Re: Lua command examples for CHDKPTP CLI?
« Reply #2 on: 03 / November / 2015, 16:26:37 »
My apologies. How does one close / delete a topic?

nevermind - its already been closed
« Last Edit: 03 / November / 2015, 16:32:42 by aquilatarot »

*

Offline reyalp

  • ******
  • 10863
Re: Lua command examples for CHDKPTP CLI?
« Reply #3 on: 03 / November / 2015, 16:37:07 »
There are some examples in the USAGE.TXT included with chdkptp.

From your other post
Quote
= get_zoom
! get_zoom
. get_zoom

this is basically the error I get:

ERROR: :80: '=' expected near '<eof>'
user code: 1
Lua you send to the camera has to be valid Lua. So to call a function like get_zoom, you need to use get_zoom().

To run code on the camera in chdkptp, you should start the line wither either = or .
The difference is that = waits for the code to finish and prints any return values, while . does not. To actually return a value for = to print, you code must also include a return statement.

So to see the current zoom level, you would use
Code: [Select]
=return get_zoom()

See http://www.lua.org/manual/5.1/ for general Lua syntax. You should also be able to find some general Lua tutorials on the web. http://chdk.wikia.com/wiki/Lua has some additional resources.


Edit:
For completeness, ! runs Lua code in chdkptp, not on the camera. CHDK camera functions are not directly available, but you can extend the functionality of chdkptp or write more complicated code that interacts with the camera using the chdkptp API. There is some documentation at https://www.assembla.com/spaces/chdkptp/wiki/Scripting_Guide
« Last Edit: 03 / November / 2015, 16:40:23 by reyalp »
Don't forget what the H stands for.


Re: Lua command examples for CHDKPTP CLI?
« Reply #4 on: 03 / November / 2015, 17:18:50 »
That was perfect, you set me straight. I've got it going now. Thank you very much

*

Offline Sdack

  • *
  • 22
Re: Lua command examples for CHDKPTP CLI?
« Reply #5 on: 12 / October / 2017, 03:04:18 »
Hi folks,
I'm progressing with baby steps and have a near complete, working, bash script running on my RaspberryPi (running Raspbian Jesse with the pre built chdk-ptp-r735 version), which uses the command line version of chdkptp-ptp  to connect to my IXUS160, take a picture, transfer it to a USB drive on the Raspberry Pi, then rename the image with a time stamp and upload it to an FTP folder, on my web host, where the images are presented on my website via a folder gallery plug in for Wordpress.

I'm super happy to have got so far but I seem to be stuck on formatting the chdkptp.sh options in my bash script.

In a live, interactive, bash shell, using CHDKPTP, I can connect to the camera and set properties like zoom and focus, using the format shown two posts above this ie.

=set_zoom(50)

however, when I try to add the '=' in my bash script, it doesn't work.. neither do the same commands without the '='.  The specific commands in the code below that aren't working are

set_zoom(100); set_mf(1); set_focus(100)l;

I feel sure it's a simple formatting issue.. please shine a light for me

Code: [Select]
#!/bin/bash

HOSTftp=[myftphost]
USERftp=[myftpusername]
PASSftp=[mypassword]

currdate="`date +%Y_%m_%d___%H_%M`"
currday="`date +%Y_%m_%d`"

mkdir -p /media/pi/PiStore/chdk-download
mkdir -p /media/pi/PiStore/tmp

sudo sh /usr/local/bin/chdkptp-r735/chdkptp.sh -c -e "delete DCIM" -e"exec sys.sleep(2000)" -e"luar switch_mode_usb(1); set_zoom(100); set_mf(1); set_focus(100);shoot(); switch_mode_usb(0)" -e"exec sys.sleep(2000)" -e"mdl DCIM /media/pi/PiStore/tmp" -e"exec sys.sleep(2000)" -e"delete DCIM" -e"dis"

sudo cp /media/pi/PiStore/tmp/1*/*.JPG /media/pi/PiStore/chdk-download/still-$currdate.jpg
sudo cp /media/pi/PiStore/chdk-download/still-$currdate.jpg /media/pi/PiStore/tmp/
#sudo rm -rf /media/pi/PiStore/tmp/*
echo "FTP Upload"
ftp -inpv $HOSTftp<< EOF
user $USERftp $PASSftp
binary

lcd /media/pi/PiStore/tmp/

cd timelapse/
put still-$currdate.jpg
bye
EOF

sudo rm -rf /media/pi/PiStore/tmp/*
echo "Finished - `date +%y-%m-%d__%H-%M`"


exit 0

I suspect this style of script, where the majority of it is done in the bash style, with a call to chdkptp.sh and a subsequent string of options to modify the output to the camera.  Most of the scripts I've seen so far seem to be built in lua for upload to the camera.  If there are any examples of the bash script approach that I can look at, please link to to them.

The distinct advantage of my bash script approach, to my mind, is the

Best wishes

Nigel
Byron Bay
Australia
« Last Edit: 12 / October / 2017, 22:28:02 by Sdack »

*

Offline reyalp

  • ******
  • 10863
Re: Lua command examples for CHDKPTP CLI?
« Reply #6 on: 13 / October / 2017, 03:33:28 »
In a live, interactive, bash shell, using CHDKPTP, I can connect to the camera and set properties like zoom and focus, using the format shown two posts above this ie.
The first thing I'd try is pasting your whole command chdkptp, as a single line. Note that you don't need ; to separate them in lua, spaces are enough.

Another thing I notice is that you have no delay between any of the steps. It's quite likely you need some delay after switch_mod_usb(), and possibly after set_zoom or set_focus. You can do this camera side with sleep(ms)

Also, I would recommend using the chdkptp 'rec' and 'play' commands rather than using switch_mode_usb() directly, because the chdkptp commands wait for the switch to complete, and do the right thing if the mode is already set.
So something like
Code: [Select]
...
-e"rec" -e"set_zoom(100) set_mf(1) set_focus(100) shoot() sleep(1000)" -e"play"
note the sleep(1000) after shoot to allow the shot to completely finish before trying to go to play. You might not need a full second, because shoot waits for most of the shooting process.

Quote
set_zoom(100); set_mf(1); set_focus(100)l;
Maybe just a typo in the post since I don't see it in the code, but you have an 'l' after set_focus.

Don't forget what the H stands for.

*

Offline Sdack

  • *
  • 22
Re: Lua command examples for CHDKPTP CLI?
« Reply #7 on: 13 / October / 2017, 04:29:22 »
Thanks heaps,

will try out your suggestions on the weekend.
Have a good one!!!
Nigel


*

Offline Sdack

  • *
  • 22
Re: Lua command examples for CHDKPTP CLI?
« Reply #8 on: 14 / October / 2017, 17:31:43 »
Hi
I tried following your suggestions with no success.. I hammered away at it for a while but didn't find a clear syntax that worked.  My understanding of when to use ";" is unclear and I can't find any examples to follow.

Considering there are many fine examples of Lua scripts, I'm wondering if there is another way to proceed.. perhaps by invoking a more complete Lua script from bash, instead of the base chdkptp.sh with extended options?

Cheers

*

Offline reyalp

  • ******
  • 10863
Re: Lua command examples for CHDKPTP CLI?
« Reply #9 on: 14 / October / 2017, 21:49:08 »
Hi
I tried following your suggestions with no success.. I hammered away at it for a while but didn't find a clear syntax that worked.
If you can describe more specifically what doesn't work, it would be easier to help. What happens when it "doesn't work", are there any error messages?

The syntax you are using seems to be generally correct, so my guess is the failure is caused by behavior you didn't expect rather than syntax.

My approach to something like this would adding adding pieces until one fails and then try to figure out why that one fails.

As I mentioned in the earlier post, the most obvious difference between putting it all on the command line and entering it manually in the chdkptp console is timing, because entering the commands manually adds delays between the commands. If that is the problem, the pasting the same sequence of commands into the console as a single = line should fail in the same way.

If that's true, than you should be able to identify which one fails and start adding delays.

Quote
Considering there are many fine examples of Lua scripts, I'm wondering if there is another way to proceed.. perhaps by invoking a more complete Lua script from bash, instead of the base chdkptp.sh with extended options?
Yes, there are quite a few ways you can do this.

You can put a sequence of chdkptp commands (that you would enter at the chdkptp prompt, like 'rec' or 'luar' etc) and execute them with chdkptp.sh -e"source myfile.txt"

You write chdkptp side lua code and run it with -e"exec dofile('myfile.lua')"

You could also combine all the camera side lua you are sending with luar into a single file and run that, for example using
 -e'luar <mycamfile.lua'
Note in this case the < is intended for chdkptp, so must be protected from bash by quotes if you use it from the command line.

Quote
My understanding of when to use ";" is unclear and I can't find any examples to follow.
You basically don't need to use ";" in lua. You can use it instead of space if you want.
print('hello');print('world')
and
print('hello') print('world')
and
print('hello')
print('world')

all do exactly the same thing.

Don't forget what the H stands for.

 

Related Topics