Any Camera Connect reverse engineering? - General Discussion and Assistance - CHDK Forum

Any Camera Connect reverse engineering?

  • 28 Replies
  • 5470 Views
*

Offline RaduP

  • *****
  • 926
Any Camera Connect reverse engineering?
« on: 19 / November / 2023, 13:34:21 »
Advertisements
Hello everyone

I am working at a universal macro slider. It uses an ESP32 with a nice slider and stepper controller I got from Ali express.
I wrote a web configuration interface that can be accessed from a phone or computer. You can set the number of steps, delays, etc. And it can also communicate with the device that's on it via BT or IR. Right now it supports any phone camera (it sends the shutter key via BT) and Canon cameras via IR. I plan to add some other cameras that use IR on the list (which should be easy). And I would like to add a wifi remote trigger option too (and support as many cameras as possible). I know that newer Canon cameras have a standard API (which I didn't check yet because I don't have a camera that supports it). Older cameras with wifi use the Camera Connect app to enable remote shutter and other things that I don't need. I looked online and couldn't find any info, so I was wondering if someone here managed to find out how to do remote shutter via wifi on cameras not supporting the newer CCAPI.


Also, if anyone is interested in my project, please ask.

*

Offline RaduP

  • *****
  • 926
Re: Any Camera Connect reverse engineering?
« Reply #1 on: 22 / December / 2023, 08:16:20 »
Well, after a lot of research I finally got it to work. It turns out CHDK is not needed for PTP/IP. Unfortunately the protocol is not very well documented, but this blog helped a lot: https://julianschroden.com/post/2023-05-10-pairing-and-initializing-a-ptp-ip-connection-with-a-canon-eos-camera/
If you are interested in the code (for Arduino, but it can be ported for other OSes with a few modifications) you can find it here: https://github.com/raduprv/esp32_macro_rail/

*

Offline reyalp

  • ******
  • 14125
Re: Any Camera Connect reverse engineering?
« Reply #2 on: 22 / December / 2023, 13:35:31 »
Well, after a lot of research I finally got it to work. It turns out CHDK is not needed for PTP/IP. Unfortunately the protocol is not very well documented, but this blog helped a lot: https://julianschroden.com/post/2023-05-10-pairing-and-initializing-a-ptp-ip-connection-with-a-canon-eos-camera/
Nice find.

FWIW, I also implemented basic PTP/IP support in chkdptp, along with a python script to assist in pairing https://chdk.setepontos.com/index.php?topic=10724.msg145439#msg145439

None of this requires CHDK specifically. That said, powershots don't normally support switching to shooting mode when PTP is active, so that generally needs CHDK and often some additional PTP/IP specific hacks discussed in that thread and in https://chdk.setepontos.com/index.php?topic=14294.0

I suppose you could conceivably do this with the Canon eventproc interface https://chdk.setepontos.com/index.php?topic=4338.msg147738#msg147738 which is available over PTP/IP.
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 926
Re: Any Camera Connect reverse engineering?
« Reply #3 on: 22 / December / 2023, 13:46:03 »
The discovery part (UPnP) is superfluous. I mean, it's nice to know the camera IP without checking the router connected clients page, but you don't need it for PTP/IP. The camera is happy to accept any connection.


Regarding the not being able to switch to shooting mode, are you sure about that? I can do that just fie on my Canon M3. You just have to issue the proper command: canon_set_property_value(0xd1b0,8);//shoot mode/live view
You can check my macro rail project to see the complete Canon implementation (to shoot) and change props. My implementation is very basic, I don't need anything other than shooting, but it can be extended if needed.

*

Offline reyalp

  • ******
  • 14125
Re: Any Camera Connect reverse engineering?
« Reply #4 on: 22 / December / 2023, 14:16:59 »
The discovery part (UPnP) is superfluous. I mean, it's nice to know the camera IP without checking the router connected clients page, but you don't need it for PTP/IP. The camera is happy to accept any connection.
How do you put the camera in a state where it will accept PTP/IP connections, without doing the UPnP stuff?

I did not find a way to do this. On my cameras, using the camera menu to initiate a connect, it appears to be absolutely required, as described in https://chdk.setepontos.com/index.php?topic=10724.msg145418#msg145418

Quote
Regarding the not being able to switch to shooting mode, are you sure about that? I can do that just fie on my Canon M3. You just have to issue the proper command: canon_set_property_value(0xd1b0,8);//shoot mode/live view
Was not aware of that, but I'd file it under "additional hacking" ;)
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 926
Re: Any Camera Connect reverse engineering?
« Reply #5 on: 22 / December / 2023, 14:26:17 »
How do you put the camera in a state where it will accept PTP/IP connections, without doing the UPnP stuff?

