Page 2 of 2

Posted: Tue Jul 18, 2017 6:12 am
by brentp
This is great, thanks! Hopefully this can be woven into the support built into the firmware - penciled in for 2.13.0.

Posted: Sat Feb 24, 2018 4:31 pm
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(msg)
  println('[GoProWiFi] ' ..msg)
end

function sendCrlf()
  writeCSer(port, 13)
  writeCSer(port, 10)
end

function sendRaw(val)
  for i=1, #val do
    local c = string.sub(val, i, i)
    writeCSer(port, string.byte(c))
  end
end

function sendAt(val)
  if debug == 1 then logMsg('send: ' ..val) end
  sendRaw(val)
  sendCrlf()
end

function toInt(val)
  return string.sub(val, 1, -3)
end

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



function sendGoProShutter(cmd)
  httpGet('/bacpac/SH?t=' ..goproPwd ..'&p=%' ..cmd)
end

function startGoPro()
  logMsg('start GoPro')
  sendGoProShutter('01')    
end

function stopGoPro()
  logMsg('stop GoPro')
  sendGoProShutter('00')    
end
 

recording = 0

function initWiFi()
  logMsg('initializing')
  sendAt('AT+RST')
  sleep(2000)
  sendAt('AT+CWMODE_CUR=1')
  sleep(1000)
  sendAt('AT+CWJAP_CUR="' ..goproSsid ..'","' ..goproPwd ..'"')
  wifiStatus = 1
end

function processIncoming()
  local line = readSer(port, 100)
  if line ~= '' and debug == 1 then print('incoming response: ' ..line) end
  if string.match(line, 'WIFI GOT IP') then 
    wifiStatus = 2
  end
  if wifiStatus == 2 and string.match(line, 'OK') then
    wifiStatus = 3
    logMsg('ready for GoPro')
  end
end

function checkGoPro()
  if wifiStatus == 0 then
    initWiFi()
    lastInitTime = getUptime()
    return
  end
  if wifiStatus == 1 and getUptime() > lastInitTime + initTimeout then
    logMsg('could not connect to GoPro')
 

  end
  processIncoming()
  if wifiStatus ~= 3 then
    return
  end
  trigger = getAnalog(1)

  if recording == 0 and trigger > goproStart then
    startGoPro()
    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]