<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.autosportlabs.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=GTIspirit</id>
	<title>Autosport Labs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.autosportlabs.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=GTIspirit"/>
	<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/Special:Contributions/GTIspirit"/>
	<updated>2026-09-20T13:43:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=RaceCapture_on_Raspberry_Pi&amp;diff=9500</id>
		<title>RaceCapture on Raspberry Pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=RaceCapture_on_Raspberry_Pi&amp;diff=9500"/>
		<updated>2022-11-11T22:25:26Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Additional Tips */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
&lt;br /&gt;
We designed the RaceCapture app to run nearly anywhere - even a Raspberry Pi. And now, for about $100 you can create a hardwired, dedicated dash for your RaceCapture system. &lt;br /&gt;
&lt;br /&gt;
[[image:racecapture_raspberry_pi.jpg|1024px]]&lt;br /&gt;
&lt;br /&gt;
==Benefits==&lt;br /&gt;
You get all of the benefits of a dedicated dash:&lt;br /&gt;
* &#039;&#039;&#039;Automatically runs upon power up&#039;&#039;&#039; - you can configure the dash to automatically launch the RaceCapture App - just as you&#039;d expect it to work.&lt;br /&gt;
* &#039;&#039;&#039;Hard-wired data connection to RaceCapture&#039;&#039;&#039; - no wireless connections to configure, with the reliability of a direct wire.&lt;br /&gt;
* &#039;&#039;&#039;Runs on the bare metal&#039;&#039;&#039; - The RaceCapture app runs without Android or iOS; there&#039;s no other apps competing for resources, or compromising system stability. &lt;br /&gt;
* &#039;&#039;&#039;Overheating resistance&#039;&#039;&#039; -  Your typical mobile device requires extra care in very hot weather to prevent damage to it&#039;s internal battery, and will shut down if overheated. With proper heat-sinking, the Raspberry Pi should handle the heat.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
The RaceCapture app running on the Raspberry Pi is compatible with any hardware version of RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
[[image:racecapture_raspberry_pi_backside.jpg|1024px]]&lt;br /&gt;
&lt;br /&gt;
==Experimental!==&lt;br /&gt;
While the results are pretty great, these instructions are &#039;&#039;currently&#039;&#039; for those adventurous race car hackers who know their away around a command line, comfortable working with hardware and want to dig in.  &#039;&#039;&#039;Think it&#039;s cool, but too much to tackle?&#039;&#039;&#039; Rope in your nearest computer/electronics geek - you need one on your race team, anyway. :)  &#039;&#039;&#039;Or, just use the plug and play option&#039;&#039;&#039; and use an Android or iOS device via Bluetooth or WiFi.&lt;br /&gt;
&lt;br /&gt;
==Current status and future plans==&lt;br /&gt;
Even though this is brand new and officially experimental in nature, we still made it as easy as reasonably possible: we wrapped up the RaceCapture App into as close to a self-running installer, that can run on a bone stock Raspberry Pi image - only a few changes are required to the default image, detailed below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;However&#039;&#039;&#039;, in the near future we will create a dedicated Raspberry Pi image that you can burn to an SD card and simply boot up, and move towards more official support as we iron out the issues. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Reporting issues and getting support===&lt;br /&gt;
Chances are you&#039;ll encounter an issue you&#039;ll want to report. Before you do that, [https://github.com/autosportlabs/RaceCapture_App/issues?q=is%3Aopen+is%3Aissue+label%3A%22raspberry+pi%22 check the issue log] to see if it&#039;s already known.&lt;br /&gt;
&lt;br /&gt;
Otherwise - the best place for support, feedback and sharing success stories is [http://forum.autosportlabs.com on the  forums] .  Drop us a note there so we can see the progress of your project!&lt;br /&gt;
&lt;br /&gt;
=Hardware Selection=&lt;br /&gt;
===Raspberry Pi===&lt;br /&gt;
We recommend the Raspberry Pi 4 2GB and higher for best performance and support.&lt;br /&gt;
&lt;br /&gt;
===Display===&lt;br /&gt;
The RaceCapture app package is designed to recognize the following screens:&lt;br /&gt;
&lt;br /&gt;
* [https://www.raspberrypi.org/products/raspberry-pi-touch-display/ Official Raspberry Pi display] with capacitive touch screen;&lt;br /&gt;
* Displays supporting the AR1100 resistive touch screen controller.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other displays can work as well, and additional work may be needed to support the screen&#039;s touch controller. If unsure, just pick the [https://www.raspberrypi.org/products/raspberry-pi-touch-display/ Official Raspberry Pi display]&lt;br /&gt;
===Enclosure===&lt;br /&gt;
A recommended enclosure is the [http://https://www.amazon.com/dp/B01HV97F64 Smart Pi Touch Case]&lt;br /&gt;
&lt;br /&gt;
You can 3D print a sun shade for this enclosure  [[file:P001 Raspberry Pi Display Sun Shade.stl.zip|download the .stl file]] (&#039;&#039;Courtesy of Michael Lee&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
[[image:SmartPi_touch_case.jpg|400px]] [[image:RaceCapture_Sun_shade_3dprinted_preview.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_RaspberryPi_sun_shade_dashboard.jpg|800px]]&lt;br /&gt;
&lt;br /&gt;
Installed on Dashboard&lt;br /&gt;
&lt;br /&gt;
===Power Supply===&lt;br /&gt;
The Raspberry Pi dashboard requires its own power supply.  You&#039;ll need a high quality 5v power supply with 2 amps minimum capacity; 3 amps is highly recommended, and ideally one with a low drop out voltage, so power is not cut to the Raspberry Pi when you&#039;re loading the main battery, such as when cranking the engine.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Suggested Power Supplies&#039;&#039;&#039;&lt;br /&gt;
* [https://www.amazon.com/Jabinco-LM2596-Converter-3-0-40V-1-5-35V/dp/B0817P8BGB/ Buck Converter based on the LM2596]&lt;br /&gt;
&lt;br /&gt;
====Powering RaceCapture====&lt;br /&gt;
After you have power to the Raspberry Pi dashboard, you may notice your RaceCapture device will be powered by the USB cable connected to the Pi, just as if you&#039;re powering RaceCapture from your laptop.  &#039;&#039;&#039;You will still want to power your RaceCapture via 12v&#039;&#039;&#039;; see the respective installation guides for information on how to power your device.&lt;br /&gt;
&lt;br /&gt;
===Heat sinking===&lt;br /&gt;
If you&#039;re running in hot weather, we recommend the standard Raspberry Pi heatsink kit to keep your system cool.&lt;br /&gt;
&lt;br /&gt;
For Pi4 users, we recommend active fan cooling in addition to the heat sink.&lt;br /&gt;
&lt;br /&gt;
=Installation=&lt;br /&gt;
==Installing Rasbian OS==&lt;br /&gt;
At the moment we recommend Buster Lite - problems have been reported with later versions. &lt;br /&gt;
&lt;br /&gt;
Download from [https://www.raspberrypi.org/downloads/raspbian/ download from the official site] and follow the instructions for burning to an SD card. &lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve created your image, boot up your Raspberry Pi and log in with the default username of &#039;pi&#039; and password &#039;raspberry&#039;.&lt;br /&gt;
&lt;br /&gt;
===Updating to latest packages===&lt;br /&gt;
It is always good form to update the latest packages after a fresh install. Enter this at the command line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Raspberry Pi support==&lt;br /&gt;
The RaceCapture app is compatible with Raspberry Pi 4 and 3.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable GPU driver===&lt;br /&gt;
Enable Fake KMS under advanced boot options:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo raspi-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to Advanced Options -&amp;gt; GL Driver -&amp;gt; Select OpenGL desktop driver with fake KMS&lt;br /&gt;
&lt;br /&gt;
* Be sure to reboot after exiting raspi-config&lt;br /&gt;
&lt;br /&gt;
==Installing dependencies==&lt;br /&gt;
===Activate ssh===&lt;br /&gt;
Ssh is used to store passwords used by the app. Steps to ensure it is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo raspi-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Go under Interfacing Options or Advanced Options and start the ssh service. &lt;br /&gt;
&lt;br /&gt;
Next, at the command prompt enter&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh-add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to create at least one key.&lt;br /&gt;
&lt;br /&gt;
===Install package dependencies===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install mesa-utils libgles2 libegl1-mesa libegl-mesa0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Change the default password===&lt;br /&gt;
For maximum security, change the password for the default user &#039;pi&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; passwd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and specify a new, secure password.&lt;br /&gt;
&lt;br /&gt;
===Configure Raspberry Pi base settings===&lt;br /&gt;
====Enable Hardware rendering====&lt;br /&gt;
Enter the following line to enable hardware accelerated rendering.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo adduser pi render&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Notes&#039;&#039;&#039;:&lt;br /&gt;
** Without this setting, UI rendering will be extremely slow.&lt;br /&gt;
** Assumes RaceCapture is launched as pi. If not, replace pi with the user you are logging in as.&lt;br /&gt;
** If you&#039;re coming in to fix this after the fact, you&#039;ll need to reboot/re-login to take effect.&lt;br /&gt;
&lt;br /&gt;
====Enable WiFi====&lt;br /&gt;
If you want network capability in addition to the ethernet connection, [https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md enable and configure WiFi per the official documentation]&lt;br /&gt;
&lt;br /&gt;
====(Optional) Enable SSH====&lt;br /&gt;
You can optionally enable SSH for remote management from the comfort of your main computer&#039;s keyboard and screen. &lt;br /&gt;
&lt;br /&gt;
[https://www.raspberrypi.org/documentation/remote-access/ssh/ Enable and configure ssh per the official documentation]&lt;br /&gt;
&lt;br /&gt;
====Install multi-touch tools====&lt;br /&gt;
Install the packages that enable multi-touch interfaces.  Enter the following at the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo apt-get install mtdev-tools&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Configure memory split====&lt;br /&gt;
You&#039;ll need to bump up the memory made available to the GPU. Increase the default value of 64 to &#039;&#039;&#039;256&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Via raspi-config tool&#039;&#039;&#039;&lt;br /&gt;
You can adjust the memory split by running the raspi-config tool. See the [https://www.raspberrypi.org/documentation/configuration/raspi-config.md official documentation]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing /boot/config.txt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can adjust the value directly by editing the /boot/config.txt file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo nano /boot/config.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the line containing gpu_mem=64 and change the number to 256&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gpu_mem=256&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Save the file by pressing &#039;&#039;&#039;ctrl-x&#039;&#039;&#039; then  press &#039;&#039;&#039;Y&#039;&#039;&#039;  to confirm.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Installing the RaceCapture app package==&lt;br /&gt;
&lt;br /&gt;
Download the latest [http://podium.live/software RaceCapture app package for Raspberry Pi] and place it in the /opt/ directory of the Raspberry Pi.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Directly downloading to the Raspberry Pi&#039;&#039;&#039;&lt;br /&gt;
You can download it directly by getting the URL of the package by right-clicking the download link and copying the URL to your clipboard. Then, use it in the command below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /opt&lt;br /&gt;
sudo wget &amp;lt;package URL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Extract the package===&lt;br /&gt;
Now extract the downloaded package :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo tar -xjvf &amp;lt;downloaded file&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launch the app===&lt;br /&gt;
Launch the RaceCapture app by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching with Watchdog===&lt;br /&gt;
You can enable an automatic watchdog that re-launches the app in case a crash occurs. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh -w 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note:&#039;&#039;&#039; You can break out of the application by issuing &#039;&#039;&#039;Alt + PrntScn + k&#039;&#039;&#039; to the application. &lt;br /&gt;
&lt;br /&gt;
You can further stop all racecapture processes by issuing the following command (e.g. via ssh)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
killall -9 run_racecapture&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enabling on screen keyboard===&lt;br /&gt;
If you don&#039;t have a wireless keyboard attached via usb, you can enable an on-screen keyboard.&lt;br /&gt;
&lt;br /&gt;
Edit the kivy config.ini file with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo nano ~/.kivy/config.ini&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and update the keyboard_mode line with:&lt;br /&gt;
&lt;br /&gt;
keyboard_mode = multi&lt;br /&gt;
&lt;br /&gt;
==Automatic start upon power up==&lt;br /&gt;
To get the full dedicated dashboard experience, you can enable automatic launch of the RaceCapture app upon power up. &lt;br /&gt;
&lt;br /&gt;
To do this, edit the system&#039;s startup file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo nano /etc/rc.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and add the following line &#039;&#039;&#039;before the exit 0&#039;&#039;&#039; line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/boot_racecapture.sh pi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Save the file by pressing &#039;&#039;&#039;ctrl-x&#039;&#039;&#039; then  press &#039;&#039;&#039;Y&#039;&#039;&#039;  to confirm.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Connecting to your RaceCapture system=&lt;br /&gt;
[[image:racecapture_raspberry_pi_connections.jpg|900px]]&lt;br /&gt;
===Powering up===&lt;br /&gt;
* Connect the power to your display and power up. &lt;br /&gt;
* Connect your RaceCapture/Pro or RaceCapture/Track to the Raspberry Pi using the USB cable.  &lt;br /&gt;
&lt;br /&gt;
* Launch the RaceCapture app by running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have it set to launch automatically, simply let it start upon power-up.&lt;br /&gt;
&lt;br /&gt;
===Connection and usage===&lt;br /&gt;
&lt;br /&gt;
Once the RaceCapture App is running, it will connect automatically over USB.  You can use the app just as you would on Android or iOS.&lt;br /&gt;
&lt;br /&gt;
=Extra Features=&lt;br /&gt;
&lt;br /&gt;
===Hardwire buttons===&lt;br /&gt;
&lt;br /&gt;
The RaceCapture app responds to keyboard commands for certain behaviors. You can use a USB keyboard - or a device that emulates keyboard commands - to control the RaceCapture App.&lt;br /&gt;
&lt;br /&gt;
Currently there are keyboard commands for the following:&lt;br /&gt;
* &#039;&#039;&#039;Navigating dashboard screens&#039;&#039;&#039;  - Use the left and right arrow keys to switch between screens&lt;br /&gt;
* &#039;&#039;&#039;Escaping from screens / menus&#039;&#039;&#039; - The Escape key can be used to exit out of screens and options, just like the &#039;back&#039; button on Android.&lt;br /&gt;
* &#039;&#039;&#039;Acknowledging alerts&#039;&#039;&#039; - Use the following keys to acknowledge alerts, including responding to pit-to-car alerts:&lt;br /&gt;
** K : to indicate &#039;Yes&#039; or &#039;OK&#039;&lt;br /&gt;
** N : to indicate &#039;No&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Additional Tips=&lt;br /&gt;
See this link for additional tips on how to setup the Pi and speed up the boot times.  This should be especially helpful for beginners.&lt;br /&gt;
&lt;br /&gt;
https://wiki.autosportlabs.com/Raspberry_Pi_Tips&lt;br /&gt;
&lt;br /&gt;
Logfiles for troubleshooting can be found at&lt;br /&gt;
&lt;br /&gt;
/home/pi&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=RaceCapture_on_Raspberry_Pi&amp;diff=9198</id>
		<title>RaceCapture on Raspberry Pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=RaceCapture_on_Raspberry_Pi&amp;diff=9198"/>
		<updated>2021-12-21T22:54:16Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Enabling on screen keyboard */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
&lt;br /&gt;
We designed the RaceCapture app to run nearly anywhere - even a Raspberry Pi. And now, for about $100 you can create a hardwired, dedicated dash for your RaceCapture system. &lt;br /&gt;
&lt;br /&gt;
[[image:racecapture_raspberry_pi.jpg|1024px]]&lt;br /&gt;
&lt;br /&gt;
==Benefits==&lt;br /&gt;
You get all of the benefits of a dedicated dash:&lt;br /&gt;
* &#039;&#039;&#039;Automatically runs upon power up&#039;&#039;&#039; - you can configure the dash to automatically launch the RaceCapture App - just as you&#039;d expect it to work.&lt;br /&gt;
* &#039;&#039;&#039;Hard-wired data connection to RaceCapture&#039;&#039;&#039; - no wireless connections to configure, with the reliability of a direct wire.&lt;br /&gt;
* &#039;&#039;&#039;Runs on the bare metal&#039;&#039;&#039; - The RaceCapture app runs without Android or iOS; there&#039;s no other apps competing for resources, or compromising system stability. &lt;br /&gt;
* &#039;&#039;&#039;Overheating resistance&#039;&#039;&#039; -  Your typical mobile device requires extra care in very hot weather to prevent damage to it&#039;s internal battery, and will shut down if overheated. With proper heat-sinking, the Raspberry Pi should handle the heat.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
The RaceCapture app running on the Raspberry Pi is compatible with any hardware version of RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
[[image:racecapture_raspberry_pi_backside.jpg|1024px]]&lt;br /&gt;
&lt;br /&gt;
==Experimental!==&lt;br /&gt;
While the results are pretty great, these instructions are &#039;&#039;currently&#039;&#039; for those adventurous race car hackers who know their away around a command line, comfortable working with hardware and want to dig in.  &#039;&#039;&#039;Think it&#039;s cool, but too much to tackle?&#039;&#039;&#039; Rope in your nearest computer/electronics geek - you need one on your race team, anyway. :)  &#039;&#039;&#039;Or, just use the plug and play option&#039;&#039;&#039; and use an Android or iOS device via Bluetooth or WiFi.&lt;br /&gt;
&lt;br /&gt;
==Current status and future plans==&lt;br /&gt;
Even though this is brand new and officially experimental in nature, we still made it as easy as reasonably possible: we wrapped up the RaceCapture App into as close to a self-running installer, that can run on a bone stock Raspberry Pi image - only a few changes are required to the default image, detailed below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;However&#039;&#039;&#039;, in the near future we will create a dedicated Raspberry Pi image that you can burn to an SD card and simply boot up, and move towards more official support as we iron out the issues. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Reporting issues and getting support===&lt;br /&gt;
Chances are you&#039;ll encounter an issue you&#039;ll want to report. Before you do that, [https://github.com/autosportlabs/RaceCapture_App/issues?q=is%3Aopen+is%3Aissue+label%3A%22raspberry+pi%22 check the issue log] to see if it&#039;s already known.&lt;br /&gt;
&lt;br /&gt;
Otherwise - the best place for support, feedback and sharing success stories is [http://forum.autosportlabs.com on the  forums] .  Drop us a note there so we can see the progress of your project!&lt;br /&gt;
&lt;br /&gt;
=Hardware Selection=&lt;br /&gt;
===Raspberry Pi===&lt;br /&gt;
RaceCapture currently requires the Raspberry Pi 3: [https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ Raspberry Pi 3].&lt;br /&gt;
&lt;br /&gt;
It is not yet compatible with the Pi 4, due to extensive changes in the graphics subsystem.  Expect to see Pi 4 support in the 2.0 version of the app. &lt;br /&gt;
&lt;br /&gt;
===Display===&lt;br /&gt;
The RaceCapture app package is designed to recognize the following screens:&lt;br /&gt;
&lt;br /&gt;
* [https://www.raspberrypi.org/products/raspberry-pi-touch-display/ Official Raspberry Pi display] with capacitive touch screen;&lt;br /&gt;
* Displays supporting the AR1100 resistive touch screen controller.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other displays can work as well, and additional work may be needed to support the screen&#039;s touch controller. If unsure, just pick the [https://www.raspberrypi.org/products/raspberry-pi-touch-display/ Official Raspberry Pi display]&lt;br /&gt;
===Enclosure===&lt;br /&gt;
A recommended enclosure is the [http://https://www.amazon.com/dp/B01HV97F64 Smart Pi Touch Case]&lt;br /&gt;
&lt;br /&gt;
You can 3D print a sun shade for this enclosure  [[file:P001 Raspberry Pi Display Sun Shade.stl.zip|download the .stl file]] (&#039;&#039;Courtesy of Michael Lee&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
[[image:SmartPi_touch_case.jpg|400px]] [[image:RaceCapture_Sun_shade_3dprinted_preview.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_RaspberryPi_sun_shade_dashboard.jpg|800px]]&lt;br /&gt;
&lt;br /&gt;
Installed on Dashboard&lt;br /&gt;
&lt;br /&gt;
===Power Supply===&lt;br /&gt;
The Raspberry Pi dashboard requires its own power supply.  You&#039;ll need a high quality 5v power supply with 2 amps minimum capacity; 3 amps is highly recommended, and ideally one with a low drop out voltage, so power is not cut to the Raspberry Pi when you&#039;re loading the main battery, such as when cranking the engine.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Suggested Power Supplies&#039;&#039;&#039;&lt;br /&gt;
* [https://www.amazon.com/Jabinco-LM2596-Converter-3-0-40V-1-5-35V/dp/B0817P8BGB/ Buck Converter based on the LM2596]&lt;br /&gt;
&lt;br /&gt;
====Powering RaceCapture====&lt;br /&gt;
After you have power to the Raspberry Pi dashboard, you may notice your RaceCapture device will be powered by the USB cable connected to the Pi, just as if you&#039;re powering RaceCapture from your laptop.  &#039;&#039;&#039;You will still want to power your RaceCapture via 12v&#039;&#039;&#039;; see the respective installation guides for information on how to power your device.&lt;br /&gt;
&lt;br /&gt;
===Heat sinking===&lt;br /&gt;
If you&#039;re running in hot weather, we recommend the standard Raspberry Pi heatsink kit to keep your system cool.&lt;br /&gt;
&lt;br /&gt;
For Pi4 users, we recommend active fan cooling in addition to the heat sink.&lt;br /&gt;
&lt;br /&gt;
=Installation=&lt;br /&gt;
==Installing Rasbian OS==&lt;br /&gt;
We recommend installing the latest Lite distribution - [https://www.raspberrypi.org/downloads/raspbian/ download from the official site] and follow the instructions for burning to an SD card. &lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve created your image, boot up your Raspberry Pi and log in with the default username of &#039;pi&#039; and password &#039;raspberry&#039;.&lt;br /&gt;
&lt;br /&gt;
===Updating to latest packages===&lt;br /&gt;
It is always good form to update the latest packages after a fresh install. Enter this at the command line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Raspberry Pi support==&lt;br /&gt;
The RaceCapture app is compatible with Raspberry Pi 4 and 3.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable GPU driver===&lt;br /&gt;
Enable Fake KMS under advanced boot options:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo raspi-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to Advanced Options -&amp;gt; GL Driver -&amp;gt; Select OpenGL desktop driver with fake KMS&lt;br /&gt;
&lt;br /&gt;
* Be sure to reboot after exiting raspi-config&lt;br /&gt;
&lt;br /&gt;
==Installing dependencies==&lt;br /&gt;
===Activate ssh===&lt;br /&gt;
Ssh is used to store passwords used by the app. Steps to ensure it is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo raspi-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Go under Interfacing Options or Advanced Options and start the ssh service. &lt;br /&gt;
&lt;br /&gt;
Next, at the command prompt enter&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh-add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to create at least one key.&lt;br /&gt;
&lt;br /&gt;
===Install package dependencies===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install mesa-utils libgles2 libegl1-mesa libegl-mesa0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Change the default password===&lt;br /&gt;
For maximum security, change the password for the default user &#039;pi&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; passwd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and specify a new, secure password.&lt;br /&gt;
&lt;br /&gt;
===Configure Raspberry Pi base settings===&lt;br /&gt;
====Enable Hardware rendering====&lt;br /&gt;
Enter the following line to enable hardware accelerated rendering.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo adduser pi render&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Notes&#039;&#039;&#039;:&lt;br /&gt;
** Without this setting, UI rendering will be extremely slow.&lt;br /&gt;
** Assumes RaceCapture is launched as pi. If not, replace pi with the user you are logging in as.&lt;br /&gt;
** If you&#039;re coming in to fix this after the fact, you&#039;ll need to reboot/re-login to take effect.&lt;br /&gt;
&lt;br /&gt;
====Enable WiFi====&lt;br /&gt;
If you want network capability in addition to the ethernet connection, [https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md enable and configure WiFi per the official documentation]&lt;br /&gt;
&lt;br /&gt;
====(Optional) Enable SSH====&lt;br /&gt;
You can optionally enable SSH for remote management from the comfort of your main computer&#039;s keyboard and screen. &lt;br /&gt;
&lt;br /&gt;
[https://www.raspberrypi.org/documentation/remote-access/ssh/ Enable and configure ssh per the official documentation]&lt;br /&gt;
&lt;br /&gt;
====Install multi-touch tools====&lt;br /&gt;
Install the packages that enable multi-touch interfaces.  Enter the following at the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo apt-get install mtdev-tools&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Configure memory split====&lt;br /&gt;
You&#039;ll need to bump up the memory made available to the GPU. Increase the default value of 64 to &#039;&#039;&#039;256&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Via raspi-config tool&#039;&#039;&#039;&lt;br /&gt;
You can adjust the memory split by running the raspi-config tool. See the [https://www.raspberrypi.org/documentation/configuration/raspi-config.md official documentation]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing /boot/config.txt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can adjust the value directly by editing the /boot/config.txt file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo nano /boot/config.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the line containing gpu_mem=64 and change the number to 256&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gpu_mem=256&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Save the file by pressing &#039;&#039;&#039;ctrl-x&#039;&#039;&#039; then  press &#039;&#039;&#039;Y&#039;&#039;&#039;  to confirm.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Installing the RaceCapture app package==&lt;br /&gt;
&lt;br /&gt;
Download the latest [http://podium.live/software RaceCapture app package for Raspberry Pi] and place it in the /opt/ directory of the Raspberry Pi.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Directly downloading to the Raspberry Pi&#039;&#039;&#039;&lt;br /&gt;
You can download it directly by getting the URL of the package by right-clicking the download link and copying the URL to your clipboard. Then, use it in the command below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /opt&lt;br /&gt;
sudo wget &amp;lt;package URL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Extract the package===&lt;br /&gt;
Now extract the downloaded package :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo tar -xjvf &amp;lt;downloaded file&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launch the app===&lt;br /&gt;
Launch the RaceCapture app by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching with Watchdog===&lt;br /&gt;
You can enable an automatic watchdog that re-launches the app in case a crash occurs. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh -w 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note:&#039;&#039;&#039; You can break out of the application by issuing &#039;&#039;&#039;Alt + PrntScn + k&#039;&#039;&#039; to the application. &lt;br /&gt;
&lt;br /&gt;
You can further stop all racecapture processes by issuing the following command (e.g. via ssh)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
killall -9 run_racecapture&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enabling on screen keyboard===&lt;br /&gt;
If you don&#039;t have a wireless keyboard attached via usb, you can enable an on-screen keyboard.&lt;br /&gt;
&lt;br /&gt;
Edit the kivy config.ini file with:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo nano ~/.kivy/config.ini&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and update the keyboard_mode line with:&lt;br /&gt;
&lt;br /&gt;
keyboard_mode = multi&lt;br /&gt;
&lt;br /&gt;
==Automatic start upon power up==&lt;br /&gt;
To get the full dedicated dashboard experience, you can enable automatic launch of the RaceCapture app upon power up. &lt;br /&gt;
&lt;br /&gt;
To do this, edit the system&#039;s startup file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo nano /etc/rc.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and add the following line &#039;&#039;&#039;before the exit 0&#039;&#039;&#039; line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/boot_racecapture.sh pi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Save the file by pressing &#039;&#039;&#039;ctrl-x&#039;&#039;&#039; then  press &#039;&#039;&#039;Y&#039;&#039;&#039;  to confirm.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Connecting to your RaceCapture system=&lt;br /&gt;
[[image:racecapture_raspberry_pi_connections.jpg|900px]]&lt;br /&gt;
===Powering up===&lt;br /&gt;
* Connect the power to your display and power up. &lt;br /&gt;
* Connect your RaceCapture/Pro or RaceCapture/Track to the Raspberry Pi using the USB cable.  &lt;br /&gt;
&lt;br /&gt;
* Launch the RaceCapture app by running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have it set to launch automatically, simply let it start upon power-up.&lt;br /&gt;
&lt;br /&gt;
===Connection and usage===&lt;br /&gt;
&lt;br /&gt;
Once the RaceCapture App is running, it will connect automatically over USB.  You can use the app just as you would on Android or iOS.&lt;br /&gt;
&lt;br /&gt;
=Extra Features=&lt;br /&gt;
&lt;br /&gt;
===Hardwire buttons===&lt;br /&gt;
&lt;br /&gt;
The RaceCapture app responds to keyboard commands for certain behaviors. You can use a USB keyboard - or a device that emulates keyboard commands - to control the RaceCapture App.&lt;br /&gt;
&lt;br /&gt;
Currently there are keyboard commands for the following:&lt;br /&gt;
* &#039;&#039;&#039;Navigating dashboard screens&#039;&#039;&#039;  - Use the left and right arrow keys to switch between screens&lt;br /&gt;
* &#039;&#039;&#039;Escaping from screens / menus&#039;&#039;&#039; - The Escape key can be used to exit out of screens and options, just like the &#039;back&#039; button on Android.&lt;br /&gt;
* &#039;&#039;&#039;Acknowledging alerts&#039;&#039;&#039; - Use the following keys to acknowledge alerts, including responding to pit-to-car alerts:&lt;br /&gt;
** K : to indicate &#039;Yes&#039; or &#039;OK&#039;&lt;br /&gt;
** N : to indicate &#039;No&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Additional Tips=&lt;br /&gt;
See this link for additional tips on how to setup the Pi and speed up the boot times.  This should be especially helpful for beginners.&lt;br /&gt;
&lt;br /&gt;
https://wiki.autosportlabs.com/Raspberry_Pi_Tips&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=RaceCapture_on_Raspberry_Pi&amp;diff=9197</id>
		<title>RaceCapture on Raspberry Pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=RaceCapture_on_Raspberry_Pi&amp;diff=9197"/>
		<updated>2021-12-12T19:51:42Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: SSH activation is under 5 Interfacing Options and not Advanced Options on Pi 4 running Buster&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Introduction=&lt;br /&gt;
&lt;br /&gt;
We designed the RaceCapture app to run nearly anywhere - even a Raspberry Pi. And now, for about $100 you can create a hardwired, dedicated dash for your RaceCapture system. &lt;br /&gt;
&lt;br /&gt;
[[image:racecapture_raspberry_pi.jpg|1024px]]&lt;br /&gt;
&lt;br /&gt;
==Benefits==&lt;br /&gt;
You get all of the benefits of a dedicated dash:&lt;br /&gt;
* &#039;&#039;&#039;Automatically runs upon power up&#039;&#039;&#039; - you can configure the dash to automatically launch the RaceCapture App - just as you&#039;d expect it to work.&lt;br /&gt;
* &#039;&#039;&#039;Hard-wired data connection to RaceCapture&#039;&#039;&#039; - no wireless connections to configure, with the reliability of a direct wire.&lt;br /&gt;
* &#039;&#039;&#039;Runs on the bare metal&#039;&#039;&#039; - The RaceCapture app runs without Android or iOS; there&#039;s no other apps competing for resources, or compromising system stability. &lt;br /&gt;
* &#039;&#039;&#039;Overheating resistance&#039;&#039;&#039; -  Your typical mobile device requires extra care in very hot weather to prevent damage to it&#039;s internal battery, and will shut down if overheated. With proper heat-sinking, the Raspberry Pi should handle the heat.&lt;br /&gt;
&lt;br /&gt;
==Compatibility==&lt;br /&gt;
The RaceCapture app running on the Raspberry Pi is compatible with any hardware version of RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
[[image:racecapture_raspberry_pi_backside.jpg|1024px]]&lt;br /&gt;
&lt;br /&gt;
==Experimental!==&lt;br /&gt;
While the results are pretty great, these instructions are &#039;&#039;currently&#039;&#039; for those adventurous race car hackers who know their away around a command line, comfortable working with hardware and want to dig in.  &#039;&#039;&#039;Think it&#039;s cool, but too much to tackle?&#039;&#039;&#039; Rope in your nearest computer/electronics geek - you need one on your race team, anyway. :)  &#039;&#039;&#039;Or, just use the plug and play option&#039;&#039;&#039; and use an Android or iOS device via Bluetooth or WiFi.&lt;br /&gt;
&lt;br /&gt;
==Current status and future plans==&lt;br /&gt;
Even though this is brand new and officially experimental in nature, we still made it as easy as reasonably possible: we wrapped up the RaceCapture App into as close to a self-running installer, that can run on a bone stock Raspberry Pi image - only a few changes are required to the default image, detailed below.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;However&#039;&#039;&#039;, in the near future we will create a dedicated Raspberry Pi image that you can burn to an SD card and simply boot up, and move towards more official support as we iron out the issues. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Reporting issues and getting support===&lt;br /&gt;
Chances are you&#039;ll encounter an issue you&#039;ll want to report. Before you do that, [https://github.com/autosportlabs/RaceCapture_App/issues?q=is%3Aopen+is%3Aissue+label%3A%22raspberry+pi%22 check the issue log] to see if it&#039;s already known.&lt;br /&gt;
&lt;br /&gt;
Otherwise - the best place for support, feedback and sharing success stories is [http://forum.autosportlabs.com on the  forums] .  Drop us a note there so we can see the progress of your project!&lt;br /&gt;
&lt;br /&gt;
=Hardware Selection=&lt;br /&gt;
===Raspberry Pi===&lt;br /&gt;
RaceCapture currently requires the Raspberry Pi 3: [https://www.raspberrypi.org/products/raspberry-pi-3-model-b/ Raspberry Pi 3].&lt;br /&gt;
&lt;br /&gt;
It is not yet compatible with the Pi 4, due to extensive changes in the graphics subsystem.  Expect to see Pi 4 support in the 2.0 version of the app. &lt;br /&gt;
&lt;br /&gt;
===Display===&lt;br /&gt;
The RaceCapture app package is designed to recognize the following screens:&lt;br /&gt;
&lt;br /&gt;
* [https://www.raspberrypi.org/products/raspberry-pi-touch-display/ Official Raspberry Pi display] with capacitive touch screen;&lt;br /&gt;
* Displays supporting the AR1100 resistive touch screen controller.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Other displays can work as well, and additional work may be needed to support the screen&#039;s touch controller. If unsure, just pick the [https://www.raspberrypi.org/products/raspberry-pi-touch-display/ Official Raspberry Pi display]&lt;br /&gt;
===Enclosure===&lt;br /&gt;
A recommended enclosure is the [http://https://www.amazon.com/dp/B01HV97F64 Smart Pi Touch Case]&lt;br /&gt;
&lt;br /&gt;
You can 3D print a sun shade for this enclosure  [[file:P001 Raspberry Pi Display Sun Shade.stl.zip|download the .stl file]] (&#039;&#039;Courtesy of Michael Lee&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
[[image:SmartPi_touch_case.jpg|400px]] [[image:RaceCapture_Sun_shade_3dprinted_preview.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_RaspberryPi_sun_shade_dashboard.jpg|800px]]&lt;br /&gt;
&lt;br /&gt;
Installed on Dashboard&lt;br /&gt;
&lt;br /&gt;
===Power Supply===&lt;br /&gt;
The Raspberry Pi dashboard requires its own power supply.  You&#039;ll need a high quality 5v power supply with 2 amps minimum capacity; 3 amps is highly recommended, and ideally one with a low drop out voltage, so power is not cut to the Raspberry Pi when you&#039;re loading the main battery, such as when cranking the engine.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Suggested Power Supplies&#039;&#039;&#039;&lt;br /&gt;
* [https://www.amazon.com/Jabinco-LM2596-Converter-3-0-40V-1-5-35V/dp/B0817P8BGB/ Buck Converter based on the LM2596]&lt;br /&gt;
&lt;br /&gt;
====Powering RaceCapture====&lt;br /&gt;
After you have power to the Raspberry Pi dashboard, you may notice your RaceCapture device will be powered by the USB cable connected to the Pi, just as if you&#039;re powering RaceCapture from your laptop.  &#039;&#039;&#039;You will still want to power your RaceCapture via 12v&#039;&#039;&#039;; see the respective installation guides for information on how to power your device.&lt;br /&gt;
&lt;br /&gt;
===Heat sinking===&lt;br /&gt;
If you&#039;re running in hot weather, we recommend the standard Raspberry Pi heatsink kit to keep your system cool.&lt;br /&gt;
&lt;br /&gt;
For Pi4 users, we recommend active fan cooling in addition to the heat sink.&lt;br /&gt;
&lt;br /&gt;
=Installation=&lt;br /&gt;
==Installing Rasbian OS==&lt;br /&gt;
We recommend installing the latest Lite distribution - [https://www.raspberrypi.org/downloads/raspbian/ download from the official site] and follow the instructions for burning to an SD card. &lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve created your image, boot up your Raspberry Pi and log in with the default username of &#039;pi&#039; and password &#039;raspberry&#039;.&lt;br /&gt;
&lt;br /&gt;
===Updating to latest packages===&lt;br /&gt;
It is always good form to update the latest packages after a fresh install. Enter this at the command line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get dist-upgrade&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Raspberry Pi support==&lt;br /&gt;
The RaceCapture app is compatible with Raspberry Pi 4 and 3.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Enable GPU driver===&lt;br /&gt;
Enable Fake KMS under advanced boot options:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo raspi-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go to Advanced Options -&amp;gt; GL Driver -&amp;gt; Select OpenGL desktop driver with fake KMS&lt;br /&gt;
&lt;br /&gt;
* Be sure to reboot after exiting raspi-config&lt;br /&gt;
&lt;br /&gt;
==Installing dependencies==&lt;br /&gt;
===Activate ssh===&lt;br /&gt;
Ssh is used to store passwords used by the app. Steps to ensure it is running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo raspi-config&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Go under Interfacing Options or Advanced Options and start the ssh service. &lt;br /&gt;
&lt;br /&gt;
Next, at the command prompt enter&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ssh-add&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
to create at least one key.&lt;br /&gt;
&lt;br /&gt;
===Install package dependencies===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install mesa-utils libgles2 libegl1-mesa libegl-mesa0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Change the default password===&lt;br /&gt;
For maximum security, change the password for the default user &#039;pi&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; passwd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and specify a new, secure password.&lt;br /&gt;
&lt;br /&gt;
===Configure Raspberry Pi base settings===&lt;br /&gt;
====Enable Hardware rendering====&lt;br /&gt;
Enter the following line to enable hardware accelerated rendering.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo adduser pi render&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Notes&#039;&#039;&#039;:&lt;br /&gt;
** Without this setting, UI rendering will be extremely slow.&lt;br /&gt;
** Assumes RaceCapture is launched as pi. If not, replace pi with the user you are logging in as.&lt;br /&gt;
** If you&#039;re coming in to fix this after the fact, you&#039;ll need to reboot/re-login to take effect.&lt;br /&gt;
&lt;br /&gt;
====Enable WiFi====&lt;br /&gt;
If you want network capability in addition to the ethernet connection, [https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md enable and configure WiFi per the official documentation]&lt;br /&gt;
&lt;br /&gt;
====(Optional) Enable SSH====&lt;br /&gt;
You can optionally enable SSH for remote management from the comfort of your main computer&#039;s keyboard and screen. &lt;br /&gt;
&lt;br /&gt;
[https://www.raspberrypi.org/documentation/remote-access/ssh/ Enable and configure ssh per the official documentation]&lt;br /&gt;
&lt;br /&gt;
====Install multi-touch tools====&lt;br /&gt;
Install the packages that enable multi-touch interfaces.  Enter the following at the command line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo apt-get install mtdev-tools&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Configure memory split====&lt;br /&gt;
You&#039;ll need to bump up the memory made available to the GPU. Increase the default value of 64 to &#039;&#039;&#039;256&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Via raspi-config tool&#039;&#039;&#039;&lt;br /&gt;
You can adjust the memory split by running the raspi-config tool. See the [https://www.raspberrypi.org/documentation/configuration/raspi-config.md official documentation]&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Editing /boot/config.txt&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can adjust the value directly by editing the /boot/config.txt file. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; sudo nano /boot/config.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find the line containing gpu_mem=64 and change the number to 256&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gpu_mem=256&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Save the file by pressing &#039;&#039;&#039;ctrl-x&#039;&#039;&#039; then  press &#039;&#039;&#039;Y&#039;&#039;&#039;  to confirm.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Installing the RaceCapture app package==&lt;br /&gt;
&lt;br /&gt;
Download the latest [http://podium.live/software RaceCapture app package for Raspberry Pi] and place it in the /opt/ directory of the Raspberry Pi.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Directly downloading to the Raspberry Pi&#039;&#039;&#039;&lt;br /&gt;
You can download it directly by getting the URL of the package by right-clicking the download link and copying the URL to your clipboard. Then, use it in the command below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd /opt&lt;br /&gt;
sudo wget &amp;lt;package URL&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Extract the package===&lt;br /&gt;
Now extract the downloaded package :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo tar -xjvf &amp;lt;downloaded file&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launch the app===&lt;br /&gt;
Launch the RaceCapture app by running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Launching with Watchdog===&lt;br /&gt;
You can enable an automatic watchdog that re-launches the app in case a crash occurs. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh -w 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Note:&#039;&#039;&#039; You can break out of the application by issuing &#039;&#039;&#039;Alt + PrntScn + k&#039;&#039;&#039; to the application. &lt;br /&gt;
&lt;br /&gt;
You can further stop all racecapture processes by issuing the following command (e.g. via ssh)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
killall -9 run_racecapture&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Enabling on screen keyboard===&lt;br /&gt;
If you don&#039;t have a wireless keyboard attached via usb, you can enable an on-screen keyboard.&lt;br /&gt;
&lt;br /&gt;
Edit the ~/.kivy/config.ini and update the keyboard_mode line with:&lt;br /&gt;
&lt;br /&gt;
```  keyboard_mode = multi```&lt;br /&gt;
&lt;br /&gt;
==Automatic start upon power up==&lt;br /&gt;
To get the full dedicated dashboard experience, you can enable automatic launch of the RaceCapture app upon power up. &lt;br /&gt;
&lt;br /&gt;
To do this, edit the system&#039;s startup file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo nano /etc/rc.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and add the following line &#039;&#039;&#039;before the exit 0&#039;&#039;&#039; line.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/boot_racecapture.sh pi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Save the file by pressing &#039;&#039;&#039;ctrl-x&#039;&#039;&#039; then  press &#039;&#039;&#039;Y&#039;&#039;&#039;  to confirm.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Connecting to your RaceCapture system=&lt;br /&gt;
[[image:racecapture_raspberry_pi_connections.jpg|900px]]&lt;br /&gt;
===Powering up===&lt;br /&gt;
* Connect the power to your display and power up. &lt;br /&gt;
* Connect your RaceCapture/Pro or RaceCapture/Track to the Raspberry Pi using the USB cable.  &lt;br /&gt;
&lt;br /&gt;
* Launch the RaceCapture app by running:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/racecapture/run_racecapture.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have it set to launch automatically, simply let it start upon power-up.&lt;br /&gt;
&lt;br /&gt;
===Connection and usage===&lt;br /&gt;
&lt;br /&gt;
Once the RaceCapture App is running, it will connect automatically over USB.  You can use the app just as you would on Android or iOS.&lt;br /&gt;
&lt;br /&gt;
=Extra Features=&lt;br /&gt;
&lt;br /&gt;
===Hardwire buttons===&lt;br /&gt;
&lt;br /&gt;
The RaceCapture app responds to keyboard commands for certain behaviors. You can use a USB keyboard - or a device that emulates keyboard commands - to control the RaceCapture App.&lt;br /&gt;
&lt;br /&gt;
Currently there are keyboard commands for the following:&lt;br /&gt;
* &#039;&#039;&#039;Navigating dashboard screens&#039;&#039;&#039;  - Use the left and right arrow keys to switch between screens&lt;br /&gt;
* &#039;&#039;&#039;Escaping from screens / menus&#039;&#039;&#039; - The Escape key can be used to exit out of screens and options, just like the &#039;back&#039; button on Android.&lt;br /&gt;
* &#039;&#039;&#039;Acknowledging alerts&#039;&#039;&#039; - Use the following keys to acknowledge alerts, including responding to pit-to-car alerts:&lt;br /&gt;
** K : to indicate &#039;Yes&#039; or &#039;OK&#039;&lt;br /&gt;
** N : to indicate &#039;No&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Additional Tips=&lt;br /&gt;
See this link for additional tips on how to setup the Pi and speed up the boot times.  This should be especially helpful for beginners.&lt;br /&gt;
&lt;br /&gt;
https://wiki.autosportlabs.com/Raspberry_Pi_Tips&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8681</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8681"/>
		<updated>2020-05-17T19:02:33Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Lua Script for Garmin Virb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for GoPro=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for Garmin Virb=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your Garmin Virb camera using the Garmin [https://developer.garmin.com/downloads/virb/Camera_Network_Services_API_v0.5.pdf Camera Network Services API].   Not all commands in the API may work.  Use commandList (via [https://www.postman.com/ Postman]) to determine which API commands are supported by your Garmin Virb camera.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;The Garmin Virb always uses 192.168.0.1 HTTP port ( 80 ).&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: this Lua script is different than the GoPro script above in that Garmin uses POST commands instead of GET commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;For a more detailed explanation, see&#039;&#039; [https://forum.autosportlabs.com/viewtopic.php?t=6267 How to send HTTP POST request via Lua Script?]&amp;lt;br&amp;gt;&lt;br /&gt;
It may be possible to control other WiFi devices by altering the POST command accordingly.  e.g. instead of sending httpPost arguments {&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;} substitute this with the commands specified by the device API.   Be sure to adjust the server host IP address if different than the Garmin standard.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;Ssid&#039;&#039;&#039;: Specify the WiFi network name (SSID)&lt;br /&gt;
* &#039;&#039;&#039;Pwd&#039;&#039;&#039;: Specify the WiFi password&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;Port&#039;&#039;&#039;: 5 is the WiFi port for the RaceCapture/Track MK2.  Change according to [https://wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting#Port_mappings Port mapping]&lt;br /&gt;
* &#039;&#039;&#039;autoStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;autoStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold.&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
setTickRate(10) --TickRate is in Hz&lt;br /&gt;
--configure WiFi serial port&lt;br /&gt;
port = 5&lt;br /&gt;
initSer(port,115200,8,0,1)&lt;br /&gt;
--Specify client SSID here&lt;br /&gt;
Ssid = &#039;VIRB-4615&#039;&lt;br /&gt;
--Specify client wifi password here&lt;br /&gt;
Pwd = &#039;12345678&#039;&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
&lt;br /&gt;
--initialize variables&lt;br /&gt;
trigger = 0&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
--define constants&lt;br /&gt;
autoStart = 0  --Threshold to start recording&lt;br /&gt;
autoStop = 1  --Threshold to stop recording&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------WiFi Code--------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
reps = 3 --number of times to repeat command&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[WiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpPost(cmd)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;192.168.0.1&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local post = &#039;POST /virb HTTP/1.1\r\nHost: 192.168.0.1\r\nAccept: */*\r\nContent-Length: &#039; ..toInt(#cmd)..&#039;\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n&#039; ..cmd ..&#039;\r\n&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#post))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(post)&lt;br /&gt;
  if debug == 1 then println(post) end&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&#039;AT+CIPCLOSE&#039;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..Ssid ..&#039;&amp;quot;,&amp;quot;&#039; ..Pwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) or string.match(line, &#039;WIFI CONNECTED&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for WiFi&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkWiFi()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to WiFi&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  --trigger = getGpsSpeed()&lt;br /&gt;
  trigger = bit.rshift(bit.band(getChannel(&amp;quot;77AB2&amp;quot;),0x40),6)&lt;br /&gt;
  --trigger = 1&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; autoStart then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; autoStop then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;stopRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkWiFi()&lt;br /&gt;
  --println(&#039;trigger value: &#039; ..trigger)&lt;br /&gt;
  --println(&#039;recording status: &#039; ..recording)&lt;br /&gt;
  if debug ==1 then println(&amp;quot;WiFi Status: &amp;quot; ..wifiStatus) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A few comments:&lt;br /&gt;
* The POST command is repeated the number of times specified by reps.  This is because during testing the startRecording was not entirely reliable.  The camera somehow missed the command.&lt;br /&gt;
* The trigger condition is set to use bit 6 of the CAN channel 77AB2.  This signal comes from a switch on the dashboard wired to an ECU, which then sends switch status on the CAN to which the RaceCapture/Track MK2 is connected.  Modify accordingly if you have a similar switch, otherwise comment this out and uncomment the getGpsSpeed() line, altering the autoStart and autoStop thresholds accordingly.&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8680</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8680"/>
		<updated>2020-05-17T18:58:14Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Lua Script for Garmin Virb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for GoPro=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for Garmin Virb=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your Garmin Virb camera using the Garmin [https://developer.garmin.com/downloads/virb/Camera_Network_Services_API_v0.5.pdf Camera Network Services API]. &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;The Garmin Virb always uses 192.168.0.1 HTTP port ( 80 ).&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: this Lua script is different than the GoPro script above in that Garmin uses POST commands instead of GET commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;For a more detailed explanation, see&#039;&#039; [https://forum.autosportlabs.com/viewtopic.php?t=6267 How to send HTTP POST request via Lua Script?]&amp;lt;br&amp;gt;&lt;br /&gt;
It may be possible to control other WiFi devices by altering the POST command accordingly.  e.g. instead of sending httpPost arguments {&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;} substitute this with the commands specified by the device API.   Be sure to adjust the server host IP address if different than the Garmin standard.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;Ssid&#039;&#039;&#039;: Specify the WiFi network name (SSID)&lt;br /&gt;
* &#039;&#039;&#039;Pwd&#039;&#039;&#039;: Specify the WiFi password&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;Port&#039;&#039;&#039;: 5 is the WiFi port for the RaceCapture/Track MK2.  Change according to [https://wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting#Port_mappings Port mapping]&lt;br /&gt;
* &#039;&#039;&#039;autoStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;autoStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold.&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
setTickRate(10) --TickRate is in Hz&lt;br /&gt;
--configure WiFi serial port&lt;br /&gt;
port = 5&lt;br /&gt;
initSer(port,115200,8,0,1)&lt;br /&gt;
--Specify client SSID here&lt;br /&gt;
Ssid = &#039;VIRB-4615&#039;&lt;br /&gt;
--Specify client wifi password here&lt;br /&gt;
Pwd = &#039;12345678&#039;&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
&lt;br /&gt;
--initialize variables&lt;br /&gt;
trigger = 0&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
--define constants&lt;br /&gt;
autoStart = 0  --Threshold to start recording&lt;br /&gt;
autoStop = 1  --Threshold to stop recording&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------WiFi Code--------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
reps = 3 --number of times to repeat command&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[WiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpPost(cmd)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;192.168.0.1&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local post = &#039;POST /virb HTTP/1.1\r\nHost: 192.168.0.1\r\nAccept: */*\r\nContent-Length: &#039; ..toInt(#cmd)..&#039;\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n&#039; ..cmd ..&#039;\r\n&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#post))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(post)&lt;br /&gt;
  if debug == 1 then println(post) end&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&#039;AT+CIPCLOSE&#039;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..Ssid ..&#039;&amp;quot;,&amp;quot;&#039; ..Pwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) or string.match(line, &#039;WIFI CONNECTED&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for WiFi&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkWiFi()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to WiFi&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  --trigger = getGpsSpeed()&lt;br /&gt;
  trigger = bit.rshift(bit.band(getChannel(&amp;quot;77AB2&amp;quot;),0x40),6)&lt;br /&gt;
  --trigger = 1&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; autoStart then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; autoStop then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;stopRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkWiFi()&lt;br /&gt;
  --println(&#039;trigger value: &#039; ..trigger)&lt;br /&gt;
  --println(&#039;recording status: &#039; ..recording)&lt;br /&gt;
  if debug ==1 then println(&amp;quot;WiFi Status: &amp;quot; ..wifiStatus) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A few comments:&lt;br /&gt;
* The POST command is repeated the number of times specified by reps.  This is because during testing the startRecording was not entirely reliable.  The camera somehow missed the command.&lt;br /&gt;
* The trigger condition is set to use bit 6 of the CAN channel 77AB2.  This signal comes from a switch on the dashboard wired to an ECU, which then sends switch status on the CAN to which the RaceCapture/Track MK2 is connected.  Modify accordingly if you have a similar switch, otherwise comment this out and uncomment the getGpsSpeed() line, altering the autoStart and autoStop thresholds accordingly.&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8679</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8679"/>
		<updated>2020-05-17T18:53:56Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Optional */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for GoPro=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for Garmin Virb=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your Garmin Virb camera using the Garmin [https://developer.garmin.com/downloads/virb/Camera_Network_Services_API_v0.5.pdf Camera Network Services API]. &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: this Lua script is different than the GoPro script above in that Garmin uses POST commands instead of GET commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;For a more detailed explanation, see&#039;&#039; [https://forum.autosportlabs.com/viewtopic.php?t=6267 How to send HTTP POST request via Lua Script?]&amp;lt;br&amp;gt;&lt;br /&gt;
It may be possible to control other WiFi devices by altering the POST command accordingly.  e.g. instead of sending httpPost arguments {&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;} substitute this with the commands specified by the device API. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;Ssid&#039;&#039;&#039;: Specify the WiFi network name (SSID)&lt;br /&gt;
* &#039;&#039;&#039;Pwd&#039;&#039;&#039;: Specify the WiFi password&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;Port&#039;&#039;&#039;: 5 is the WiFi port for the RaceCapture/Track MK2.  Change according to [https://wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting#Port_mappings Port mapping]&lt;br /&gt;
* &#039;&#039;&#039;autoStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;autoStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold.&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
setTickRate(10) --TickRate is in Hz&lt;br /&gt;
--configure WiFi serial port&lt;br /&gt;
port = 5&lt;br /&gt;
initSer(port,115200,8,0,1)&lt;br /&gt;
--Specify client SSID here&lt;br /&gt;
Ssid = &#039;VIRB-4615&#039;&lt;br /&gt;
--Specify client wifi password here&lt;br /&gt;
Pwd = &#039;12345678&#039;&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
&lt;br /&gt;
--initialize variables&lt;br /&gt;
trigger = 0&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
--define constants&lt;br /&gt;
autoStart = 0  --Threshold to start recording&lt;br /&gt;
autoStop = 1  --Threshold to stop recording&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------WiFi Code--------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
reps = 3 --number of times to repeat command&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[WiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpPost(cmd)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;192.168.0.1&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local post = &#039;POST /virb HTTP/1.1\r\nHost: 192.168.0.1\r\nAccept: */*\r\nContent-Length: &#039; ..toInt(#cmd)..&#039;\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n&#039; ..cmd ..&#039;\r\n&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#post))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(post)&lt;br /&gt;
  if debug == 1 then println(post) end&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&#039;AT+CIPCLOSE&#039;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..Ssid ..&#039;&amp;quot;,&amp;quot;&#039; ..Pwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) or string.match(line, &#039;WIFI CONNECTED&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for WiFi&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkWiFi()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to WiFi&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  --trigger = getGpsSpeed()&lt;br /&gt;
  trigger = bit.rshift(bit.band(getChannel(&amp;quot;77AB2&amp;quot;),0x40),6)&lt;br /&gt;
  --trigger = 1&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; autoStart then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; autoStop then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;stopRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkWiFi()&lt;br /&gt;
  --println(&#039;trigger value: &#039; ..trigger)&lt;br /&gt;
  --println(&#039;recording status: &#039; ..recording)&lt;br /&gt;
  if debug ==1 then println(&amp;quot;WiFi Status: &amp;quot; ..wifiStatus) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A few comments:&lt;br /&gt;
* The POST command is repeated the number of times specified by reps.  This is because during testing the startRecording was not entirely reliable.  The camera somehow missed the command.&lt;br /&gt;
* The trigger condition is set to use bit 6 of the CAN channel 77AB2.  This signal comes from a switch on the dashboard wired to an ECU, which then sends switch status on the CAN to which the RaceCapture/Track MK2 is connected.  Modify accordingly if you have a similar switch, otherwise comment this out and uncomment the getGpsSpeed() line, altering the autoStart and autoStop thresholds accordingly.&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8678</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8678"/>
		<updated>2020-05-17T18:48:21Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Lua Script for Garmin Virb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for GoPro=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for Garmin Virb=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your Garmin Virb camera using the Garmin [https://developer.garmin.com/downloads/virb/Camera_Network_Services_API_v0.5.pdf Camera Network Services API]. &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: this Lua script is different than the GoPro script above in that Garmin uses POST commands instead of GET commands.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;For a more detailed explanation, see&#039;&#039; [https://forum.autosportlabs.com/viewtopic.php?t=6267 How to send HTTP POST request via Lua Script?]&amp;lt;br&amp;gt;&lt;br /&gt;
It may be possible to control other WiFi devices by altering the POST command accordingly.  e.g. instead of sending httpPost arguments {&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;} substitute this with the commands specified by the device API. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;Ssid&#039;&#039;&#039;: Specify the WiFi network name (SSID)&lt;br /&gt;
* &#039;&#039;&#039;Pwd&#039;&#039;&#039;: Specify the WiFi password&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;autoStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;autoStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold.&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
setTickRate(10) --TickRate is in Hz&lt;br /&gt;
--configure WiFi serial port&lt;br /&gt;
port = 5&lt;br /&gt;
initSer(port,115200,8,0,1)&lt;br /&gt;
--Specify client SSID here&lt;br /&gt;
Ssid = &#039;VIRB-4615&#039;&lt;br /&gt;
--Specify client wifi password here&lt;br /&gt;
Pwd = &#039;12345678&#039;&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
&lt;br /&gt;
--initialize variables&lt;br /&gt;
trigger = 0&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
--define constants&lt;br /&gt;
autoStart = 0  --Threshold to start recording&lt;br /&gt;
autoStop = 1  --Threshold to stop recording&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------WiFi Code--------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
reps = 3 --number of times to repeat command&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[WiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpPost(cmd)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;192.168.0.1&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local post = &#039;POST /virb HTTP/1.1\r\nHost: 192.168.0.1\r\nAccept: */*\r\nContent-Length: &#039; ..toInt(#cmd)..&#039;\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n&#039; ..cmd ..&#039;\r\n&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#post))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(post)&lt;br /&gt;
  if debug == 1 then println(post) end&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&#039;AT+CIPCLOSE&#039;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..Ssid ..&#039;&amp;quot;,&amp;quot;&#039; ..Pwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) or string.match(line, &#039;WIFI CONNECTED&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for WiFi&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkWiFi()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to WiFi&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  --trigger = getGpsSpeed()&lt;br /&gt;
  trigger = bit.rshift(bit.band(getChannel(&amp;quot;77AB2&amp;quot;),0x40),6)&lt;br /&gt;
  --trigger = 1&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; autoStart then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; autoStop then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;stopRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkWiFi()&lt;br /&gt;
  --println(&#039;trigger value: &#039; ..trigger)&lt;br /&gt;
  --println(&#039;recording status: &#039; ..recording)&lt;br /&gt;
  if debug ==1 then println(&amp;quot;WiFi Status: &amp;quot; ..wifiStatus) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A few comments:&lt;br /&gt;
* The POST command is repeated the number of times specified by reps.  This is because during testing the startRecording was not entirely reliable.  The camera somehow missed the command.&lt;br /&gt;
* The trigger condition is set to use bit 6 of the CAN channel 77AB2.  This signal comes from a switch on the dashboard wired to an ECU, which then sends switch status on the CAN to which the RaceCapture/Track MK2 is connected.  Modify accordingly if you have a similar switch, otherwise comment this out and uncomment the getGpsSpeed() line, altering the autoStart and autoStop thresholds accordingly.&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8677</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8677"/>
		<updated>2020-05-17T18:23:38Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: Initial page for Garmin Virb camera control&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for GoPro=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for Garmin Virb=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your Garmin Virb camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;Ssid&#039;&#039;&#039;: Specify the WiFi network name (SSID)&lt;br /&gt;
* &#039;&#039;&#039;Pwd&#039;&#039;&#039;: Specify the WiFi password&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;autoStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;autoStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
setTickRate(10) --TickRate is in Hz&lt;br /&gt;
--configure WiFi serial port&lt;br /&gt;
port = 5&lt;br /&gt;
initSer(port,115200,8,0,1)&lt;br /&gt;
--Specify client SSID here&lt;br /&gt;
Ssid = &#039;VIRB-4615&#039;&lt;br /&gt;
--Specify client wifi password here&lt;br /&gt;
Pwd = &#039;12345678&#039;&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
&lt;br /&gt;
--initialize variables&lt;br /&gt;
trigger = 0&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
--define constants&lt;br /&gt;
autoStart = 0  --Threshold to start recording&lt;br /&gt;
autoStop = 1  --Threshold to stop recording&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
------WiFi Code--------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
reps = 3 --number of times to repeat command&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[WiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpPost(cmd)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;192.168.0.1&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local post = &#039;POST /virb HTTP/1.1\r\nHost: 192.168.0.1\r\nAccept: */*\r\nContent-Length: &#039; ..toInt(#cmd)..&#039;\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n&#039; ..cmd ..&#039;\r\n&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#post))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(post)&lt;br /&gt;
  if debug == 1 then println(post) end&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&#039;AT+CIPCLOSE&#039;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..Ssid ..&#039;&amp;quot;,&amp;quot;&#039; ..Pwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) or string.match(line, &#039;WIFI CONNECTED&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for WiFi&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkWiFi()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to WiFi&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  --trigger = getGpsSpeed()&lt;br /&gt;
  trigger = bit.rshift(bit.band(getChannel(&amp;quot;77AB2&amp;quot;),0x40),6)&lt;br /&gt;
  --trigger = 1&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; autoStart then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;startRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; autoStop then&lt;br /&gt;
    for i=1,reps,1&lt;br /&gt;
    do&lt;br /&gt;
    httpPost(&#039;{&amp;quot;command&amp;quot;:&amp;quot;stopRecording&amp;quot;}&#039;)&lt;br /&gt;
    end&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkWiFi()&lt;br /&gt;
  println(&#039;trigger value: &#039; ..trigger)&lt;br /&gt;
  println(&#039;recording status: &#039; ..recording)&lt;br /&gt;
  if debug ==1 then println(&amp;quot;WiFi Status: &amp;quot; ..wifiStatus) end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8676</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8676"/>
		<updated>2020-05-17T18:13:23Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Lua Script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script for GoPro=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
	<entry>
		<id>https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8675</id>
		<title>AutomaticCameraControl</title>
		<link rel="alternate" type="text/html" href="https://wiki.autosportlabs.com/index.php?title=AutomaticCameraControl&amp;diff=8675"/>
		<updated>2020-05-17T18:09:09Z</updated>

		<summary type="html">&lt;p&gt;GTIspirit: /* Currently supported cameras */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Automatic Camera Control=&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
This guide shows you how to enable automatic start / stop control of WiFi enabled cameras, such as GoPro using RaceCapture or PodiumConnect. &lt;br /&gt;
&lt;br /&gt;
==How it works==&lt;br /&gt;
Most action cameras offer a WiFi interface for remote control. GoPro is one such camera, and allows shutter control via the WiFi interface, which RaceCapture or PodiumConnect can leverage for automatic triggering. &lt;br /&gt;
&lt;br /&gt;
===Currently supported versions of RaceCapture hardware===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
* RaceCapture/Pro MK2 with external WiFi add-on (see below)&lt;br /&gt;
&lt;br /&gt;
===Currently supported cameras===&lt;br /&gt;
* GoPro Hero 2/3&lt;br /&gt;
* GoPro Hero 4/5 (experimental)&lt;br /&gt;
* Garmin Virb Ultra 30 (experimental)&lt;br /&gt;
&lt;br /&gt;
Note, We recommend GoPro 2/3 due to stability / reliability issues seen with the later GoPro devices. &lt;br /&gt;
&lt;br /&gt;
Additional Camera support will be added with future firmware releases.&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
RaceCapture or PodiumConnect is configured so it&#039;s WiFi client connects to the camera&#039;s access point using its SSID and WiFi password.  &lt;br /&gt;
&lt;br /&gt;
When RaceCapture/PodiumConnect triggers the camera based on a sensor threshold such as speed, RPM or other value, it sends a command to the camera to start recording.  When the sensor falls below the threshold, the corresponding command is sent to stop the recording. &lt;br /&gt;
&lt;br /&gt;
===Simultaneous WiFi connection with the RaceCapture App===&lt;br /&gt;
Since the WiFi client feature is used on RaceCapture/PodiumConnect to connect to the camera, the Access Point remains available for the RaceCapture app to connect via WiFi, as usual. Or, via Bluetooth, if supported by the RaceCapture system.&lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_camera_control.jpg|400px]]&lt;br /&gt;
&lt;br /&gt;
==Setting up Automatic Camera Control==&lt;br /&gt;
&lt;br /&gt;
===Applies to===&lt;br /&gt;
* PodiumConnect&lt;br /&gt;
* RaceCapture/Apex&lt;br /&gt;
* RaceCapture/Pro MK3&lt;br /&gt;
* RaceCapture/Track MK1 and MK2&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* Firmware 2.13.0 or higher&lt;br /&gt;
&lt;br /&gt;
===Set up WiFi client===&lt;br /&gt;
Navigate to Setup / Wireless and ensure:&lt;br /&gt;
* WiFi is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* WiFi client is turned &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
* Camera SSID and password are specified in the WiFi client settings. &lt;br /&gt;
&lt;br /&gt;
[[image:WiFi_camera_control_config.png]]&lt;br /&gt;
&lt;br /&gt;
===Set up Automatic Control===&lt;br /&gt;
Navigate to Setup / Automatic Control and ensure:&lt;br /&gt;
* The desired sensor channel trigger is selected (Speed is the default)&lt;br /&gt;
* Your start / stop and time thresholds are configured&lt;br /&gt;
* Camera Control is turned &#039;&#039;&#039;ON&#039;&#039;&#039; and you have your camera model selected. &lt;br /&gt;
&lt;br /&gt;
[[Image:automatic_control_camera_settings.png]]&lt;br /&gt;
&lt;br /&gt;
===Write Settings===&lt;br /&gt;
Write the settings back to RaceCapture by pressing the &#039;&#039;&#039;Write&#039;&#039;&#039; button under Setup. &lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
Turn on the camera and ensure the camera has it&#039;s WiFi interface enabled. &lt;br /&gt;
&lt;br /&gt;
Power up RaceCapture, connect the RaceCapture app and verify the WiFi client is connected under the System Status page. &lt;br /&gt;
[[image:verifying_wifi_client_connected.png]]&lt;br /&gt;
&lt;br /&gt;
It may take several seconds for the client to connect. If not, re-check the camera&#039;s SSID/password, and ensure WiFi is enabled on the camera. &lt;br /&gt;
* &#039;&#039;&#039;Note&#039;&#039;&#039;: On GoPros, the Camera must be in &#039;App mode&#039; with WiFi enabled. &lt;br /&gt;
&lt;br /&gt;
Once it is connected to the camera, you can test the camera by triggering the configured camera&#039;s threshold. &lt;br /&gt;
* &#039;&#039;&#039;Tip&#039;&#039;&#039;: For static testing, you can configure the camera control to one of the Accelerometer channels, such as &#039;&#039;&#039;AccelZ&#039;&#039;&#039; and trigger by inverting RaceCapture. Or, use RPM, battery voltage or similar. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==RaceCapture/Pro MK2==&lt;br /&gt;
While the automatic camera control firmware feature is not available for RaceCapture/Pro MK2, it can still be controlled via a Lua script. &lt;br /&gt;
&lt;br /&gt;
[[image:RaceCapture_WiFi_GoPro_control_diagram.png]]&lt;br /&gt;
&lt;br /&gt;
When WiFi is enabled on your GoPro camera it creates a network that other devices can connect to.  A WiFi enabled version of RaceCapture/Pro can connect to this network and issue the appropriate commands to control various camera functions - in this case, starting and stopping video recording.&lt;br /&gt;
&lt;br /&gt;
Starting and stopping the GoPro can be controlled by a variety of means: speed, RPM or based on other sensor data, enabled by a Lua Script running on RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
This guide focuses on using GPS speed to trigger the camera; for triggering on other sensors see the [[RaceCapturePro_Lua_Scripting|Lua scripting guide]] as a reference for what other sensor data is available.&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Currently, the WiFi module can only be used to enable GoPro triggering. &lt;br /&gt;
* &#039;&#039;&#039;If running firmware version 2.10.x or higher&#039;&#039;&#039; To use this script, you must disable the built-in WiFi control, or else it will take over the connection and block the script from running. &lt;br /&gt;
* Future versions of RaceCapture firmware and app will allow built-in firmware control of GoPro cameras, which will eliminate the need for this script. &lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* RaceCapture/Pro MK2 running firmware 2.9.1 or higher&lt;br /&gt;
* [https://www.autosportlabs.com/product/racecapturepro-wifi-module/ RaceCapture/Pro WiFi module]&lt;br /&gt;
* WiFi enabled GoPro Hero camera, with WiFi activated&lt;br /&gt;
* GPS Connectivity (for speed measurement)&lt;br /&gt;
&lt;br /&gt;
==Steps==&lt;br /&gt;
&lt;br /&gt;
===Configure your GoPro===&lt;br /&gt;
Using the GoPro app, configure the WiFi network, making a note of the network name (SSID) and password.&lt;br /&gt;
&lt;br /&gt;
===Connect the WiFi module===&lt;br /&gt;
Connect the RaceCapture/Pro WiFi module to the outermost (Auxiliary) port of RaceCapture/Pro.&lt;br /&gt;
* When powered up, you should see the power LED illuminate.&lt;br /&gt;
* This port is to the right of the Bluetooth Port.&lt;br /&gt;
** The WiFi module does not interfere with the operation of the Bluetooth module.&lt;br /&gt;
&lt;br /&gt;
===Enable Lua script for GoPro connectivity===&lt;br /&gt;
Customize the Lua script shown at the bottom with the GoPro&#039;s WiFi network name (SSID) and password, then copy and paste the Lua script shown at the bottom into the scripting window of your RaceCapture/Pro. &lt;br /&gt;
&lt;br /&gt;
Steps:&lt;br /&gt;
* Connect RaceCapture/Pro to the RaceCapture app and read the current configuration.&lt;br /&gt;
* Copy the Lua script into the Scripting window:&lt;br /&gt;
** Ensure the script window is first blank by removing the default script by deleting the text in the window.&lt;br /&gt;
*** &#039;&#039;&#039;Note&#039;&#039;&#039;: If you have an existing script you want to keep, you will need to blend the camera functionality with your existing script. How to do this is beyond the scope of this guide; see the [[RaceCapturePro_Lua_Scripting|Lua Scripting Guide]] for more information.&lt;br /&gt;
** Copy the script into the window by using the &#039;&#039;&#039;ctrl-v&#039;&#039;&#039; keyboard shortcut.&lt;br /&gt;
* Write the configuration back to RaceCapture/Pro.&lt;br /&gt;
&lt;br /&gt;
[[image:gopro_script.png]]&lt;br /&gt;
&lt;br /&gt;
===Bench testing===&lt;br /&gt;
Once the Lua script is written to RaceCapture/Pro, it will attempt to connect to the network created by the GoPro camera. Once connected, it will be ready to issue start / stop commands to the camera.&lt;br /&gt;
&lt;br /&gt;
[[image:GoProCameraControl_RaceCapture.jpg]]&lt;br /&gt;
&lt;br /&gt;
Before road testing, ensure RaceCapture/Pro can connect to the GoPro&#039;s WiFi network by observing the messages in the window below the script.&lt;br /&gt;
* &#039;&#039;&#039;Tip 1&#039;&#039;&#039;: Touch or click the &#039;&#039;&#039;Poll Log&#039;&#039;&#039; to see the current message in the RaceCapture/Pro log&lt;br /&gt;
* &#039;&#039;&#039;Tip 2&#039;&#039;&#039;: To restart the Lua script, touch or click the &#039;Restart&#039; button.&lt;br /&gt;
&lt;br /&gt;
===Road testing===&lt;br /&gt;
Mount the GoPro in the car as usual and power up RaceCapture/Pro, waiting for GPS achieve a lock.&lt;br /&gt;
&lt;br /&gt;
* Drive carefully above the speed threshold and observe the GoPro - you should hear and see the familiar beep and red light activate, just as if you manually started recording using the shutter button on the camera. &lt;br /&gt;
* When you drop below the threshold, the GoPro should stop recording.&lt;br /&gt;
&lt;br /&gt;
As RaceCapture/Pro starts and stops the camera, you will see the following information in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] start GoPro&lt;br /&gt;
[GoProWiFi] stop GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Troubleshooting=&lt;br /&gt;
If RaceCapture/Pro cannot control the camera, check the following:&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi network name (SSID) and password&#039;&#039;&#039;: Ensure the name and password currently in the script matches how your GoPro was configured.&lt;br /&gt;
* &#039;&#039;&#039;Enable WiFi on the GoPro&#039;&#039;&#039;: The blue LED on the GoPro should be blinking periodically&lt;br /&gt;
* &#039;&#039;&#039;RaceCapture/Pro WiFi module connection&#039;&#039;&#039;: Ensure the module is plugged into the outermost RJ11 port and the green LED is illuminated.&lt;br /&gt;
* &#039;&#039;&#039;Verify WiFi connection&#039;&#039;&#039;: Ensure RaceCapture/Pro can connect to the GoPro WiFi network. You should see the following messages in the log upon power-up:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[lua] Successfully loaded script.&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] ready for GoPro&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If RaceCapture/Pro cannot connect to the GoPro&#039;s network you will see this in the log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
[GoProWiFi] could not connect to GoPro&lt;br /&gt;
[GoProWiFi] initializing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Lua Script=&lt;br /&gt;
&lt;br /&gt;
The following Lua Script enables WiFi control of your GoPro camera. &lt;br /&gt;
&lt;br /&gt;
==Customization==&lt;br /&gt;
You will need to edit the following fields at the minimum, located at the top of the script:&lt;br /&gt;
&lt;br /&gt;
===Required===&lt;br /&gt;
* &#039;&#039;&#039;GoPro WiFi password&#039;&#039;&#039;: Specify the WiFi password used for the GoPro WiFi adapter&lt;br /&gt;
* &#039;&#039;&#039;GoPro SSID&#039;&#039;&#039;: Specify the GoPro WiFi network name (SSID)&lt;br /&gt;
&lt;br /&gt;
===Optional===&lt;br /&gt;
* &#039;&#039;&#039;goproStart&#039;&#039;&#039;: Change this if you want to start recording at a different threshold. &lt;br /&gt;
* &#039;&#039;&#039;goproStop&#039;&#039;&#039;: Change this if you want to stop recording at a different threshold. &#039;&#039;&#039;Ensure this is less than the start trigger&#039;&#039;&#039;&lt;br /&gt;
* &#039;&#039;&#039;tickRate&#039;&#039;&#039;: Adjust this to update how often you want RaceCapture/Pro to perform a start/stop check. Value is in Hz. If uncertain, leave this alone&lt;br /&gt;
* &#039;&#039;&#039;debug&#039;&#039;&#039;: If things aren&#039;t working as expected you can set this to 1 to see the conversation between the WiFi module and the GoPro.&lt;br /&gt;
** This information shows up in the log window below the script window - check the box &#039;&#039;&#039;Poll log&#039;&#039;&#039; to see this information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
--Specify your GoPro wifi password here&lt;br /&gt;
goproPwd = &#039;12345678&#039;&lt;br /&gt;
&lt;br /&gt;
--Specify your GoPro SSID here&lt;br /&gt;
goproSsid = &#039;aslhero1&#039;&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to start recording&lt;br /&gt;
goproStart = 10&lt;br /&gt;
&lt;br /&gt;
--Speed threshold to stop recording&lt;br /&gt;
goproStop = 5&lt;br /&gt;
&lt;br /&gt;
--How fast we check, in Hz&lt;br /&gt;
tickRate = 10&lt;br /&gt;
&lt;br /&gt;
--Set this to 1 to log communications between RCP &amp;amp; WiFi&lt;br /&gt;
debug = 0&lt;br /&gt;
-----------------------------&lt;br /&gt;
--DO NOT EDIT BELOW&lt;br /&gt;
-----------------------------&lt;br /&gt;
--the serial port where the WiFi is connected&lt;br /&gt;
port = 4&lt;br /&gt;
--indicates wifiStatus&lt;br /&gt;
--0 = not init, 1 = init sent, 2 = got IP, 3 = ready&lt;br /&gt;
wifiStatus = 0&lt;br /&gt;
lastInitTime = 0&lt;br /&gt;
initTimeout = 20000&lt;br /&gt;
&lt;br /&gt;
function logMsg(msg)&lt;br /&gt;
  println(&#039;[GoProWiFi] &#039; ..msg)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendCrlf()&lt;br /&gt;
  writeCSer(port, 13)&lt;br /&gt;
  writeCSer(port, 10)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendRaw(val)&lt;br /&gt;
  for i=1, #val do&lt;br /&gt;
    local c = string.sub(val, i, i)&lt;br /&gt;
    writeCSer(port, string.byte(c))&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendAt(val)&lt;br /&gt;
  if debug == 1 then logMsg(&#039;send: &#039; ..val) end&lt;br /&gt;
  sendRaw(val)&lt;br /&gt;
  sendCrlf()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function toInt(val)&lt;br /&gt;
  return string.sub(val, 1, -3)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function httpGet(url)&lt;br /&gt;
  sendAt(&#039;AT+CIPSTART=&amp;quot;TCP&amp;quot;,&amp;quot;10.5.5.9&amp;quot;,80&#039;)&lt;br /&gt;
  sleep(500)&lt;br /&gt;
  local crlf = string.char(13) ..string.char(10)&lt;br /&gt;
  local get = &#039;GET &#039; ..url ..&#039; HTTP/1.0&#039; ..crlf ..crlf&lt;br /&gt;
  sendAt(&#039;AT+CIPSEND=&#039; ..toInt(#get))&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendRaw(get)&lt;br /&gt;
  sleep(100)&lt;br /&gt;
  sendAt(&amp;quot;AT+CIPCLOSE&amp;quot;) &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function sendGoProShutter(cmd)&lt;br /&gt;
  httpGet(&#039;/bacpac/SH?t=&#039; ..goproPwd ..&#039;&amp;amp;p=%&#039; ..cmd)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function startGoPro()&lt;br /&gt;
  logMsg(&#039;start GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;01&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function stopGoPro()&lt;br /&gt;
  logMsg(&#039;stop GoPro&#039;)&lt;br /&gt;
  sendGoProShutter(&#039;00&#039;)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
recording = 0&lt;br /&gt;
&lt;br /&gt;
function initWiFi()&lt;br /&gt;
  logMsg(&#039;initializing&#039;)&lt;br /&gt;
  sendAt(&#039;AT+RST&#039;)&lt;br /&gt;
  sleep(2000)&lt;br /&gt;
  sendAt(&#039;AT+CWMODE_CUR=1&#039;)&lt;br /&gt;
  sleep(1000)&lt;br /&gt;
  sendAt(&#039;AT+CWJAP_CUR=&amp;quot;&#039; ..goproSsid ..&#039;&amp;quot;,&amp;quot;&#039; ..goproPwd ..&#039;&amp;quot;&#039;)&lt;br /&gt;
  wifiStatus = 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function processIncoming()&lt;br /&gt;
  local line = readSer(port, 100)&lt;br /&gt;
  if line ~= &#039;&#039; and debug == 1 then print(line) end&lt;br /&gt;
  if string.match(line, &#039;WIFI GOT IP&#039;) then &lt;br /&gt;
    wifiStatus = 2&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 2 and string.match(line, &#039;OK&#039;) then&lt;br /&gt;
    wifiStatus = 3&lt;br /&gt;
    logMsg(&#039;ready for GoPro&#039;)&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function checkGoPro()&lt;br /&gt;
  if wifiStatus == 0 then&lt;br /&gt;
    initWiFi()&lt;br /&gt;
    lastInitTime = getUptime()&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  if wifiStatus == 1 and getUptime() &amp;gt; lastInitTime + initTimeout then&lt;br /&gt;
    logMsg(&#039;could not connect to GoPro&#039;)&lt;br /&gt;
    wifiStatus = 0&lt;br /&gt;
  end&lt;br /&gt;
  processIncoming()&lt;br /&gt;
  if wifiStatus ~= 3 then&lt;br /&gt;
    return&lt;br /&gt;
  end&lt;br /&gt;
  trigger = getGpsSpeed()&lt;br /&gt;
&lt;br /&gt;
  if recording == 0 and trigger &amp;gt; goproStart then&lt;br /&gt;
    startGoPro()&lt;br /&gt;
    recording = 1&lt;br /&gt;
  end&lt;br /&gt;
  if recording == 1 and trigger &amp;lt; goproStop then&lt;br /&gt;
    stopGoPro()&lt;br /&gt;
    recording = 0&lt;br /&gt;
  end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function onTick()&lt;br /&gt;
  checkGoPro()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
setTickRate(tickRate)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>GTIspirit</name></author>
	</entry>
</feed>