Skip to content

Instantly share code, notes, and snippets.

@codeanticode
Created August 11, 2016 23:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codeanticode/56b6504eac09facc9e7fdb6fd6a65c0b to your computer and use it in GitHub Desktop.
Save codeanticode/56b6504eac09facc9e7fdb6fd6a65c0b to your computer and use it in GitHub Desktop.
Processing sketch to keep the GoPro alive
import java.net.Socket;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
void setup() {
thread("keepAlive");
}
void draw() {
}
void keepAlive() {
String UDP_IP = "10.5.5.9";
int UDP_PORT = 8554;
int KEEP_ALIVE_PERIOD = 2500;
while (true) {
Socket socket = null;
try {
socket = new Socket(UDP_IP, UDP_PORT);
//Send the message to the server
OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
String sendMessage = "_GPHD_:0:0:2:0.000000\n";
bw.write(sendMessage);
bw.flush();
}
catch (Exception exception) {
exception.printStackTrace();
}
finally {
//Closing the socket
try {
if (socket != null) socket.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
delay(KEEP_ALIVE_PERIOD);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment