Couple of months ago, my friend* Joseph G. Wezensky gave a presentation on MicroPython at a local Meetup. The presentation was great, but I'm not a big fan of MicroPython on micro controllers. At the end of the presentation, he did something unusual, he gave away ESP8266 kits for attendees to apply what they've learned. I didn't want to take a kit because I bought ESP32 few months earlier and it was not very consistent. Finally, the host told me to take the last one or it will end up on someone's shelf collecting dust.
Making a remote for GoPro is not a new idea; I even found a library for that. I just wanted to make something simpler. I really didn't wanna pay $80 for it.
* Full disclosure: Joe doesn't even know me. However, anyone gives away dev boards is my friend.
Software:We start by couple of includes for ESP8266. If you are using ESP32 you'll have to drop ESP8266 from the header file names. Don't forget to plugin your GoPro SSID and password. I used pin 0 for my push button because it is the one closest to GND so I won't need a jumper.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
HTTPClient http;
char ssid[] = "YourGoProSSID";
char pass[] = "YourGoProPassword";
int OnOffState = 0;
int SwitchPinNumber = 0;
Next, we tell the board we are using the built-in LED and adding an internal pull up resistor to our push button pin. I found it necessary to wait for that pin to finish initializing and that is why I added a while loop.
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(SwitchPinNumber, INPUT_PULLUP);
while (digitalRead(SwitchPinNumber)) yield();
}
In the main loop we will check if the button is pressed then check if we are connected to the camera. If we are not connected, we will keep trying to connect. Once that is settled, we will turn the camera on if it was off or turn it off if it was on with the first SendCommand. The second SendCommand is needed only if the camera has been turned on and we need to start recording. If we are turning the camera off we will wait 5 seconds to make sure we don't reenter the main loop by accident. BTW, I did try to use one button from GoPro but it wouldn't work with the remote and that's why I had to turn on the camera then start recording in two different commands. The last line is used to make the built-in LED blink if the camera is recording and stays solid if it is off.
void loop() {
if (!digitalRead(SwitchPinNumber)) {
if (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) yield();
}
OnOffState = 1 - OnOffState;
SendCommand("bacpac", "PW", "0" + String(OnOffState));
if (OnOffState) SendCommand("bacpac", "SH", "0" + String(OnOffState));
else delay(5000);
tone(LED_BUILTIN, OnOffState * 2);
}
}
Last but not least, we need to define what SendCommand is. We make http call to the camera and wait until we get 200 OK.
void SendCommand(String P1, String P2, String Op) {
http.begin("http://10.5.5.9/" + P1 + "/" + P2 + "?t=" + pass + "&p=%" + Op);
while (http.GET() != 200) yield();
http.end();
}
In this code you'll see that parameter P1 is always "backpac". I only needed two parameters, P2, and Op, but I kept P1 in case I have more time to expand the code to include more commands.
Demo:This video starts with turning GoPro WiFi on (flashing blue on GoPro). Next, turn the remote on (solid blue on remote). Once we press the button, GoPro will turn on and start recording (flashing red on GoPro and flashing blue on the remote). If we press the button again, GoPro will stop recording and turn off.
Comments