Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ideviceinfo com.apple.mobile.battery over WiFi - sometimes works? #947

Closed
JCsplash opened this issue May 8, 2020 · 28 comments
Closed

ideviceinfo com.apple.mobile.battery over WiFi - sometimes works? #947

JCsplash opened this issue May 8, 2020 · 28 comments

Comments

@JCsplash
Copy link

JCsplash commented May 8, 2020

It seems like ideviceinfo -u DID -q com.apple.mobile.battery over WiFi (with iTunes WiFi Sync turned on without usb connection - sometimes works).

Is this considered normal?

@JCsplash JCsplash changed the title ideviceinfo com.apple.mobile.battery - over WiFi? ideviceinfo com.apple.mobile.battery over WiFi - sometimes works? May 8, 2020
@JCsplash JCsplash closed this as completed May 8, 2020
@nikias
Copy link
Member

nikias commented May 8, 2020

The wifi connection is not permanent. It only works when the device wakes up every now and then.

@JCsplash
Copy link
Author

JCsplash commented May 9, 2020

You're right Nikias but the wait is at most a couple minutes in my case so it isn't bad. Thanks for all you do!

Do you think it'll ever be possible to read Apple Watch's battery level through ideviceinfo? Maybe battery level can go from Watch → iPhone → Custom Bonjour (?) Sync Service → ideviceinfo / mac. Would this be possible?

@nikias
Copy link
Member

nikias commented May 9, 2020

@JCsplash for Apple watch we need to go through companion proxy. I think this is possible.

@JCsplash
Copy link
Author

JCsplash commented May 9, 2020

@nikias Would you mind elaborating a bit? Would this approach require an apple watch app and/or iPhone app?

Right now I plan to do it the brute force way :(

  1. Get battery level on custom Apple Watch App (via background tasks)
  2. Send charge to iPhone companion app (via watch connectivity)
  3. Send charge to Firebase from iPhone
  4. Mac reads from firebase.

If somehow we could achieve Apple Watch → Mac directly that’d be huge. But not sure what exactly you’re thinking of.

@nikias
Copy link
Member

nikias commented May 10, 2020

I will post an addition to the library in the upcoming days and then you implement it for your needs. No need for an app. Just stay put.

@JCsplash
Copy link
Author

Thank you @nikias! I just finished the app above which works but is overkill and slow (watch connectivity only gives me at most 2 updates an hr).

I can’t wait to try your solution. I'm already using ideviceinfo to get ipad / iphone charge so this would be perfect. If you’d be down to share your thought process along the way, I’d really appreciate that as well!

@JCsplash
Copy link
Author

Also @nikias I found the code below that tries this com.apple.companion_proxy approach.

https://gist.github.com/matteyeux/04df80e5368d99a001b7

Maybe this could help?

@nikias
Copy link
Member

nikias commented May 18, 2020

@JCsplash
Copy link
Author

@nikias thank you for making this, it looks great! I’m not exactly sure how i can use it though. Would you mind sharing some more instructions? Is there a command i can call like ideviceinfo?

@nikias
Copy link
Member

nikias commented May 19, 2020

@JCsplash compile and run my test program comptest that I posed in my previous comment.

@JCsplash
Copy link
Author

JCsplash commented May 19, 2020

Screen Shot 2020-05-19 at 12 00 47 AM

@nikias I'm getting " error: no matching function for call to 'idevice_new_with_options'". I pretty sure i have the latest code. Any thoughts on what to do here?

@nikias
Copy link
Member

nikias commented May 19, 2020

You must have an older version installed somewhere.

@JCsplash
Copy link
Author

JCsplash commented May 19, 2020

EDIT: Ended up doing the following which was able to compile comptest.

gcc comptest.c -L<PATH TO DIRECTORY WITH LIBIMOBILEDEVICE.A> -limobiledevice  -L<PATH TO DIRECTORY WITH LIBPLIST.A> -lplist

I'm running into this error now. Are you able to successfully compile/link by just doing "gcc comptest.c"?

I checked that i do have companion_proxy.h installed in the latest version. But somehow comptest is not recognizing its methods.

Screen Shot 2020-05-19 at 10 59 48 AM

@JCsplash
Copy link
Author

JCsplash commented May 19, 2020

This works amazing! Thank you so much @nikias ! Is there any way to make it run a bit faster like idevice_id or ideviceinfo? Right now it takes about 3-4s.

Here's what I did to get it working (if anyone else needs help)

Compiling Code

gcc <INSERT_PATH_TO_COMPTEST> -L<INSERT_PATH_TO DIRECTORY_WITH_LIBIMOBILEDEVICE.A> -limobiledevice  -L<INSERT_PATH_TO_DIRECTORY_WITH_LIBPLIST.A> -lplist -o <INSERT_YOUR_FILE_NAME>

Move executable to /usr/local/bin so it can be used globally (Optional)

Running Code

<INSERT_YOUR_FILE_NAME> <INSERT_IPHONE_UDID>

@nikias
Copy link
Member

nikias commented May 19, 2020

It doesn't run faster, this is how Apple implemented it unfortunately. Like every time you query a key it closes the connection from the device side...

@JCsplash
Copy link
Author

No worries, this is great. Do you know if apple pencil also uses companion_proxy to connect to iPad or if that's just for watches?

@nikias
Copy link
Member

nikias commented May 19, 2020

Just watches. Appel Pencil uses Bluetooth LE.

@JCsplash
Copy link
Author

JCsplash commented May 19, 2020

@nikias Sounds good. What do you think about adding a timeout to comptest? Do you think it's necessary?

@nikias
Copy link
Member

nikias commented May 20, 2020

Do whatever you want with it, it's just a proof of concept.

@JCsplash
Copy link
Author

Sounds good. Thank you so much @nikias !

@JCsplash
Copy link
Author

Hey @nikias is there a "BatteryIsCharging" or "ExternalChargeCapable" value for Apple Watch? I tried using get_value_from_watch but just got back "Unexpected error occurred".

I'm wondering if those fields even exist?

@nikias
Copy link
Member

nikias commented May 21, 2020

BatteryIsCharging definitely exists. See my updated example in the gist.

@nikias
Copy link
Member

nikias commented May 21, 2020

Also please update libplist again, I had a name mismatch between header file and public interface function.

@JCsplash
Copy link
Author

@nikias Did you push your libplist changes? I still see "bbde6a4" as the last libplist commit made 6 days ago?

@nikias
Copy link
Member

nikias commented May 21, 2020

my bad, now I did

@JCsplash
Copy link
Author

Just updated libplist, compiled, and BatteryIsCharging works great! Thanks @nikias !

@JCsplash
Copy link
Author

Hey @nikias , quick question. Do you know if WiFi networks can have WiFi sync disabled by their administrators? I realized WiFi sync works on my WPA2 Personal Network but not on the WPA2 Enterprise network at my school. Is this typical?

@nikias
Copy link
Member

nikias commented May 23, 2020

Maybe the admins are dropping certain packet types. WiFi sync uses mDNS for device discovery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants