goprowifihack icon indicating copy to clipboard operation
goprowifihack copied to clipboard

Bluetooth API for waking HERO5 from wifi-sleep

Open ratnick opened this issue 7 years ago • 81 comments

Problem: HERO5 wifi connection times out when cam not recording. Need guidance for how to re-awake the cam using Bluetooth.

Description: We are using GoPro professionally in the field doing interviews. To be able to sync in-field notes with the video, we have developed a Java program which runs on a PC and a Mac. It is based on https://github.com/DomDomHaas/gopro-wifi-API and works fine on HERO 3.

But after upgrading the Java API to comply with the HTTP API for HERO5, I discovered that HERO5 has a time-out on the wifi connection, when not recording. This happens even if I constantly poll the camera status. According to https://community.gopro.com/t5/Cameras/Hero5-Session-Wifi-vs-Bluetooth/td-p/30201 this is intended behaviour to save battery. It also states that Bluetooth is the mechanism to wake up the cam again.

But I am lacking a prescription for how to wake up the camera using Bluetooth. The API description only states how to do the pairing, but not how to actually re-awake the camera programatically.

I'm sure I'm not the only one facing this kind of issue. Any help would be much appreciated. Once the application is finished, i will of course share it.

  • GoPro Camera(s): HERO5
  • Firmware Version: latest (dec 2017)
  • Steps to reproduce: any scenario not recording.
  • Happens every time? yes

ratnick avatar Jan 03 '18 09:01 ratnick

Same problem here. The Hero5B wifi is available for about 5 minutes after the camera has been turned off and WOL works fine during this time to turn on the gopro again, but after this period wifi is apparently turned off. I would love to see a solution which extends the wifi standby time rather than to use BT. Any solutions appreciated.

mtbsteve avatar Jan 03 '18 21:01 mtbsteve

Yep - so would I. I have tried several ways to extend the wifi-connection time. I have tried (without success) every minute to:

  • send WOL
  • send http status request
  • start/stop a recording (via http)
  • disable + enable wifi connection (from the PC)

But no matter what I do, the gopro terminates the wifi session after 10 or so minutes. When this happens, it's like cutting the branch you sit on, and there is no way of getting wifi back, except using the re-connect UI on the camera itself.

I wonder if there is any way around using bluetooth?

ratnick avatar Jan 08 '18 14:01 ratnick

I tested with my iPhone and the Gopro app connected.

  1. Wifi on, Bluetooth on: the GP5B stays connected forever
  2. Wifi on, Bluetooth off: after 10 min sharp, the Gopro awakens, switches to multishot, takes automatically one multishot, and then continues to stay on
  3. iPhone connected to Gopro wifi, app is closed: wifi connection shuts down exactly after 10 min. While the gopro is still turned on and gopro settings still shows wifi enabled, the gopro access point no longer visible in the iPhone settings. Connection can be reestablished only with bluetooth turned on via the gopro app.

So besides a parallel bluetooth connection, there seems to be a way to keep wifi awake by a mode change plus shutter release within the 10 minutes. Further testing needed....

mtbsteve avatar Jan 08 '18 20:01 mtbsteve