On my Canon M3 I go to playback mode, then press the Wi-Fi key (the up arrow on the joystick), then Connect to smartphone.

As for the 'hack' to switch it to live mode, I know it works on my camera, but please try it on your camera first, see if it works on all.
« Last Edit: 22 / December / 2023, 14:28:23 by RaduP »

*

Offline reyalp

  • ******
  • 14125
Re: Any Camera Connect reverse engineering?
« Reply #6 on: 22 / December / 2023, 16:36:10 »
Quote
How do you put the camera in a state where it will accept PTP/IP connections, without doing the UPnP stuff?
On my Canon M3 I go to playback mode, then press the Wi-Fi key (the up arrow on the joystick), then Connect to smartphone.
Ah, that must be the difference, I've only ever used PC option, which presumably makes some effort to make sure it's connecting to the expected device on the wireless network. I never figured out exactly how it decides, but my guess is IP or MAC. I never investigated the phone option, I kinda expected they used a different protocol and didn't want to install Canon's apps.

I guess you already paired the camera with a phone running Canon's app?

Quote
As for the 'hack' to switch it to live mode, I know it works on my camera, but please try it on your camera first, see if it works on all.
Yes, I didn't mean 'hack' as something bad, just in terms of needing to code somewhere doing something undocumented. I'll check it out. Would be nice to have a less hokey method than the ways I found.
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 926
Re: Any Camera Connect reverse engineering?
« Reply #7 on: 22 / December / 2023, 16:53:44 »
I paired my camera with the phone before, but it shouldn't make a difference. Canon cameras (as opposed to Sony) don't care about credentials, they will accept any connection. Just try it :)


As for the hack, I know what you mean, but I wouldn't really consider it a hack, it's just part of the Canon PTP, just not documented. The code is in the gphoto2 lib https://fossies.org/linux/libgphoto2/camlibs/ptp2/ptp.h, and it's called #define PTP_DPC_CANON_EOS_EVFOutputDevice   0xD1b0
The name is a bit unintuitive, and I am not sure if it works on your camera as well, but I hope it works. If it doesn't, try different values instead of 8.


Do you by any chance have an ESP32 around? If so, maybe you can try my code and see if it works on your camera too.

*

Offline reyalp

  • ******
  • 14125
Re: Any Camera Connect reverse engineering?
« Reply #8 on: 23 / December / 2023, 02:33:12 »
I paired my camera with the phone before, but it shouldn't make a difference. Canon cameras (as opposed to Sony) don't care about credentials, they will accept any connection. Just try it :)
On my cameras, using the phone option without any registered only allows the "add new device" option. Entering that brings up a "Start dedicated app on target device" screen. On ELPH130 and G7X,  PTP/IP connection fails with an error likely (edit: confirmed  "Connection refused") indicating nothing is listening on the port. However, with SX730, a prompt appears on the camera asking to allow the device and accepting it allows the connection to complete successfully.

Oddly, the CHDK PTP opcode isn't reported as supported on the initial connection, although it's available subsequently and works.

Going through this registers a device in the list with the "friendly name" hard coded in my chdkptp code, unlike the PC connection path which uses a value from the UPnP dialog. (The hard coded name in chdkptp is "whee" and I puzzled over where it got that before I remembered...)

Prop 0xd1b0 is supported on SX730, but so far my attempts to set killed the connection or crashed the camera.

The cameras that don't work also don't generate any UPnP chatter recognized by my script, so I'll need to do some tcpdump-ing to see if they're doing anything else.
Quote
Do you by any chance have an ESP32 around?
Nope
« Last Edit: 23 / December / 2023, 03:20:01 by reyalp »
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 926
Re: Any Camera Connect reverse engineering?
« Reply #9 on: 23 / December / 2023, 08:30:10 »
It's strange that on your G7X at least the port isn't open. Maybe run a portscan on the camera's IP and see if the port is open or not (or if there are other opened ports). I mean, the mobile app must connect somehow to it.

As for the crashes while setting that prop, which PTP command did you use to set it? It must be set with #define PTP_OC_CANON_EOS_SetDevicePropValueEx   0x9110 using a special protocol, not #define PTP_OC_GetDevicePropValue       0x1015

 

Related Topics


SimplePortal © 2008-2014, SimplePortal