Open PlastiBots opened 2 years ago
Have you tried the example in the library, does it work?
As far as i remember on my hero3, if i closed the connection wrongly (i.e. turn off the camera or esp manually) this same problem happened
Hi. Yes, I tried the example and the same thing. It only ever works the first time connected, then after it fails. Only way it works again is by resetting the wifi connection on the GoPro, then it works again for the first time only and fails. I've read other threads with a similar issue. It's as if the GoPro is closing the connection.
I think your delay is too long, you need to call the keep alive more often
Edit: To clarify, I've removed the delay(1000); as well. I tried that. If you look at the sample I included, it dives right into attempting to take a shot while also having a keepAlive() in there. I've even removed it from setup() and tried it in the loop. All result in the same thing. Works fine the first time, then fails until GoPro WiFi is reset.
So, I figured out the steps necessary to cause the fail, but still no closer to determining why. This has only been validated on a Hero 7 Black. After doing all sorts of tests including restarts (3s and 10s), removing power from the GP, downgrading the GP FW to 1.6.1 (was 1.8.x) it fails the same way every time. The only success I could get is to ensure that I always called gp.end() before powering down the ESP or camera. I was able to test this by calling it, then powering down the ESP and GP in different sequences. It always worked when powered back up. If either is powered down without this call, it fails on subsequent power cycles. To get it back in check, I found powering down both devices. For the GoPro remove the battery and any charge cable and wait a minute or so, then power on the GoPro, then the ESP and try again. If this fails after a number of attempts, try resetting the GoPro network connections (not this will require re-pairing to the GP app on your phone).
Code for this is below. I've included a sample for the M5Atom Lite as well as M5Stick-C Plus, but any ESP32 with a few buttons wired up will do. In this case, a single click takes a shot, while holding it > 2 seconds calls gp.end() etc. A bit of a pain but it works. Ideally adding some sort supercap and watching the power pin to detect power disconnect which could feed into a software call go gp.end(). Good news is the M5Stick-C Plus has a built-in battery, so I suppose some code to detect battery drain over time and a graceful power down will do...
Although I'm not certain, I think the GoPro is failing with some feature where it hasn't let go of a setting or mode. I'm thinking something related to the UDP client and maybe flushing things. It seems that a full power down with battery removal clears it for the time being...
About the below code samples: These are both WIP and not in end-state. Right now they simply trigger a photo based on a button click. My end goal is for this to serve as a timelapse photo trigger for my resin printer. It will use a LDR sensor and trigger a photo when UV Light comes on. I already have this working with an ESP32Cam (www.plastibots.com), but wanted to get better resolution out of the GoPro.
M5 Atom Lite Sample:
#define CAMERA HERO7 // Change here for your camera
//from my Hero 7: 06 41 69 EF 79 94
byte remote_MAC_ADD[] = { 0x06, 0x41, 0x69, 0xEF, 0x79, 0x94 };
const char* board = "RTLapseCAM"; //ESP Board Name
GoProControl gp(GOPRO_SSID, GOPRO_PASS, CAMERA, remote_MAC_ADD, board);
void setup()
{
gp.enableDebug(&Serial);
//xTaskCreate(keep_alive, "keep_alive", 10000, NULL, 1, NULL); //for ESP32
while (!gp.isConnected())
{
gp.begin();
}
//delay(1000);
//gp.turnOn();
//gp.confirmPairing();
//gp.keepAlive();
//gp.setMode(PHOTO_MODE);
//gp.keepAlive();
//delay(1000);
//gp.shoot();
//gp.keepAlive();
//delay(1000);
//gp.shoot();
//delay(1000);
//gp.shoot();
Serial.println(">> Printing Status...");
gp.printStatus();
delay(1000);
}
void loop()
{
M5.update(); //Read the press state of the key.
if (M5.Btn.wasPressed())
{
Serial.println("Button - take a shot.");
//if (!gp.isConnected()){gp.begin(); delay(2000);}
gp.shoot();
}
if (M5.Btn.pressedFor(2000)) //pressed for 2 seconds or more.
{
Serial.println("Closing connection.");
gp.end();
}
//Serial.println("In Main Loop. Keep alive.");
gp.keepAlive(); // not needed on HERO3
delay(10);
}
m5 Stick-C Plus Sample (note it's crude and still needs some work):
//#include "M5Atom.h"
#include <M5StickCPlus.h>
#include <GoProControl.h>
#include "Secrets.h"
#define CAMERA HERO7 // Change here for your camera
//from my Hero 7: 06 41 69 EF 79 94
byte remote_MAC_ADD[] = { 0x06, 0x41, 0x69, 0xEF, 0x79, 0x94 };
const char* board = "RTLapseCAM"; //ESP Board Name
boolean doneOnce = false;
GoProControl gp(GOPRO_SSID, GOPRO_PASS, CAMERA, remote_MAC_ADD, board);
void setup()
{
gp.enableDebug(&Serial);
//xTaskCreate(keep_alive, "keep_alive", 10000, NULL, 1, NULL); //for ESP32
M5.begin(); // Initialize M5StickC Plus.
M5.Lcd.setTextColor(TFT_BLUE);
//M5.Lcd.setTextColor(TFT_RED,TFT_BLACK); M5.Lcd.setTextFont(4);
M5.Lcd.setTextSize(3); //Set font size.
M5.Lcd.setRotation(3); //Rotate the screen.
M5.Lcd.setCursor(10, 10);
M5.Lcd.println("RTLapseCAM");
M5.Lcd.println("Connecting...");
while (!gp.isConnected())
{
gp.begin();
}
lcdClear();
M5.Lcd.println("RTLapseCAM");
M5.Lcd.println("Connected!");
Serial.println(">> Printing Status...");
gp.printStatus();
lcdClear();
delay(1000);
M5.Lcd.setTextSize(2); //Set font size.
}
void loop()
{
M5.update(); //Read the press state of the key.
if (M5.BtnA.wasPressed())
{
while (!gp.isConnected()) //if disconnected, re-connect
{
lcdClear(); M5.Lcd.setCursor(10, 10);M5.Lcd.print("Re-Connecting");
gp.begin();
}
Serial.println("Button - take a shot.");
lcdClear(); M5.Lcd.setCursor(10, 10); M5.Lcd.print("Taking a shot..");
//if (!gp.isConnected()){gp.begin(); delay(2000);}
gp.shoot();
}
if (M5.BtnA.pressedFor(2000)) //pressed for 2 seconds or more.
{
Serial.println("Closing connection.");
lcdClear();M5.Lcd.setCursor(10, 10); M5.Lcd.print("Closing Connection.");
gp.end();
delay(2000);
Serial.println("Powering Off M5Stick-C Plus.");
//lcdClear();M5.Lcd.setCursor(10, 10); M5.Lcd.print("POWERING OFF M5");
//delay(1000);
//M5.Axp.PowerOff();
lcdClear();M5.Lcd.setCursor(10, 10); M5.Lcd.print("Re-starting M5");
delay(1000);
esp_restart();
}
//Serial.println("In Main Loop. Keep alive.");
gp.keepAlive(); // not needed on HERO3
delay(10);
}
void lcdClear()
{
M5.Lcd.fillScreen(BLACK);
}
Hi. First off, thank you for the great effort put into creating this library! Have a challenge with failed connections after the first attempt. I can only get the ESP to trigger picture captures after resetting the GoPro WiFi connection and rebooting it. The first time in, I can connect and take photos. After this, it fails. Regardless of power cycling the ESP or the GoPro Below is the code I am using, and further down is the Serial output:
Attempting to connect to SSID: "GP50039006" Using password: "kS9-mMx-Rvx" ....................................................... Connected to GoPro Attempting a shot. Connection lost Attempting a shot. Connect the camera first Attempting a shot. Connect the camera first Attempting a shot. Connect the camera first..