Thanks. It inspired me, so what I do now is:

  1. Connect the PC to the cameras hotspot, and then my PC application to the camera.
  2. Right after (or before, doesn't really matter), connect to the camera with the GoPro app. Stay on that connection for at least 10 minutes. It seems like the app only needs to send the "keep alive" to the camera once, because you can close the app hereafter.

The trick is that the PC can operate the camera using HTTP commands while the cam is the same time connected to the phone (which keeps the cam's wifi alive).

It's simple...but really a messy solution. I simply wonder why GoPro has not implemented a "disable wifi timeout" setting for users who has the camera connected to an external power source.

It seems to work though. Thanks to mtbsteve's inspiration :-)

ratnick avatar Jan 28 '18 08:01 ratnick

Well I don’t believe that this is a viable solution but rather a bug in the gopro firmware. I noticed that after connecting with the gopro app under some circumstances the gopro wifi did not switch off at all even after disabling the wifi in the camera. The only proper solution is with a combination of wifi and a BT connection in parallel.

mtbsteve avatar Jan 28 '18 11:01 mtbsteve

You can keep alive the gopro from my api.

gopro.KeepAlive()

KonradIT avatar Jan 28 '18 12:01 KonradIT

@mtbsteve: I agree - this is not a real solution. It's a "hack" or work-around. @KonradIT: Interesting. My PC program is in Java, so I would need to port your KeepAlive.

Is this the relevant line? sock.sendto("GPHD:0:0:2:0.000000\n".encode(), (self.ip_addr, 8554))

And does it use a bluetooth connection? (sorry for my ignorance here, but I'm really not familiar with sockets and the syntax used here.

thanks :-)

ratnick avatar Jan 29 '18 11:01 ratnick

yes that's the line.

KonradIT avatar Jan 29 '18 13:01 KonradIT

OK, good. Can you elaborate what it does? Is there any documentation behind this? Do you use bluetooth or wifi?

ratnick avatar Jan 29 '18 14:01 ratnick

wifi. look for keep alive on Wikipedia

KonradIT avatar Jan 29 '18 14:01 KonradIT

Excellent-thanks @KonradIT Do I need to constantly send this message to keep it alive? What is the recommended interval?

mtbsteve avatar Jan 29 '18 21:01 mtbsteve

Any explanation why that keep alive works?

@ratnick did you tried the code to Java? I need to use it in C#

Console.WriteLine($"Sending Keep alive, bytes sent: {new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp).SendTo(Encoding.UTF8.GetBytes("_GPHD_:0:0:2:0.000000\n"), new IPEndPoint(IPAddress.Parse("10.5.5.9"), 8554))}");

or

var m = Encoding.UTF8.GetBytes("_GPHD_:0:0:2:0.000000\n");
var c = new UdpClient(AddressFamily.InterNetwork);
Log($"Sending Keep alive, bytes sent: {c.Send(m, m.Length, "10.5.5.9", 8554)}");
c.Close();

An alternative I was trying to do is to use: http://10.5.5.9/gp/gpControl/command/wireless/ap/ssid?ssid=CURRENTSSIDNAME but I have had mixed results. Sometimes it stays alive weeks.

eried avatar Mar 07 '18 08:03 eried

Hi @eried No - i did not try because I could not find any supporting documentation, and without that, it's just a big guess-work. So i stayed with the solution depicted in my post, i.e. letting a mobile phone app handle the keep-alive for the first 10 minutes. Hereafter it seems like the camera keeps itself alive. But admittedly - it's a crappy "solution". But the best i could do with the time I had for this.

ratnick avatar Mar 07 '18 12:03 ratnick

@ratnick but do not you have issues after a while? like a couple hours? I am doing the same but for some reason my gopro stops answering my requests (after a day or so) until I connect via the phone again.

eried avatar Mar 07 '18 13:03 eried

@eried what camera are you using? Bluetooth might be needed to ping the GoPro

KonradIT avatar Mar 07 '18 14:03 KonradIT

@KonradIT Hero Session 5

You mean, on some cameras there is no way to keep them alive without bluetooth? I only need to shoot a photo every hour and retrieve the photo.

eried avatar Mar 07 '18 14:03 eried

Yes @eried , you need to first send a Bluetooth message to wake it up.

KonradIT avatar Mar 07 '18 14:03 KonradIT

But after the first message, can I keep it up with the UDP message you are sending in your wrapper? @KonradIT or I will need the phone all the time to wake it?

eried avatar Mar 07 '18 14:03 eried

Also try to have a Magic Packet sent every few seconds like in here: http://github.com/konradit/gopro-py-api

KonradIT avatar Mar 07 '18 14:03 KonradIT

@eried it seems to only need 10 minutes with the phone app. Aftern then, you can close the app and the gopro stays on. Tested on GoPro 5.

ratnick avatar Mar 07 '18 16:03 ratnick

@eried @ratnick The wake on lan issue affects only the H5 session or H5 Black as well? I will try to "sniff" the Bluetooth wake message.

KonradIT avatar Mar 08 '18 10:03 KonradIT

@KonradIT I only have the H5 session, and yes it sleeps after a while. However,

@ratnick you are totally right, thanks! after leaving my phone 15 mins with the app opened I have been running my script connected to the GoPro for 1 day without any issues!

eried avatar Mar 08 '18 12:03 eried

Hey guys, I can wake up the camera using this app, we can even get fw info.

I cannot pair my GoPro to my laptop though

KonradIT avatar Mar 23 '18 10:03 KonradIT

Just connecting to the camera?

eried avatar Mar 23 '18 14:03 eried

Yes. My laptop's BT controller does not pair with the GoPro for some reason, but theoretically using bluetoothctl trust > pair > connect should work.

KonradIT avatar Mar 23 '18 15:03 KonradIT

https://streamable.com/tjb3t

KonradIT avatar Mar 23 '18 15:03 KonradIT

Here's a link to a full Java implementation for taking notes synchronised with GoPro videos for use in a professional interview setting. GoPro is remote controlled from the app, and it's easy to find the spot in the video corresponding to the note taken during the session. Supports GoPro 3, 4, 5, 6.

https://github.com/ratnick/GoPro-Notetaker-tool

A lot of credits to @KonradIT :-)

ratnick avatar May 01 '18 13:05 ratnick

Hey, anyone figured out how to keep the HERO5 alive & connected to WiFi? Thanks!

krystof-k avatar May 10 '18 09:05 krystof-k

I have some progress. I bought Raspberry Pi with BLE yesterday and I'm able to wake up the GoPro over Bluetooth. However still not figured out how to turn on the WiFi (but at least there is a way to turn GoPro off over WiFi and then turn it on over BLE).

krystof-k avatar May 11 '18 06:05 krystof-k

@krystof-k Which RPI did you buy? Mi Pi Zero stopped working all of a sudden.

KonradIT avatar May 11 '18 06:05 KonradIT