<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vincentsparkes</title>
	<atom:link href="https://vince.sparkes.co/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>https://vince.sparkes.co/blog</link>
	<description></description>
	<lastBuildDate>Sun, 08 Apr 2018 20:21:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>How to setup WordPress with a local database on Azure App Service on Linux</title>
		<link>https://vince.sparkes.co/blog/?p=1878</link>
		<comments>https://vince.sparkes.co/blog/?p=1878#comments</comments>
		<pubDate>Sun, 08 Apr 2018 20:19:02 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Azure]]></category>

		<guid isPermaLink="false">http://vince.sparkes.co/blog/?p=1878</guid>
		<description><![CDATA[Azure App Service on Windows is perfectly happy to setup a WordPress site with MySql in-app. It even used to work the same for Linux, unfortunately that functionality was temporarily removed around March 2017 (https://blogs.msdn.microsoft.com/appserviceteam/2017/03/21/create-wordpress-using-web-apps-on-linux/). Considering the price of £57/month for the most basic Azure MySql database, I decided to try and use MySql in-app with &#8230; <a href="https://vince.sparkes.co/blog/?p=1878" class="more-link">Continue reading <span class="screen-reader-text">How to setup WordPress with a local database on Azure App Service on Linux</span></a>]]></description>
				<content:encoded><![CDATA[<p>Azure App Service on Windows is perfectly happy to setup a WordPress site with MySql in-app. It even used to work the same for Linux, unfortunately that functionality was <em>temporarily </em>removed around March 2017 (<a title="https://blogs.msdn.microsoft.com/appserviceteam/2017/03/21/create-wordpress-using-web-apps-on-linux/" href="https://blogs.msdn.microsoft.com/appserviceteam/2017/03/21/create-wordpress-using-web-apps-on-linux/" target="_blank">https://blogs.msdn.microsoft.com/appserviceteam/2017/03/21/create-wordpress-using-web-apps-on-linux/</a>).</p>
<p>Considering the price of £57/month for the most basic Azure MySql database, I decided to try and use MySql in-app with WordPress on Linux.</p>
<p><em>Warning: This might not work for you, there must have been a reason this functionality was disabled in the first place!</em></p>
<p>To start with I found the docker images which used to be used. The source for which is available at <a title="https://github.com/Azure-App-Service/apps/tree/master/Wordpress" href="https://github.com/Azure-App-Service/apps/tree/master/Wordpress" target="_blank">https://github.com/Azure-App-Service/apps/tree/master/Wordpress</a> and the images <a title="https://hub.docker.com/r/appsvc/apps/tags/" href="https://hub.docker.com/r/appsvc/apps/tags/" target="_blank">https://hub.docker.com/r/appsvc/apps/tags/</a>.</p>
<p>I then created a new <b>Web App for Containers</b> and configured the container to point at <strong>appsvc/apps:wordpress-0.3</strong>.</p>
<p>I then added the following <strong>Application settings</strong>:</p>
<ul>
<li>WEBSITES_ENABLE_APP_SERVICE_STORAGE = true</li>
<li>DATABASE_HOST = localhost</li>
<li>DATABASE_NAME = wordpress</li>
<li>DATABASE_USERNAME = [[Database Username]]</li>
<li>DATABASE_PASSWORD = [[Database Password]]</li>
<li>TABLE_NAME_PREFIX = wp_</li>
<li>PHPMYADMIN_USERNAME = [[PhpMyAdmin Username]]</li>
<li>PHPMYADMIN_PASSWORD = [[PhpMyAdmin Password]]</li>
</ul>
<p>After restarting the App Service, you should then be able to visit the site where you should see &#8220;Installing WordPress&#8230;&#8221; text. After a few minutes, once it&#8217;s all setup, you should then see the familiar WordPress installation guide.</p>
<h3>But what about HTTPS?</h3>
<p>So we want our WordPress site to be secure. We can follow the previous post to create and configure the certificate (<a title="How to setup SSL Certificates for Azure App Service Web App on Linux" href="http://vince.sparkes.co/blog/?p=1870" target="_blank">see here</a>).</p>
<p>We then need to configure WordPress to handle it.</p>
<p><em>Note: It&#8217;s best to do this after finishing the WordPress installation guide, as it overwrites the wp-config.php file.</em></p>
<p>We&#8217;ll start by going to the Kudu SSH terminal (https://[[App Service Name]].scm.azurewebsites.net/webssh/host).</p>
<p>From there we need to install a text editor (as for some very strange reason one isn&#8217;t installed by default?!):</p><pre class="crayon-plain-tag">apt-get update

apt-get install nano</pre><p><em>Note: You might prefer vim, however I tried it and as it&#8217;s an embedded terminal, it didn&#8217;t seem to handle the ESC character, rendering you stuck in vim&#8230; forever&#8230; nightmare!</em></p>
<p>Now we can edit our wp-config.php file.</p><pre class="crayon-plain-tag">nano /home/site/wwwroot/wp-config.php</pre><p>You&#8217;ll want to make your file look similar to this (namely adding the FORCE_SSL_ADMIN and the following line, and updating the WP_HOME and WP_SITEURL to https):</p><pre class="crayon-plain-tag">define('WP_DEBUG', false);

define('FORCE_SSL_ADMIN', true);
$_SERVER['HTTPS']='on';

/* That's all, stop editing! Happy blogging. */

//Relative URLs for swapping across app service deployment slots
define('WP_HOME', 'https://'. filter_input(INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_STRING));
define('WP_SITEURL', 'https://'. filter_input(INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_STRING));</pre><p>If you&#8217;ve never used nano before then, once you&#8217;ve made your changes, press Ctrl + X and type Y to save your changes and exit.</p>
<p>Given you uploaded your certificate, bound it to the domain, and enforced HTTPS only, then after refreshing the site, you should have a fully working and secure WordPress site!</p>
<p>I haven&#8217;t dabbled with the backups yet, but plan to in the near future.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1878</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to setup SSL Certificates for Azure App Service Web App on Linux</title>
		<link>https://vince.sparkes.co/blog/?p=1870</link>
		<comments>https://vince.sparkes.co/blog/?p=1870#comments</comments>
		<pubDate>Sun, 08 Apr 2018 18:43:55 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Azure]]></category>

		<guid isPermaLink="false">http://vince.sparkes.co/blog/?p=1870</guid>
		<description><![CDATA[I have an Azure App Service which hosts a few web apps (all on Linux as you cannot have both Windows and Linux apps on the same App Service Plan, and to be honest the Linux ones just seemed more responsive than the Windows ones). Azure has yet to embrace the LetsEncrypt movement, so the &#8230; <a href="https://vince.sparkes.co/blog/?p=1870" class="more-link">Continue reading <span class="screen-reader-text">How to setup SSL Certificates for Azure App Service Web App on Linux</span></a>]]></description>
				<content:encoded><![CDATA[<p>I have an Azure App Service which hosts a few web apps (all on Linux as you cannot have both Windows and Linux apps on the same App Service Plan, and to be honest the Linux ones just seemed more responsive than the Windows ones).</p>
<p>Azure has yet to embrace the LetsEncrypt movement, so the only options for setting up SSL certificates with your Web App is via Azure App Service Certificates (starting ~£50/year) or manually uploading an otherwise acquired certificate.</p>
<p>There is a helpful guide for setting up LetsEncrypt for Web Apps on Windows (<a title="https://www.troyhunt.com/everything-you-need-to-know-about-loading-a-free-lets-encrypt-certificate-into-an-azure-website/" href="https://www.troyhunt.com/everything-you-need-to-know-about-loading-a-free-lets-encrypt-certificate-into-an-azure-website/" target="_blank">https://www.troyhunt.com/everything-you-need-to-know-about-loading-a-free-lets-encrypt-certificate-into-an-azure-website/</a>) however this does not work for Web Apps on Linux.</p>
<p>These are the steps I took to configure my sites (massive thanks to <a title="https://www.lastcoolnameleft.com/2017/08/letsencrypt-on-azure-app-service-for-linux/" href="https://www.lastcoolnameleft.com/2017/08/letsencrypt-on-azure-app-service-for-linux/" target="_blank">https://www.lastcoolnameleft.com/2017/08/letsencrypt-on-azure-app-service-for-linux/</a> for doing most of the ground work!).</p>
<h3>Generating the certificate</h3>
<p>To generate the certificates I used the Certbot tool. I chose to run this via docker.</p><pre class="crayon-plain-tag">docker run -it --rm --name certbot -v "[[Certificates folder e.g. C:/certs]]:/etc/letsencrypt" -v "[[Certificates folder e.g C:/certs]]:/var/lib/letsencrypt" certbot/certbot certonly --manual --preferred-challeneges http</pre><p><em>Note: You&#8217;ll need to make sure you&#8217;ve enabled Shared Drives in Docker for Windows. To do this open <strong>Docker Settings</strong> and click <strong>Shared Drives</strong>. Tick the drive you want to share and click <strong>Apply</strong>.</em></p>
<p><em>Another Note: I tried the DNS challenge however with 123-reg at least, the TTL for the TXT record was 4 hours, and if you rerun the certbot it will give you new validation values everytime, meaning if you screw up you won&#8217;t get another chance for around 4 hours!</em></p>
<p>Follow the interactive steps:</p>
<ol>
<li>If this is the first time you&#8217;ve run it then you will need to enter your email address.</li>
<li>Then follow the link to read the terms and conditions, then enter A to agree</li>
<li>Decide whether you would like to share your email with the EFF</li>
<li>Enter the domain name(s) you would like to generate a certificate for, note this does not support wildcards certificates</li>
<li>Then agree to having your IP address logged (if you don&#8217;t you cannot generate the certificate so make sure you are using an IP address you are happy sharing?)</li>
<li>Follow the instructions to validate you own the domain
<ol>
<li>We picked the http option earlier which means we need to generate a file on the server</li>
<li>To do this go the Kudu page and find the SSH page (will typically look like https://[[Web App Name]].scm.azurewebsites.net/webssh/host)</li>
<li>You&#8217;ll want to<br />
<pre class="crayon-plain-tag">cd /home/site/wwwroot</pre>
</li>
<li>Then<br />
<pre class="crayon-plain-tag">mkdir .well-known &amp;&amp; cd .well-known</pre>
</li>
<li>Then<br />
<pre class="crayon-plain-tag">mkdir acme-challenge &amp;&amp; cd acme-challenge</pre>
</li>
<li>Then<br />
<pre class="crayon-plain-tag">echo [[Certbot file contents]] &gt; [[Certbot file name]]</pre>
</li>
</ol>
</li>
</ol>
<p>Certbot will then spit out a bunch of files in your mounted folder.</p>
<p>Unfortunately these files aren&#8217;t quite usable. We&#8217;ll need to extract a certificate from them. For that we&#8217;ll need to install openssl locally. Navigate to <a title="https://slproweb.com/products/Win32OpenSSL.html " href="https://slproweb.com/products/Win32OpenSSL.html%20" target="_blank">https://slproweb.com/products/Win32OpenSSL.html </a>and download the latest version (<strong>Win64 OpenSSL v1.1.0h</strong> was the one I used). I chose to install the binaries to the OpenSSL bin directory, and then added that directory to my path environment variable (for Windows 10, type environment variables into Start and add a new row to the Path variable).</p>
<p>Once installed we&#8217;ll need to run the following (I used the archive version as the live folder didn&#8217;t work for me, and it simply linked to the archive folder anyway)</p><pre class="crayon-plain-tag">openssl pkcs12 -export -out [[Domain Name]].pfx -inkey [[Certificates folder e.g. C:/certs]]/archive/[[Domain Name]]/privkey1.pem -in [[Certificates folder e.g. C:/certs]]/archive/[[Domain Name]]/fullchain1.pem</pre><p>You will be prompted for an export password, which is important to remember as we&#8217;ll need it when we upload the certificate to Azure (use something memorable e.g. iHATEcertificates69!)</p>
<h3>Using the certificate</h3>
<p>Once we have our certificate we can navigate to the<strong> SSL certificates</strong> page on our Web App in Azure. Choose <strong>Upload Certificate</strong>, choose the [[Domain Name]].pfx file and enter the export password you chose earlier.</p>
<p>Then we simply click <strong>Add binding</strong> under the<strong> SSL bindings</strong> area on the same page and associate the certificate with the custom domain name we have already added.</p>
<p>One final thing that is probably worth doing is going to the <strong>Custom domains</strong> tab and enabling <strong>HTTPS Only</strong>, this essentially forces all HTTP traffic to use HTTPS.</p>
<h3>Whats next?</h3>
<p>LetsEncrypt only gives you certificates that are valid for 3 months. That means we&#8217;ll need to do the same steps in 3 months, which is a bit tedious.</p>
<p>I plan on building a tool to help with this (similar to the LetsEncrypt Windows App Service tool), so watch this space!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1870</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress permissions</title>
		<link>https://vince.sparkes.co/blog/?p=1862</link>
		<comments>https://vince.sparkes.co/blog/?p=1862#comments</comments>
		<pubDate>Thu, 26 Mar 2015 21:20:21 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://vince.sparkes.co/blog/?p=1862</guid>
		<description><![CDATA[It had been a while since I had written anything on this blog, and I was using some ancient version of WordPress with some dodgy custom theme I built. Inevitably I decided an upgrade would be worthwhile. I won&#8217;t bore you with the details as there are already plenty of brilliant guides out there to &#8230; <a href="https://vince.sparkes.co/blog/?p=1862" class="more-link">Continue reading <span class="screen-reader-text">WordPress permissions</span></a>]]></description>
				<content:encoded><![CDATA[<p>It had been a while since I had written anything on this blog, and I was using some ancient version of WordPress with some dodgy custom theme I built. Inevitably I decided an upgrade would be worthwhile. I won&#8217;t bore you with the details as there are already plenty of brilliant guides out there to do that.</p>
<p>The other day I decided to write a post on my sparkly new blog, and thought why not brighten it up a bit with some images. I clicked <strong>Add Media</strong>, dragged and dropped my images onto the shiny new upload window, and it didn&#8217;t work.</p>
<p>There was an error writing to the <strong>wp-content/uploads/&#8230;</strong> folder.</p>
<p>The correct fix was relatively easy, however it wasn&#8217;t outlined in detail at any one place, until now!</p>
<p>If you too are hosting WordPress using nginx on a Linux server then follow these steps to configure WordPress to accept uploads whilst remaining secure.</p>
<ol>
<li>Find your nginx config file, mine was under <strong>/etc/nginx/nginx.conf</strong> and open it up.</li>
<li>The first line should read something like <strong>user www-data;</strong></li>
<li>This describes who nginx runs as. By default it&#8217;s <strong>www-data</strong>.</li>
<li>This user needs to be able to write to the <strong>wp-content/uploads</strong> folder.</li>
<li>Navigate to your WordPress installation folder and execute <strong>chown -R www-data:www-data wp-content/uploads</strong> (you may need to prefix this with <strong>sudo</strong> depending on your security setup).</li>
</ol>
<p>Voila! The user <strong>www-data</strong> now owns that directory and you will be able to upload files there.</p>
<p>Don&#8217;t take the easy option of <strong>chmod</strong> <strong>777 </strong>your WordPress install directory, stay secure and follow the above instructions.</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1862</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple SSH and teaching Pageant to remember</title>
		<link>https://vince.sparkes.co/blog/?p=1845</link>
		<comments>https://vince.sparkes.co/blog/?p=1845#comments</comments>
		<pubDate>Tue, 24 Mar 2015 20:53:05 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://vince.sparkes.co/blog/?p=1845</guid>
		<description><![CDATA[Recently I&#8217;ve found myself bouncing between various servers using SSH and FTP more often than one wishes. Obviously being the security conscious person I am, every password must be different and complex enough to defer even the most determined of intruders. As you are probably all too well aware, this doesn&#8217;t half slow things down when &#8230; <a href="https://vince.sparkes.co/blog/?p=1845" class="more-link">Continue reading <span class="screen-reader-text">Simple SSH and teaching Pageant to remember</span></a>]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;ve found myself bouncing between various servers using SSH and FTP more often than one wishes. Obviously being the security conscious person I am, every password must be different and complex enough to defer even the most determined of intruders.</p>
<p>As you are probably all too well aware, this doesn&#8217;t half slow things down when travelling between servers; the remembering, the typing, the mis-remembering, the re-typing&#8230;</p>
<p>I was at the verge of despair when I decided to delve back into the Sys Admin module I took at University, and investigate using keys as an alternative authentication system.<a href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/1-Pageantshortcut.png"><br />
</a></p>
<p>My first goal was to streamline the connection between my Windows laptop and my Linux NAS, using my tool of choice, PuTTY.</p>
<ol>
<li>We need to create a Public/Private key combination. For this we&#8217;ll fire up PuTTYgen, which is installed automatically with PuTTY.</li>
<li>Hit the <strong>Generate</strong> button, and squiggle your mouse around until the bar fills up!<a class="image-collapsible-container" href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/1-PuTTYGen.png"><img class="aligncenter wp-image-1847 size-full" src="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/1-PuTTYGen.png" alt="PuTTYGen" width="493" height="478" /></a></li>
<li>I like to add a bit more of a description to the comment here, usually <strong>username</strong>@<strong>servername</strong> of what I&#8217;m connecting to.<a class="image-collapsible-container" href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/2-Keycreation.png"><img class="image-collapsible aligncenter wp-image-1848 size-full" src="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/2-Keycreation.png" alt="Key Creation" width="493" height="478" /></a></li>
<li>Next we need to <strong>Save private key</strong>, now it doesn&#8217;t really matter where you save it to, my preference at the moment is <strong>username</strong>@<strong>servername</strong>.ppk  in a <strong>Keys</strong> folder under my user profile e.g. C:\Users\<strong>Username</strong>\Keys.</li>
<li>Now for what should be the last time, we need to login to our server using our username and password, and navigate to the <strong>.ssh </strong>folder e.g. <strong>cd ~/.ssh</strong></li>
<li>Then we either need to create or edit a file called <strong>authorized_keys</strong>, note that the file doesn&#8217;t have an extension. Welcome to the crazy world of Linux! Anyway we can do this by calling any editor we like, personally I use vim so execute <strong>vim authorized_keys</strong></li>
<li>Then we need to copy and paste (right click to paste into a PuTTY session) the content from PuTTYgen box <strong>Public key for pasting into Open SSH authorized_keys file</strong> into our editor.<a class="image-collapsible-container" href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/3-Vim.png"><img class="aligncenter wp-image-1851 size-full" src="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/3-Vim.png" alt="Vim" width="675" height="425" /></a></li>
<li>If you&#8217;re still using vim, press <strong>Esc</strong> followed by <strong>:wq</strong> to save and exit.</li>
</ol>
<p>That should be everything needed to get the SSH set up. Close your PuTTY session and try connecting to your server in a new session.</p>
<p>Still here? Yup, we&#8217;re not quite done yet. Windows and PuTTY don&#8217;t know how to use our private key at the moment, so we are still prompted for our password. Luckily PuTTY comes with a nifty little utility called <strong>Pageant</strong> (not sure what it stands for but I always forget the second &#8216;a&#8217;).</p>
<p>Double clicking on the private key we saved earlier should open up Pageant and add our key to the store. Then next time we create a new session with the server we should be logged in automatically.</p>
<p>This is all well and good, however if we were to restart our PC and try to connect to our server we would once again be prompted for our username and password. This is because Pageant does not persist our keys, or even automatically startup. Adding this functionality is pretty easy to achieve following these steps.</p>
<ol>
<li>Locate the Pageant shortcut on the Start Menu, on Windows 8 it&#8217;s as simple as pressing the Windows key, typing <strong>pageant</strong>, right clicking on the search result and selecting <strong>Open file location</strong>.</li>
<li>It should take you to somewhere like <strong>C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PuTTY<a class="image-collapsible-container" href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/1-Pageantshortcut.png"><img class="aligncenter wp-image-1846 size-full" src="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/1-Pageantshortcut.png" alt="Pageant Shortcut" width="838" height="403" /></a></strong></li>
<li>Now we need to copy the shortcut for Pageant and paste it in our Startup folder. This can be located by navigating to <strong>%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup<a class="image-collapsible-container" href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/2-Startupfolder.png"><img class="aligncenter wp-image-1849 size-full" src="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/2-Startupfolder.png" alt="Startup Folder" width="838" height="403" /></a></strong></li>
<li>Next we need to tell Pageant what keys to load when it starts up. Right click on the newly pasted shortcut, and select <strong>Properties</strong></li>
<li>In the target field we need to append the path to each of our keys e.g. a complete target field could look like <strong>&#8220;C:\Program Files (x86)\PuTTY\pageant.exe&#8221; &#8220;C:\Users\Username\Keys\username@servername.ppk&#8221;<a class="image-collapsible-container" href="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/3-Shortcutproperties.png"><img class="aligncenter wp-image-1850 size-full" src="http://vince.sparkes.co/blog/wp-content/uploads/2015/03/3-Shortcutproperties.png" alt="Shortcut Properties" width="377" height="516" /></a></strong></li>
</ol>
<p>That&#8217;s it. All done. Fire it up and give it a go. I use Windows 8.1 with the latest installed version of PuTTY and the server has Ubuntu 14 on it, so depending on your setup some paths could be different. Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1845</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking the Everlast EV-410 Exercise Bike</title>
		<link>https://vince.sparkes.co/blog/?p=1834</link>
		<comments>https://vince.sparkes.co/blog/?p=1834#comments</comments>
		<pubDate>Wed, 10 Apr 2013 20:31:40 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Bike Hack]]></category>

		<guid isPermaLink="false">http://vincentsparkes.co.uk/blog/?p=1834</guid>
		<description><![CDATA[I recently agreed to take part in the JDRF Ride to Cure Diabetes charity event. In preparation for the event I purchased an exercise bike, the Everlast EV-410. Relatively cheap and collapsible, it met every expectation, but could still be improved&#8230; It comes with a &#8220;computer&#8221; which displays distance, speed, calories burnt, time, and pulse. This &#8230; <a href="https://vince.sparkes.co/blog/?p=1834" class="more-link">Continue reading <span class="screen-reader-text">Hacking the Everlast EV-410 Exercise Bike</span></a>]]></description>
				<content:encoded><![CDATA[<p>I recently agreed to take part in the <a href="https://www.jdrf.org.uk/get-involved/join-in-an-event/ride" target="_blank">JDRF Ride to Cure Diabetes</a> charity event. In preparation for the event I purchased an exercise bike, the Everlast EV-410. Relatively cheap and collapsible, it met every expectation, but could still be improved&#8230;</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2013/04/ev410.jpg"><img class="aligncenter size-full wp-image-1838" title="Everlast EV-410" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2013/04/ev410.jpg" alt="" width="300" height="300" /></a></p>
<p>It comes with a &#8220;computer&#8221; which displays distance, speed, calories burnt, time, and pulse. This is all well and good whilst using the bike, but what about recording progress over a period of time?</p>
<p>The simple solution would be to manually record this information. However I&#8217;d prefer to automate it, so set myself this little challenge. My plan is to connect it to the PC, ideally using WiFi and record the information automatically.</p>
<p>Thankfully the &#8220;computer&#8221; on the bike isn&#8217;t hardwired. The wheel of the bike has a cable that plugs into the computer via a standard 3.5mm audio jack. A little bit of research suggested that the cable is used to transmit a pulse for every revolution of the wheel.</p>
<p>To test this theory I invested in two cables, a splitter and a standard 3.5mm auxiliary cable.</p>
<p style="text-align: center;"><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2013/04/WP_000112.jpg"><img class="aligncenter size-large wp-image-1839" title="Cable arrangement" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2013/04/WP_000112-768x1024.jpg" alt="" width="384" height="512" /></a></p>
<p>I used the splitter to intercept the signal (as shown above), and the auxiliary cable to connect the the bike to my PC via the microphone port. I then used the free software (<a href="http://audacity.sourceforge.net/" target="_blank">Audacity</a>) to record the input when riding the bike. As expected it produced a blip for every revolution!</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2013/04/audaicty.png"><img class="aligncenter size-medium wp-image-1840" title="Audacity" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2013/04/audaicty-300x164.png" alt="" width="300" height="164" /></a></p>
<p>Next I needed a way to use this information. To begin with I wrote a short bit of java that reads from a WAV file, interprets the amplitude (<a href="http://ganeshtiwaridotcomdotnp.blogspot.co.uk/2011/12/java-extract-amplitude-array-from.html" target="_blank">this page came in exceptionally useful</a>), and counts the blips.</p>
<p>The next step was to get it to read directly from the bike. This involved learning a fair bit about how java handles sound, and to be honest, how computers in general handle sound!</p>
<p>Surprisingly there was very little existing code that demonstrates how to process sound input, so I had to write a majority of it from scratch. After some time experimenting I settled with the following solution.</p>
<ol>
<li>Find the audio mixers on the PC</li>
<li>Select the desired mixer</li>
<li>Open a line from the mixer</li>
<li>Calculate frame size (in my case 4bytes per frame, 44100 frames per second)</li>
<li>Use a stream to read from the line, frame by frame</li>
<li>Split each frame into 2 channels</li>
<li>Calculate amplitude of the left channel (right channel will be used to record pulse)</li>
</ol>
<p>This worked fairly well, and seemed to record the blips as expected. The next step was to integrate this with some form of timekeeping. Unfortunately it took around 3 seconds to process 1 second of audio. I tried changing buffer sizes, sample rates, and even tried skipping frames but to no avail. I settled on using a timer to keep track of the time, instead of the frame count.</p>
<p>Even with the lag, I&#8217;d come this far, so moved on to calculating the distance travelled for every revolution of the wheel. This was done by eye through experimentation. I settled at roughly 4.44m per revolution of the wheel, which yields distance covered the same as the bike computer.</p>
<p>Next up will be trying to find a way to overcome the lag, and designing a suitable way to store and display the information. The code I wrote is below for reference.</p>
<div id="_mcePaste">
<pre class="crayon-plain-tag">// Print system mixers
public void getMixers() {
    Mixer.Info[] mixers = AudioSystem.getMixerInfo();
    for(int i = 0; i &lt; mixers.length; i++) {
        Mixer.Info info = mixers[i];
        System.out.println(i + ": " + info.getName() + " - " + info.getDescription() + " - " + info.getVendor() + " - " + info.getVersion());
    }
}

// Is it a blip?
public static int level(int input) {
    if( input &gt;= 20000 )
        return 1;
    return 0;
}

public void getLine() {
    int mixerId = 6; // Manually chosen from running getMixers
    Mixer mixer = AudioSystem.getMixer(AudioSystem.getMixerInfo()[mixerId]);
    
    // Get lines from mixer
    Line.Info[] lines = mixer.getTargetLineInfo();
    for( int i = 0; i &lt; lines.length; i++) {
        DataLine.Info line = (DataLine.Info)lines[i];
        System.out.println(line);
    }

    try {
        // Open line from mixer
        TargetDataLine line = (TargetDataLine) mixer.getLine(lines[0]);
        line.open();

        // Fetch audio format of the line
        AudioFormat af = ((DataLine)line).getFormat();
        System.out.println(af.toString());

        // Create audio input stream from line
        AudioInputStream ais = new AudioInputStream(line);

        // Start listening on line
        line.start();
        int frameCount = 0;
        int secondCount = 0;
        int tickCount = 0;
        int previous = 0;
        double distance = 0;
        double distancePerTick = (double)10 / (double)2.25;
        ArrayList&lt;Integer&gt; ticksPerSec = new ArrayList&lt;Integer&gt;();
        long start = System.currentTimeMillis();
        int sampleSize = 4;

        // Process stream frame at a time
        while( true ) {
            byte[] frame = new byte[sampleSize];
            ais.read(frame, 0, sampleSize);

            if( af.getChannels() == 1 ) {
                // Single channel to be implemented later
            } else {
                // If two channels split frame in middle
                byte[] left = Arrays.copyOfRange(frame, 0, af.getFrameSize()/2);
                byte[] right = Arrays.copyOfRange(frame, af.getFrameSize()/2, af.getFrameSize());

                // Get amplitude
                int[] amp = WaveData.extractAmplitudeDataFromAmplitudeByteArray(af, left);

                if( level(amp[0]) == 1 &amp;&amp; previous == 0 ) {
                    tickCount++;
                }
                previous = level(amp[0]);
            }

            // Increment frame count
            frameCount++;

            if( System.currentTimeMillis() == start + 1000 ) {
                // A full sample rate has passed, equivalent to 1 second
                // Add tick count to arraylist
                ticksPerSec.add(tickCount);

                start = System.currentTimeMillis();
                distance = distance + (tickCount * distancePerTick);
                System.out.println(secondCount + ": " + distance + " - " + distancePerTick);

                // Move onto the next second
                secondCount++;

                // Reset frame and tick count
                frameCount = 0;
                tickCount = 0;
            }
        }
    } catch (LineUnavailableException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1834</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Viewsonic VOT120 Project</title>
		<link>https://vince.sparkes.co/blog/?p=1829</link>
		<comments>https://vince.sparkes.co/blog/?p=1829#comments</comments>
		<pubDate>Thu, 26 Jul 2012 11:10:03 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://vincentsparkes.co.uk/blog/?p=1829</guid>
		<description><![CDATA[My VOT120 Mini PC was originally purchased as a media server, and although running slightly warm, has done a good job. I have recently resurrected an old project, RAWRWoW, and decided to host it from the VOT120. Either down to the increased usage, or the ridiculously warm temperatures at the moment, it was running at &#8230; <a href="https://vince.sparkes.co/blog/?p=1829" class="more-link">Continue reading <span class="screen-reader-text">Viewsonic VOT120 Project</span></a>]]></description>
				<content:encoded><![CDATA[<p>My VOT120 Mini PC was originally purchased as a media server, and although running slightly warm, has done a good job.</p>
<p>I have recently resurrected an old project, RAWRWoW, and decided to host it from the VOT120. Either down to the increased usage, or the ridiculously warm temperatures at the moment, it was running at ~86 degrees Celsius the other night, I could smell burning, it was awful.</p>
<p>The airflow on the VOT120 is awful. There is an inflow grill on the back and a 40mm next to the heatsink, which pushes air through the heatsink ,and out through a grill at the top. The 2.5&#8243; HDD is mounted to the rear of the motherboard, meaning all the heat has to pass through the heatsink to leave the case, or just go through the case.</p>
<p>First thought was to swap the HDD for an SSD, it has 160GB in there at the moment, of which only about 10GB is used. Although the prices for SSD&#8217;s have come down phenomenally, they&#8217;re still a bit too pricey, and there is still a debate about lifetime on server usage.</p>
<p>In the meantime I need a more efficient way of cooling the VOT120. I rummaged through my box of parts and found a 120mm 12V case fan. Fits almost perfectly to the side of the VOT120! The only issue being, the case fan requires a 3 pin fan connection, or a 4 pin molex connection. The current fan in the VOT120 connects to a tiny 3 pin fan connection, not to mention it only supplies 5V , instead of the needed 12V.</p>
<figure id="attachment_1830" style="width: 640px;" class="wp-caption aligncenter"><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00074.jpg"><img class="size-large wp-image-1830" title="DSC00074" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00074-1024x768.jpg" alt="" width="640" height="480" /></a><figcaption class="wp-caption-text">The 120mm fan on the left and the opened up VOT120, with 40mm fan on the right.</figcaption></figure>
<p style="text-align: left;">I figured I&#8217;d give it a go anyway, so cut and stripped the tiny 3 pin fan plug, soldered and taped it to the case fan cable. Apprehensively (after the shock from the Landrover the other day), I connected the power supply and switched it on. The fan did try to spin, and with a little encourage it did spin for around 10 seconds, but then slowed to a measly ~1 RPM. This would probably be worse than the original fan!</p>
<figure id="attachment_1832" style="width: 640px;" class="wp-caption aligncenter"><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00076.jpg"><img class="size-large wp-image-1832 " title="DSC00076" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00076-1024x768.jpg" alt="" width="640" height="480" /></a><figcaption class="wp-caption-text">Old fan connector on the left, new soldered and taped tiny 3 pin connector on the right.</figcaption></figure>
<p>I shopped around on the internet for a 5V 120mm fan, I thought they would have been fairly common, but no. If I was in the USA, I could have picked one up just about anywhere, but here in the UK, there was one (unless I fancied waiting 14 &#8211; 23 days for it to arrive from China). Ended up getting the <a href="http://www.enermax.co.uk/urvegas.html">Endermax UR Vegas</a>, it&#8217;s USB powered, and has lots of fancy lights (which luckily have an off mode)! Depending how adventurous I&#8217;m feeling when it arrives, I might solder it onto the tiny 3 pin plug, rather than waste a precious USB port. Time will only tell.</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1829</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Landrover Series 2a Petrol</title>
		<link>https://vince.sparkes.co/blog/?p=1816</link>
		<comments>https://vince.sparkes.co/blog/?p=1816#comments</comments>
		<pubDate>Tue, 24 Jul 2012 08:31:05 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Land Rover]]></category>
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://vincentsparkes.co.uk/blog/?p=1816</guid>
		<description><![CDATA[Roof and cab removed, can see the roof against the wall and the cab is sitting in the tub at the moment. Eventually managed to remove the tub after removing the seats, exposing the rear half chassis and axle. The damage to the rear cross member, either needs replacing or bashing out, yes it is &#8230; <a href="https://vince.sparkes.co/blog/?p=1816" class="more-link">Continue reading <span class="screen-reader-text">Landrover Series 2a Petrol</span></a>]]></description>
				<content:encoded><![CDATA[<p>Roof and cab removed, can see the roof against the wall and the cab is sitting in the tub at the moment.</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00066.jpg"><img class="aligncenter size-large wp-image-1817" title="DSC00066" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00066-1024x768.jpg" alt="" width="640" height="480" /></a></p>
<p>Eventually managed to remove the tub after removing the seats, exposing the rear half chassis and axle.</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00067.jpg"><img class="aligncenter size-large wp-image-1818" title="DSC00067" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00067-1024x768.jpg" alt="" width="640" height="480" /></a></p>
<p>The damage to the rear cross member, either needs replacing or bashing out, yes it is full of mud as well.</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00070.jpg"><img class="aligncenter size-large wp-image-1821" title="DSC00070" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00070-1024x768.jpg" alt="" width="640" height="480" /></a></p>
<p>Rear diff removed from axle casing.</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00071.jpg"><img class="aligncenter size-large wp-image-1823" title="DSC00071" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00071-1024x768.jpg" alt="" width="640" height="480" /></a></p>
<p>The damaged rear diff.</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00072.jpg"><img class="aligncenter size-large wp-image-1824" title="DSC00072" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00072-1024x768.jpg" alt="" width="640" height="480" /></a></p>
<p>The broken parts found in the rear diff!</p>
<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00073.jpg"><img class="aligncenter size-large wp-image-1825" title="DSC00073" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2012/07/DSC00073-1024x768.jpg" alt="" width="640" height="480" /></a></p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=1816</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pairs! Game version 1 now avaliable!</title>
		<link>https://vince.sparkes.co/blog/?p=56</link>
		<comments>https://vince.sparkes.co/blog/?p=56#comments</comments>
		<pubDate>Thu, 01 Apr 2010 22:31:43 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://vincentsparkes.co.uk/blog/?p=56</guid>
		<description><![CDATA[Finally finished the third assignment for CO520! Pretty proud of it, it has taken so long, it&#8217;s ridiculous! I&#8217;ll put it up for download here after midnight to make sure no sneaky people try to steal it and submit it as their own even though it doesnt come with source code at the moment!]]></description>
				<content:encoded><![CDATA[<p>Finally finished the third assignment for CO520!</p>
<p>Pretty proud of it, it has taken so long, it&#8217;s ridiculous!</p>
<p>I&#8217;ll put it up for download <a href="http://vincentsparkes.co.uk/blog/?page_id=52">here</a> after midnight to make sure no sneaky people try to steal it and submit it as their own even though it doesnt come with source code at the moment!</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=56</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hurray Murray Android App v0.2</title>
		<link>https://vince.sparkes.co/blog/?p=46</link>
		<comments>https://vince.sparkes.co/blog/?p=46#comments</comments>
		<pubDate>Mon, 08 Mar 2010 23:41:49 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Hurry Murray App]]></category>

		<guid isPermaLink="false">http://vincentsparkes.co.uk/blog/?p=46</guid>
		<description><![CDATA[Been pretty busy lately, had a bit more of a bash at the Hurray Murray App. Quick round up: v0.2 is now available on the link on the left! New features, slightly better layout, makes it usable when rotated, icon, clear/reset button, abort button not working, gonna take a bit of effort, but i&#8217;ll get &#8230; <a href="https://vince.sparkes.co/blog/?p=46" class="more-link">Continue reading <span class="screen-reader-text">Hurray Murray Android App v0.2</span></a>]]></description>
				<content:encoded><![CDATA[<p>Been pretty busy lately, had a bit more of a bash at the Hurray Murray App. Quick round up:</p>
<ul>
<li>v0.2 is now available on the link on the left!</li>
<li>New features, slightly better layout, makes it usable when rotated, icon, clear/reset button, abort button not working, gonna take a bit of effort, but i&#8217;ll get there.</li>
<li>Installed the app on a friend&#8217;s HTC Tattoo and it works! Really could do with testing it on a few others but that can wait at the moment.</li>
<li>iPhone version looks like a no go at the moment, installed the iPhone SDK on my recent Snow Leopard installation, did some tuts, doesn&#8217;t appear to be a way to send a text from inside an app on the iPhone, but i&#8217;ll keep looking into it.</li>
<li>Signed up for the Blackberry Developer program, got the kit, another plug in for Eclipse, lovely, will get round to releasing a version for that when I get a bit of free time!</li>
</ul>
<p>So for the time being feel free to look at the updated code and have a play with it and the app!</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=46</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Snow Leopard Finally Working On My EeePC!</title>
		<link>https://vince.sparkes.co/blog/?p=36</link>
		<comments>https://vince.sparkes.co/blog/?p=36#comments</comments>
		<pubDate>Wed, 03 Mar 2010 16:30:07 +0000</pubDate>
		<dc:creator><![CDATA[Vincent]]></dc:creator>
				<category><![CDATA[Hack Book Pro]]></category>

		<guid isPermaLink="false">http://vincentsparkes.co.uk/blog/?p=36</guid>
		<description><![CDATA[After many, many hours of hard work and research I successfully have Mac OS X 10.6 or Snow Leopard, running my eeePc 1000h. How to guide on it&#8217;s way!]]></description>
				<content:encoded><![CDATA[<p><a href="http://vincentsparkes.co.uk/blog/wp-content/uploads/2010/03/IMAG0011.jpg"><img class="size-medium wp-image-33 alignnone" title="eeeMac" src="http://vincentsparkes.co.uk/blog/wp-content/uploads/2010/03/IMAG0011-300x200.jpg" alt="eeeMac" width="300" height="200" /></a></p>
<p>After many, many hours of hard work and research I successfully have Mac OS X 10.6 or Snow Leopard, running my eeePc 1000h.</p>
<p>How to guide on it&#8217;s way!</p>
]]></content:encoded>
			<wfw:commentRss>https://vince.sparkes.co/blog/?feed=rss2&#038;p=36</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
