GoPro Script - Hero5 Session

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

brentp
Site Admin
Posts: 5986
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

This is great, thanks! Hopefully this can be woven into the support built into the firmware - penciled in for 2.13.0.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

d_gatorfan
Posts: 16
Joined: Sun Apr 16, 2017 12:11 pm

Post by d_gatorfan »

jeffmcaffer wrote:I got something working for WoL and the GP Session. Here is the rough outline.
After joining the camera's network you tell the camera to wake up using
I have the gopro start/stop scripting working. I would really like to leave the camera off with wifi enabled and have the racecapture wake it up to start recording.

I am trying to get the wake on lan to work on a Hero 4.
My problem is when the camera is asleep, I can't connect to the cameras network.
If i let the race capture connect to the camera, power the camera off and wait for a delayed magic packet transmission, the camera will wake up. So I know my wake on lan function and mac address, etc. is correct.

The error i get when trying to connect to the sleeping camera.
CW_JAP:3 which according the ESP8266 documentation is "cannot find the target AP"

I really think this should work, I can do essentially what I am trying with a cell phone or a pc. Connect to the sleeping cameras wifi, use a WOL app to send a wake on lan packet and it wakes right up. Is there a different way to connect to the camera?

Any ideas would be appreciated.
Dennis

Code: Select all

count = 0
--Specify your GoPro wifi password here
goproPwd = 'florida96'

--Specify your GoPro SSID here
goproSsid = 'gpro'

--Specify Mac address of GoPro for WOL
mac ='D4D919C8F602'

--Speed threshold to start recording
goproStart = 50

--Speed threshold to stop recording
goproStop = 20

--How fast we check, in Hz
tickRate = 10

--Set this to 1 to log communications between RCP & WiFi
debug = 1
-----------------------------
--DO NOT EDIT BELOW
-----------------------------
--the serial port where the WiFi is connected
port = 4
--indicates wifiStatus
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready
wifiStatus = 0
lastInitTime = 0
initTimeout = 20000

function logMsg&#40;msg&#41;
  println&#40;'&#91;GoProWiFi&#93; ' ..msg&#41;
end

function sendCrlf&#40;&#41;
  writeCSer&#40;port, 13&#41;
  writeCSer&#40;port, 10&#41;
end

function sendRaw&#40;val&#41;
  for i=1, #val do
    local c = string.sub&#40;val, i, i&#41;
    writeCSer&#40;port, string.byte&#40;c&#41;&#41;
  end
end

function sendAt&#40;val&#41;
  if debug == 1 then logMsg&#40;'send&#58; ' ..val&#41; end
  sendRaw&#40;val&#41;
  sendCrlf&#40;&#41;
end

function toInt&#40;val&#41;
  return string.sub&#40;val, 1, -3&#41;
end

function httpGet&#40;url&#41;
  sendAt&#40;'AT+CIPSTART="TCP","10.5.5.9",80'&#41;
  sleep&#40;500&#41;
  local crlf = string.char&#40;13&#41; ..string.char&#40;10&#41;
  local get = 'GET ' ..url ..' HTTP/1.0' ..crlf ..crlf
  sendAt&#40;'AT+CIPSEND=' ..toInt&#40;#get&#41;&#41;
  sleep&#40;100&#41;
  sendRaw&#40;get&#41;
  sleep&#40;100&#41;
  sendAt&#40;"AT+CIPCLOSE"&#41;end



function sendGoProShutter&#40;cmd&#41;
  httpGet&#40;'/bacpac/SH?t=' ..goproPwd ..'&p=%' ..cmd&#41;
end

function startGoPro&#40;&#41;
  logMsg&#40;'start GoPro'&#41;
  sendGoProShutter&#40;'01'&#41;    
end

function stopGoPro&#40;&#41;
  logMsg&#40;'stop GoPro'&#41;
  sendGoProShutter&#40;'00'&#41;    
end
 

recording = 0

function initWiFi&#40;&#41;
  logMsg&#40;'initializing'&#41;
  sendAt&#40;'AT+RST'&#41;
  sleep&#40;2000&#41;
  sendAt&#40;'AT+CWMODE_CUR=1'&#41;
  sleep&#40;1000&#41;
  sendAt&#40;'AT+CWJAP_CUR="' ..goproSsid ..'","' ..goproPwd ..'"'&#41;
  wifiStatus = 1
end

function processIncoming&#40;&#41;
  local line = readSer&#40;port, 100&#41;
  if line ~= '' and debug == 1 then print&#40;'incoming response&#58; ' ..line&#41; end
  if string.match&#40;line, 'WIFI GOT IP'&#41; then 
    wifiStatus = 2
  end
  if wifiStatus == 2 and string.match&#40;line, 'OK'&#41; then
    wifiStatus = 3
    logMsg&#40;'ready for GoPro'&#41;
  end
end

function checkGoPro&#40;&#41;
  if wifiStatus == 0 then
    initWiFi&#40;&#41;
    lastInitTime = getUptime&#40;&#41;
    return
  end
  if wifiStatus == 1 and getUptime&#40;&#41; > lastInitTime + initTimeout then
    logMsg&#40;'could not connect to GoPro'&#41;
 

  end
  processIncoming&#40;&#41;
  if wifiStatus ~= 3 then
    return
  end
  trigger = getAnalog&#40;1&#41;

  if recording == 0 and trigger > goproStart then
    startGoPro&#40;&#41;
    recording = 1
  end
  if recording == 1 and trigger < goproStop then
    stopGoPro&#40;&#41;
    recording = 0
  end 
end


function wakeGoPro&#40;&#41;
logMsg&#40;'waking GoPro'&#41; 
local macChars = ''
for w in string.gmatch&#40;mac, "&#91;0-9A-Za-z&#93;&#91;0-9A-Za-z&#93;"&#41; do
macChars = macChars .. string.char&#40;tonumber&#40;w, 16&#41;&#41;
end
local magicPacket = string.char&#40;0xff&#41;&#58;rep&#40;6&#41; .. macChars&#58;rep&#40;16&#41;;
logMsg&#40;'Waking GoPro'&#41;
sendAt&#40;'AT+CIPSTART="UDP","10.5.5.9",9'&#41;
sleep&#40;500&#41;
sendAt&#40;'AT+CIPSEND=' ..toInt&#40;#magicPacket&#41;&#41;
sleep&#40;100&#41;
sendRaw&#40;magicPacket&#41;
sleep&#40;100&#41; 
sendAt&#40;"AT+CIPCLOSE"&#41;
sleep&#40;2000&#41;
end

function onTick&#40;&#41;
 if wifiStatus == 0 then
    initWiFi&#40;&#41;
    end
 processIncoming&#40;&#41; 
 if  count == 200 then
    wakeGoPro&#40;&#41;
    end
count = count +1


 end

setTickRate&#40;tickRate&#41;
[/code]

Post Reply