My RSS Feed https://www.childs.be/plugins/gs-blog/rss.php Welcome to my blog!! Fri, 02 May 2025 11:50:58 +0000 en-gb Quick way to switch to a USB WiFi adaptor on your Raspberry Pi Mon, 27 Jan 2025 12:00:00 +0000 https://www.childs.be/articles/post/quick-way-to-switch-to-a-usb-wifi-adaptor-on-your-raspberry-pi https://www.childs.be/articles/post/quick-way-to-switch-to-a-usb-wifi-adaptor-on-your-raspberry-pi I wrote a long winded guide to this in a previous post, but I've since though of a better way if you already have you onboard WiFi adaptor connected to your network. You also don't need an ethernet connection and can be running headless, simply head over to this directory: cd /etc/NetworkManager/system-connections ls -l you should <p>I wrote a&nbsp;<a href="https://www.childs.be/articles/post/how-to-switch-your-wifi-connection-to-a-usb-wifi-adaptor-on-your-raspberry-pi">long winded guide</a> to this in a previous post, but I've since though of a better way if you already have you onboard WiFi adaptor&nbsp;connected to your network.</p> <p>You also don't need an ethernet connection and can be running headless, simply head over to this directory:</p> <pre>cd /etc/NetworkManager/system-connections ls -l</pre> <p>you should then see a file with you current connection details, it will either be called <tt>preconfigured.nmconnection</tt> if you set it up from the RaspberryPi installer when you created you SD card image or just the SSID of the connection. You may have multiple entries here if you've connected to other networks. Next of your double check the name of your WiFi device by running</p> <pre>ip a s</pre> <p>Your onboard should be <tt>wlan0</tt> and your usb device if it has been recognised would be <kbd>wlan1</kbd>, then we can edit the file</p> <pre>sudo nano preconfigured.nmconnection</pre> <p>and simply add a line '<samp>interface-name=wlan1</samp>' &nbsp;under [connection] to specify the device:</p> <pre>[connection] id=preconfigured uuid=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee type=wifi interface-name=wlan1 [wifi] mode=infrastructure ssid=......</pre> <p>the [Ctrl]+[O] and [Ctrl]+[X] to save and exit, then finally we can reboot</p> <pre>sudo reboot now</pre> <p>Note that you IP address will have probably changed now to if you are SSH'ing on to the device you should use you broadcast hostname (raqspberrypi.local) or hopefully you've pre-configured a static IP address in your router's DCHP or you can just log into your router to check.</p> <p>Either way you whe your system is up we can check the connection:</p> <pre>ip a s</pre> <p>And you should be set.</p> RaspberryPi raspberrypi,wifi,usb,network How to install Filebrowser as a service using www-data as the user on a Raspberry Pi Fri, 17 Jan 2025 20:00:00 +0000 https://www.childs.be/articles/post/how-to-install-filebrowser-as-a-service-using-www-data-as-the-user-on-a-raspberry-pi https://www.childs.be/articles/post/how-to-install-filebrowser-as-a-service-using-www-data-as-the-user-on-a-raspberry-pi Install & testing First we have to set up some folders and download and install filebrowser (change the ip address to that of your rpi and a port of your choosing): cd /opt sudo mkdir filebrowser cd filebrowser curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash sudo filebrowser -r /opt/filebrowser -a 192.168.0.10 <h3>Install &amp; testing</h3> <p>First we have to set up some folders and download and install filebrowser (change the ip address to that of your rpi and a port of your choosing):</p> <pre><code>cd /opt sudo mkdir filebrowser cd filebrowser curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash sudo filebrowser -r /opt/filebrowser -a 192.168.0.10 -p 8083</code></pre> <p>And head over to your browser and hit up 192.168.0.10:8083/ to confirm it's working, you can login with admin:admin</p> <h3>Setting up as a service</h3> <p>If we are happy it's working, return to the command line and cancel (ctrl-C) out of filebrowser, then:</p> <pre>sudo nano filebrowser.json</pre> <p>and paste this configuration:</p> <pre>{ "port": 8083, "baseURL": "", "address": "192.168.0.10", "log": "stdout", "database": "/opt/filebrowser/filebrowser.db", "root": "/var/www/files/" }</pre> <p>Ctrl-O, [enter] and Crtl-X to save and exit, now we can set a few permissions:</p> <pre>cd .. sudo chown pi:www-data -R filebrowser sudo chmod 775 -R filebrowser</pre> <p>This assumes you already have www-data user and group setup and user pi is a member of the www-data group. Now onto setting filebrowser as a service:</p> <pre>sudo nano /etc/systemd/system/filebrowser.service</pre> <p>then paste inthe following:</p> <pre>[Unit] Description=File Browser After=network.target [Service] User=www-data ExecStart=/usr/local/bin/filebrowser -c /opt/filebrowser/filebrowser.json [Install] WantedBy=multi-user.target</pre> <p><kbd>Ctrl-O, [enter] and Crtl-X</kbd> to save and exit, now we can start up the server:</p> <pre>sudo systemctl enable filebrowser.service sudo systemctl start filebrowser.service</pre> <p>give it a few seconds and we can check it's working:</p> <pre>systemctl status filebrowser.service</pre> <p>You don't have to worry about creatng a folder before hand, just create a test/file when you get there so head over to your browser to check it out (and change the password).</p> RaspberryPi filebrowser,raspberrypi,www-data,service,linux How to switch your WiFi connection to a USB WiFi adaptor on your Raspberry Pi Tue, 14 Jan 2025 20:00:00 +0000 https://www.childs.be/articles/post/how-to-switch-your-wifi-connection-to-a-usb-wifi-adaptor-on-your-raspberry-pi https://www.childs.be/articles/post/how-to-switch-your-wifi-connection-to-a-usb-wifi-adaptor-on-your-raspberry-pi Update There's a quicker way if you are running headless and/or already have your Pi connected via WiFi Recently been researching USB WiFi adaptors a for my Pi3 given I just installed a PCIe Intel 8290 on my Lenovo Thinkstation M93a and I'm getting a whopping 780Mb/s connection through my WiFi broadband router. I'm also running out of ethernet <div class="alert alert-success"><strong>Update</strong> <a href="https://www.childs.be/articles/post/quick-way-to-switch-to-a-usb-wifi-adaptor-on-your-raspberry-pi">There's a quicker way if you are running headless and/or already have your Pi connected via WiFi</a></div> <p>Recently been researching USB WiFi adaptors a for my Pi3 given I just installed a PCIe Intel 8290 on my Lenovo Thinkstation M93a and I'm getting a whopping 780Mb/s connection through my WiFi broadband router. I'm also running out of ethernet ports on the router and my preference is to use one for my printer instead of it's onboard WiFi as it nicely WoL. I know the 100Mb/s spped of the ethernet isn't going to slow the Pi down on the web server side of things but it will allow me to site the Raspberry Pi closer to the bluetooth devices it interacts with and will hopefully increase the speeds to my computer. Lets get the current state of affairs:</p> <pre>iwconfig</pre> <p>We see that I'm already connected to my WiFi network using the onboard at a measly 24Mb/s:</p> <pre>mc@RaspberryPi3:~ $ iwconfig lo no wireless extensions. eth0 no wireless extensions. wlan0 IEEE 802.11 ESSID:"MYSSIDNAME" Mode:Managed Frequency:2.437 GHz Access Point: AA:BB:CC:DD:EE:FF Bit Rate=24 Mb/s Tx-Power=31 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:on Link Quality=70/70 Signal level=-37 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:13 Invalid misc:0 Missed beacon:0</pre> <p>I then went ahead and connected my new dongle:</p> <pre>wlan1 IEEE 802.11 ESSID:off/any Mode:Managed Access Point: Not-Associated Tx-Power=3 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:on</pre> <p>Sadly WiFi is still coneected to my onboard adapter. So we can take down the connection by:</p> <pre>sudo ifconfig wlan0 down</pre> <p>Now re can run netowrk-manager's connection UI:</p> <pre>sudo nmtui</pre> <p>To activate the connection:</p> <p><img alt="" src="https://www.childs.be/data/uploads/Cmyo5.png" style="width: 400px; height: 312px; margin: 10px" /></p> <p>And we can see we are now connected:</p> <pre>wlan1 IEEE 802.11 ESSID:"MYSSIDNAME" Mode:Managed Frequency:5.18 GHz Access Point: AA:BB:CC:DD:EE:FF Bit Rate=<span class="marker">780 Mb/s</span> Tx-Power=3 dBm Retry short limit:7 RTS thr:off Fragment thr:off Power Management:on Link Quality=70/70 Signal level=-38 dBm Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0 Tx excessive retries:0 Invalid misc:1 Missed beacon:0 </pre> <p>780Mb/s, nice :-)</p> <p>You can check your WiFi connection scripts here:</p> <pre>/etc/NetworkManager/system-connections/</pre> <p>it'll show you the connection details, you could probably change them both to be wlan1 or even delete one of them.</p> RaspberryPi wifi,raspberrypi,usb,linux,network How to easily broadcast the hostnames of other devices on your network using a RaspberryPi or any linux machine Sat, 11 Jan 2025 00:00:00 +0000 https://www.childs.be/articles/post/how-to-easily-broadcast-the-hostnames-of-other-devices-on-your-network-using-a-raspberrypi-or-any-linux-machine https://www.childs.be/articles/post/how-to-easily-broadcast-the-hostnames-of-other-devices-on-your-network-using-a-raspberrypi-or-any-linux-machine Whenever you read on the internet of how to connect to other devices on your home network using a hostname instead of an IP address when they the machine doesn't broadcast it, you generally get the following two answers: add an entry to your hosts file manually yourself configure your router to send out the name. There's a couple of issues <p><a href="https://www.childs.be/data/uploads/Avahi-logo.svg.png" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/Avahi-logo.svg.png" style="width: 150px; height: 112px; float: right;" /></a>Whenever you read on the internet of how to connect to other devices on your home network using a hostname instead of an IP address when they the machine doesn't broadcast it, you generally get the following two answers:</p> <ul> <li>add an entry to your hosts file manually yourself</li> <li>configure your router to send out the name.</li> </ul> <p>There's a couple of issues with this, firstly I've never owned a router with this functionality and I've never been with an ISP which will even let you use your own router - so that option is out.</p> <p>The other option of entering it manually into your hosts file seems to most including myself seems somewhat of cross purposes as the whole point is that it's all automatic and like most I just never bother.</p> <h3>The solution</h3> <p><big>Somehow it's starting us all in the face - you can piggyback on the Avahi broadcast service your Raspberry Pi or any other linux device is already running. It's not complicated either, just a quick tweak to a file and your done.</big></p> <p>If you don't already have Avahi broadcasting your Raspberry Pi's hostname it's just one command away with no setup:</p> <pre>sudo apt install avahi-daemon</pre> <p>and you are firing out your hostname. Avahi only uses fully qualified domain names which means it has to have some sort of suffix, the default it uses is .local so your raspberrypi will be reachable over the network as <samp>raspberrypi.local</samp> to any machine including macs and Apple devices.</p> <h3>How to broadcast other hostnames</h3> <p>It's easy:</p> <pre>sudo nano /etc/avahi/hosts</pre> <p>then add the IP and hostname you want to broadcast at the bottom, such as:</p> <pre>192.168.0.100 switch.local</pre> <p>Save and exit then restart the daemon:</p> <pre>sudo avahi-daemon restart</pre> <p>In my case it's the old Sky broadband router (SR101) which I've repurposed as an ethernet switch so I can have a wired connection for all my Raspberry Pis seeing as my current router has only two ethernet ports. 192.168.0.100 is it's&nbsp;IP address to which I connect to it's web configuration page so I can now connect to it using it's hostname im my browser</p> <pre>switch.local/</pre> <p>Job's a good 'n.</p> RaspberryPi raspberrypi,hostname,ip,network Fix "-bash: mail: command not found" error on RaspberryPi Thu, 09 Jan 2025 13:00:00 +0000 https://www.childs.be/articles/post/fix-bash-mail-command-not-found-error-on-raspberrypi https://www.childs.be/articles/post/fix-bash-mail-command-not-found-error-on-raspberrypi I don't know if this is related to the other issue I was having with my mailbox not being found which I fixed in the other blog post, but after installing postfix: sudo apt install postfix and correctly configuring the SMTP relay, I could send email using the sendmail function: sendmail youremail@gmail.com Subject: testing does it work! . but <p>I don't know if this is related to the other i<a href="https://www.childs.be/articles/post/fix-cannot-open-mailbox-varmailuser-no-such-file-or-directory-error-message">ssue I was having with my mailbox not being found </a>which I fixed in the other blog post, but after installing <samp>postfix</samp>:</p> <pre>sudo apt install postfix</pre> <p>and correctly configuring the SMTP relay, I could send email using the <samp>sendmail</samp> function:</p> <pre>sendmail youremail@gmail.com Subject: testing does it work! .</pre> <p>but i just couldn't use my normal command mail:</p> <pre>echo "email message text" | mail&nbsp;-s "subject line" "youremail@gmail.com"</pre> <p>which I find far more friendly than the <samp>sendmail</samp> way.</p> <p>anyhow the fix was to install&nbsp;mailutils:</p> <pre>sudo apt install&nbsp;mailutils</pre> <p>works a treat,</p> <p>So if you want to install <samp>postfix</samp> and mutt you should use:</p> <pre>sudo apt install postfix mutt&nbsp;libsasl2-modules&nbsp;mailutils</pre> RaspberryPi raspberrypi,postfix,mailutils Fix "Cannot open mailbox /var/mail/USER: No such file or directory" error message Thu, 09 Jan 2025 12:30:00 +0000 https://www.childs.be/articles/post/fix-cannot-open-mailbox-varmailuser-no-such-file-or-directory-error-message https://www.childs.be/articles/post/fix-cannot-open-mailbox-varmailuser-no-such-file-or-directory-error-message Just installed and configured postfix and mutt on a fresh copy of Raspberry Pi OS Lite, sending of mail was fine but I was having issues with mutt. Don't know whether it was related to my other issue here, but mutt opens but I get the error: Cannot open mailbox /var/mail/pi: No such file or directory Very annoying, its never happened to me <p>Just installed and configured&nbsp;<samp>postfix</samp> and <samp>mutt</samp> on a fresh copy of <a href="https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit">Raspberry Pi OS Lite</a>, sending of mail was fine but I was having issues with <samp>mutt</samp>.</p> <p>Don't know whether it was related to <a href="https://www.childs.be/articles/post/fix-bash-mail-command-not-found-error-on-raspberrypi">my other issue here</a>, but <samp>mutt</samp> opens but I get the error:</p> <pre>Cannot open mailbox /var/mail/pi: No such file or directory</pre> <p>Very annoying, its never happened to me before, and it worked fine on another install last week. There wasn't much help found on the internet but I managed to figure it out pretty quickly:</p> <pre>cd /var/mail sudo touch pi sudo chown pi:mail pi</pre> <p>Obviously you'll need to replace <samp>pi</samp> with your own username and then should be good to go:</p> <pre>mutt</pre> <p>Happy days!</p> RaspberryPi raspberrypi,mailbox,mutt,postfix Install apache php7 mySQL and phpmyadmin on Raspbian Stretch on a RaspberryPi Wed, 15 Nov 2017 08:00:00 +0000 https://www.childs.be/articles/post/how-to-install-lamp-apache-php7-mysql-mariadband-phpmyadmin-on-raspbian-stretch-on-a-raspberrypi https://www.childs.be/articles/post/how-to-install-lamp-apache-php7-mysql-mariadband-phpmyadmin-on-raspbian-stretch-on-a-raspberrypi I've been eagerly awaiting the fourth version of the RaspberryPi for a while, but when it passed the point where I had expected it to be released I googled it only to find that the next incarnation may be a while. Darn it, I have to get anothe RaspberryPi3. So the time has come to commission it and I find the lastest version of Raspian called <p><strong>I&#39;ve been eagerly awaiting the fourth version of the RaspberryPi for a while, but when it passed the point where I had expected it to be released I googled it only to find that the next incarnation may be a while.</strong></p> <p>Darn it, I have to get anothe RaspberryPi3. So the time has come to commission it and I find the lastest version of Raspian called <a href="https://www.raspberrypi.org/blog/raspbian-stretch/">stretch</a> is out and theres been a few other updates. PHP5 has finally been updated and now is now officially available in the 7th flavour having missed out 6 completely - only 7.0 though, no 7.1. MySQL is gone instead being replaced by <a href="https://www.debian.org/releases/stretch/amd64/release-notes/ch-whats-new.html#mariadb-replaces-mysql">MariaDB</a> (think it is just a rebrand though. Still on Apache version 2 though so not everything has changed.</p> <p>No biggie really except all those handy internet how-tos are all out of date so I thought I&#39;d bring you the way I takled it.</p> <p>First off, update everything, you&#39;ll need to be running this in bash or over SSH:</p> <pre>sudo apt-get update -y &amp;&amp; sudo apt-get dist-upgrade -y &amp;&amp; sudo apt-get autoclean &amp;&amp; sudo apt-get autoremove</pre> <p>next up install LAMP:</p> <pre>sudo apt-get install apache2 php7.0 mariadb-server-10.1 </pre> <p>Then PHPmyAdmin:</p> <pre>sudo apt-get install phpmyadmin</pre> <p>Just follow the prompts and teir default setting, I&#39;ve split this part out as I was getting error when I ran it all as one:</p> <pre>ERROR 2002 (HY000): Can&#39;t connect to local MySQL server through socket &#39;/var/run/mysqld/mysqld.sock&#39; (2 &quot;No such file or directory&quot;).</pre> <p>Then type</p> <pre>ifconfig</pre> <p>to get the IP address of the raspberrypi</p> <pre>wlan0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt;&nbsp; mtu 1500 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inet 192.168.0.39&nbsp; netmask 255.255.255.0&nbsp; broadcast 192.168.0.255</pre> <p>After we&#39;ve completed these steps we can head over to a browser on a computer running of the network of you rapberrypi and type and type the following URL out chaning out the IP address you th one you are seeing:</p> <pre>192.168.0.39/phpmyadmin</pre> <p>this should send you over to a page looking something like this:</p> <p><a href="https://www.childs.be/data/uploads/phpmyadmin.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/phpmyadmin.jpg" style="width: 300px; height: 350px;" /></a></p> <p>Bang in the details you entered during setup and Bob&#39;s your uncle.</p> RaspberryPi LAMP,phpmydamin,php7,rpi3 How to enable and change the Remote IR GPIO pin in OSMC Mon, 30 Oct 2017 20:00:00 +0000 https://www.childs.be/articles/post/how-to-enable-and-change-the-remote-ir-gpio-pin-in-osmc https://www.childs.be/articles/post/how-to-enable-and-change-the-remote-ir-gpio-pin-in-osmc So you want to rig up your Raspberry Pi OSMC to be controlled by your favourite remote control, easy peasy - it is just a matter of plugging the IR receiver diode in and swith GPIO on in the settings. Dont like the standard pins 17 or 18, no problem - you can change them at teh same time, just follow these instructions. Go to 'My OSMC, Select 'Pi <p><b>So you want to rig up your Raspberry Pi OSMC to be controlled by your favourite remote control, easy peasy - it is just a matter of plugging the IR receiver diode in and swith GPIO on in the settings.</b></p> <p>Dont like the standard pins 17 or 18, no problem - you can change them at teh same time, just follow these instructions.</p> <p>Go to &#39;My OSMC,</p> <p><a href="https://www.childs.be/data/uploads/gpio-osmc-2.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/gpio-osmc-2.jpg" style="width: 480px; height: 270px; align: left;" /></a></p> <p>Select &#39;Pi Config&#39;</p> <p><a href="https://www.childs.be/data/uploads/gpio-osmc-3.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/gpio-osmc-3.jpg" style="width: 480px; height: 270px; align: left;" /></a></p> <p>Scroll down to &#39;Hardware support&#39; and enable LIRC GPIO:</p> <p><a href="https://www.childs.be/data/uploads/gpio-osmc-5.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/gpio-osmc-5.jpg" style="width: 480px; height: 270px; align: left;" /></a></p> <p>Then select the alternative pins as required</p> <p><a href="https://www.childs.be/data/uploads/gpio-osmc-6.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/gpio-osmc-6.jpg" style="width: 480px; height: 270px; align: left;" /></a></p> <p>I prefer GPIO 4 for the receiver due to it&#39;s proximity to the 3.3v and the GND pins.</p> RaspberryPi raspberrypi,gpio,irremote,osmc Split and extract the first 1000 (N) rows from a text-csv-data file in Windows Thu, 08 Jun 2017 12:00:00 +0000 https://www.childs.be/articles/post/split-and-extract-the-first-1000-n-rows-from-a-text-csv-data-file-in-windows https://www.childs.be/articles/post/split-and-extract-the-first-1000-n-rows-from-a-text-csv-data-file-in-windows One of the major annoyances for me working with very large datasets you get from someone else is that you often don't know the format the file is coming in, not a problem really just take a peak in Notepad++ or Excel and you are away. But quite often these files are millions of rows in length and it is just not possible to work it out. So I've <p><strong>One of the major annoyances for me working with very large datasets you get from someone else is that you often don&#39;t know the format the file is coming in, not a problem really just take a peak in Notepad++ or Excel and you are away. But quite often these files are millions of rows in length and it is just not possible to work it out.</strong></p> <p>So I&#39;ve been trying to chip away at the problem for a while and after I finally got past the first stumbling block of having a computer so lock down I couldn&#39;t do a thing with it I was still coming up a little short.</p> <p>Looking through the defacto bible for any such problem,&nbsp;<a href="http://stackoverflow.com/questions/27932722/extract-n-lines-from-file-using-single-windows-command">Stackoverflow</a>,&nbsp;it&nbsp;looks like powershell&nbsp;is what were after running it from a command prompt:</p> <pre>powershell -command &quot;&amp; {get-content input.txt|select-object -first 10}&quot; &gt;output.txt</pre> <p>However there are few failings here:</p> <ul> <li>we can&#39;t be bothered with all the faff of getting the correct path</li> <li>it actually outputs it through the cmd console before writing it to the file thereby wrapping it the lines at the default width of 80 lines</li> <li>if you have a very large file it will read through the whole serveral Gbs when it doesnt have to</li> </ul> <h3>Drag &#39;n&#39; Drop</h3> <p>We can solve the first problem by creating a drag and drop batch file with the the output file the same as the input but with a predefined suffix, just paste the following code into a file called <code>first_1000_rows.bat</code>:</p> <pre>powershell -command &quot;&amp; {get-content %1|select-object -first 1000}&quot; &gt;%~n1&quot;_1000&quot;%~x1</pre> <p>then all we need to do is to drag the file we want to split and drop it over the batch file and hey presto.</p> <h3>No-wrap</h3> <p>Next task is we have to solve the wrapping issue, a little tweak will see us outputting it as part of the powershell process not through the command console using the <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.0/microsoft.powershell.management/set-content">set-content</a> command:</p> <pre>powershell -command &quot;&amp; {get-content %1|select-object -first 1000|set-content -path %~n1&quot;_1000&quot;%~x1}&quot;</pre> <h3>Optimisation</h3> <p>Finally we&#39;ll make a little tweak to stop after the first end rows, easy when you know how, just set the row limit on the <a href="https://msdn.microsoft.com/en-us/powershell/reference/5.0/microsoft.powershell.management/get-content">get-content</a> command:</p> <pre>powershell -command &quot;&amp; {get-content %1 -TotalCount 1000|set-content -path %~n1&quot;_1000&quot;%~x1}&quot;</pre> <p>Job&#39;s a good-un as the saying goes and now we have an extract of the file we can easily have a butchers at.</p> <h3>Dealing with spaces in paths</h3> <p>Unfortunately the Powershell - DOS interaction doesn&#39;t play nicely with <a href="https://stackoverflow.com/questions/18537098/spaces-cause-split-in-path-with-powershell">spaces</a> so we have to deal with them <a href="https://stackoverflow.com/questions/5034076/what-does-dp0-mean-and-how-does-it-work">somehow</a> as well:</p> <pre>powershell -command &quot;&amp; {get-content &#39;%~1&#39; -TotalCount 1000|set-content -path &#39;%~dp1%~n1_1000%~x1&#39;}&quot;</pre> <h3>Finished</h3> <p>Job&#39;s a good-un as the saying goes and now we have an extract of the file we can easily have a butchers at.</p> RaspberryPi powershell,sql,split,truncate Raspberry Pi 3 HDMI overscan settings and how to correct them Fri, 07 Apr 2017 08:00:00 +0000 https://www.childs.be/articles/post/raspberry-pi-3-hdmi-overscan-settings-and-how-to-correct-them https://www.childs.be/articles/post/raspberry-pi-3-hdmi-overscan-settings-and-how-to-correct-them If you've ever plugged a Raspberry Pi into a tv you've probably come across this issue - the displayed image either doesn't fill the screen or over-runs it. The usual bit of googling reveals that all you have to do is tweak a couple of overscan settings and you are good to go. It sounds easy but three Raspberry Pis in and I've only just found the <p><strong>If you&#39;ve ever plugged a Raspberry Pi into a tv you&#39;ve probably come across this issue - the displayed image either doesn&#39;t fill the screen or over-runs it.</strong></p> <p>The usual bit of googling reveals that all you have to do is tweak a couple of overscan settings and you are good to go. It sounds easy but three Raspberry Pis in and I&#39;ve only just found the technique that lets me fix it before my patience runs out.</p> <p>You&#39;ve probably been persevering down this road quite a while now so I&#39;ll spare you the basics and I will skip to a trick that may save you all the hassle</p> <h3>Change to a different HDMI input on your TV</h3> <p><a href="https://www.childs.be/data/uploads/connections.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/connections.jpg" style="width: 250px; height: 225px; float: right;margin:10px;" /></a>Simple I know, but it actually works a treat, my classic but still great by today&#39;s standards<a href="http://www.trustedreviews.com/samsung-ue32eh5000-review"> Samsung UE32EH5000</a> has two HDMI port with one designated as DVI. My computer has always occupied this slot for no other reason that it uses ATi&#39;s special DVI to HDMI converter that magically passes through the sound as well and I&#39;ve never had reason to change it - fit and forget.</p> <p>It was only since I&#39;ve been testing the dual HDMI capabilities of my graphics card that I&#39;ve had reason to try the other port and in doing so I noticed that the connection through the non DVI designated connector actually overscanned. Hang on a minute, maybe not all HDMI ports are made the same.</p> <p>On hooking my Raspberry Pi up into this socket everything ran swimmingly and and the edge of the screen lined up - magic.</p> <h3>Try my settings</h3> <p>If you don&#39;t have a fangled HDMI(DVI) port then you could have a crack at my settings. I actually came up with these before I knew about the trick above (but I am not bitter). In your terminal/SSH window type</p> <pre>sudo nano /boot/config.txt</pre> <p>then uncomment/add/change the below lines:</p> <pre>disable_overscan=1 overscan_left=39 overscan_right=39 overscan_top=25 overscan_bottom=23 framebuffer_width=1920 framebuffer_height=1080 hdmi_group=1 hdmi_mode=16</pre> <p>save the file with ctrl+o then exit with ctrl+x and reboot</p> <pre>sudo reboot now</pre> <p>to see if it has solved your woes. My settings above are actually a bit of an overkill and I&#39;m sure I don&#39;t need all of them but I&#39;m sticking with them at this moment because I done with fiddling with them for the moment.</p> <h3>How to tweak it yourself with this foolproof method</h3> <p>If my settings don&#39;t help you out here is my foolproof guide to getting it sorted. First up fire up PiXel of X with this command if you are not already in the desktop:</p> <pre>startx</pre> <p><a href="https://www.childs.be/data/uploads/pixel-vnc.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/pixel-vnc.jpg" style="width: 300px; height: 253px; float: right; margin: 10px;" /></a>Next we are going you&#39;ll need a bit of underscan going on - can you see all of the screen in your TV/monitor - you can tell this by observing your cursor.Take a close look at the on screen pointer, but default it is white surrounded by a black border then another white outline of pixels. Move the pointer to the edges of your screen.</p> <p>Left most and upper screen edges you should always be able to see the whole of pointer, to the left you should only see a vertical line of white pixels and on the lower edge you should only see a single dot of the tip.</p> <p>If you can&#39;t see em go back to your config.txt and fiddle with the settings until you can (I&#39;ll skip this step as you&#39;ve probably very up on how to get the wrong settings by now!).</p> <p>Now all you have to do it reboot and re-tweak the settings until the edges of the pointer just creep off the screen and then bring them back one pixel.</p> <p>I know it is tedious but it is the only reliable way I&#39;ve found to resolve and your OCD will be put at ease.</p> RaspberryPi raspberrypi,overscan,hdmi,tv SSL on a RaspberryPi - does it slow your site down? Wed, 22 Mar 2017 08:00:00 +0000 https://www.childs.be/articles/post/ssl-on-a-raspberrypi-does-it-slow-your-site-down https://www.childs.be/articles/post/ssl-on-a-raspberrypi-does-it-slow-your-site-down First up I'm sorry about bathering on about this SSH thing but I to be honest I'm padding out the blog posts a little bit as there's one article I've written that I'm just not sure I want to publish, It's nothing bad, just not in keeping with the tone of this site so I've racked it up at the end of the post ready to go and keep adding posts in <p><strong><a href="https://www.childs.be/data/uploads/ssl-3.png"><img alt="" src="https://www.childs.be/data/uploads/ssl-3.png" style="width: 200px; height: 230px; float: right;margin:10px" /></a>First up I&#39;m sorry about bathering on about this SSH thing but I to be honest I&#39;m padding out the blog posts a little bit as there&#39;s one article I&#39;ve written that I&#39;m just not sure I want to publish, It&#39;s nothing bad, just not in keeping with the tone of this site so I&#39;ve racked it up at the end of the post ready to go and keep adding posts in front of it.</strong></p> <p>Not that this is not an unimportant poin, it was a question I was pondered for a while - I wasn&#39;t sure if I wanted to invest in the purchase of a SSL certificate when all I&#39;d end up doing was to slow the serving of my pages down.</p> <p>Well, now I&#39;ve taken the plunge, read about <a href="https://www.childs.be/blog/post/free-letsencrypt-secure-ssl-server-certificate-install-tutorial-for-raspberry-pi">how to install a free SSL certificate on a RaspberryPi here</a>:</p> <p>What I can confirm (I should have tested load times before or after but I didn&#39;t think about it), it that I actually think my server runs faster, and I&#39;m using one of the original <a href="https://www.childs.be/blog/post/the-raspberry-pi-is-alive">RaspberryPi Model B</a>!</p> <div class="alert alert-success">A SLL certificate doesn&#39;t noticeably slow my RaspberryPi webserver down.</div> RaspberryPi SSL,https,raspberrypi Remove Real VNC from RaspberryPi Pixel and install TightVNC Tue, 14 Mar 2017 20:00:00 +0000 https://www.childs.be/articles/post/remove-real-vnc-from-raspberrypi-pixel-and-install-tightvnc https://www.childs.be/articles/post/remove-real-vnc-from-raspberrypi-pixel-and-install-tightvnc I came across my old shortcut on my windows machine to vnc onto the Pi which prompted me to have a go connecting to my new RaspberryPi3. I duly fired it up only to receive an error message along the lines of 'No configured security type is supported'. After a bit of research it turns out that RealVNC has upped their security protocols and TightVNC <p><strong><a href="https://www.childs.be/data/uploads/pixel-vnc.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/pixel-vnc.jpg" style="width: 350px; height: 295px; float: right;margin:10px" /></a>I came across my old shortcut on my windows machine to vnc onto the Pi which prompted me to have a go connecting to my new RaspberryPi3.</strong></p> <p>I duly fired it up only to receive an error message along the lines of &#39;No configured security type is supported&#39;. After a bit of research it turns out that RealVNC has upped their security protocols and TightVNC is no longer cross-compatible.</p> <p>No probs I thought - juust install the RealVNC viewer on my windows pc and give it a crack that way. I&#39;ve never really been a fan of RealVNC, but you know it&#39;s been over a decade now and I&#39;m not that set in my ways that I can&#39;t change so I installed it to see whats new.</p> <p>Turns out there a lot new! Some crappy licensing scheme whereby you have to sign into an account through their website before you vnc onto anything. This is not a grteat user experience and it&#39;s not in the RaspberryPi&#39;s way of doing things eother. So it has to go.</p> <h3>Remove RealVNC</h3> <p>If you want to do away with it also, just follow these instructions, in terminal or over SSH:</p> <pre>dpkg --get-selections | grep vnc</pre> <p>this will show you what the name of the package is you need to install, then un-install it:</p> <pre>sudo apt-get remove realvnc-vnc-server</pre> <h3>Install TightVNC</h3> <p>Then we can move on to getting tightvnc installed</p> <pre>sudo apt-get install tightvncserver</pre> <p>then run it to configure it</p> <pre>tightvncserver</pre> <p>once you&#39;ve set up some options/passwords it will then start an instance for you, we&#39;ll go ahead and kill it then start up a new one with a better/your own resolution</p> <pre>vncserver -kill :1 vncserver :1 -geometry 1024x1024 -depth 24</pre> <h3>Connect</h3> <p>you can now connect using the hostname/ip of your pi from your viewer</p> <pre>raspberrypi3:1</pre> <h3>Autostart</h3> <p>to start the server everytime you boot your pi, you can do the following:</p> <pre>sudo nano /etc/rc.local</pre> <p>then type in</p> <pre>echo &quot;Starting VNC server on port 5901&quot; sudo -u pi tightvncserver :1</pre> <p><tt>ctrl+o</tt>, <tt>enter</tt> and <tt>ctrl+x</tt> to save and exit.</p> RaspberryPi realvnc,tightvnc,vnc,pixel Running a SSL certificated/authenticated HTTPS website over dynamic DNS Mon, 06 Mar 2017 08:00:00 +0000 https://www.childs.be/articles/post/running-a-ssl-certificatedauthenticated-https-website-over-dynamic-dns https://www.childs.be/articles/post/running-a-ssl-certificatedauthenticated-https-website-over-dynamic-dns One of reasons why I originally held back on buying a SSL certificate for my website was that I wasn't sure that it'd work using a dynamic IP routing service - cos I didn't want to waste $15! Well you don't need to fret about it because I can confirm it works after I eventually got round to setting up a free LetsEncrypt.org one on my <p><strong><a href="https://www.childs.be/data/uploads/secure.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/secure.jpg" style="width: 235px; height: 130px; float: right;padding: 10px;" /></a>One of reasons why I originally held back on buying a SSL certificate for my website was that I wasn&#39;t sure that it&#39;d work using a dynamic IP routing service - cos I didn&#39;t want to waste $15!</strong></p> <p>Well you don&#39;t need to fret about it because I can confirm it works after I eventually got round to setting up a free LetsEncrypt.org one on my RaspberryPi.</p> <p>Now you&#39;ve got the answer, why don&#39;t you head over to my tutorial of how it&#39;s done.</p> <p><a href="https://www.childs.be/blog/post/free-letsencrypt-secure-ssl-server-certificate-install-tutorial-for-raspberry-pi">Free LetsEncrypt secure SSL server certificate install tutorial for Raspberry Pi</a></p> <div class="alert alert-success">Yes, SSL certificates work with dynamically routed domains on dynamic IP adresses.</div> <p>&nbsp;</p> RaspberryPi dynamicdns,ssl,website,https Free LetsEncrypt secure SSL server certificate install tutorial for Raspberry Pi Sat, 18 Feb 2017 08:00:00 +0000 https://www.childs.be/articles/post/free-letsencrypt-secure-ssl-server-certificate-install-tutorial-for-raspberry-pi https://www.childs.be/articles/post/free-letsencrypt-secure-ssl-server-certificate-install-tutorial-for-raspberry-pi For me being SSL secured has always been the benchmark as having a bonafide website. That little green padlock next to your websites URL doesn't really mean much for a blog, but I always wanted one. At the start of last year I started thing about trying to get one. Ever being a skinflint I wanted to pay nothing for it, but logic overcame <p><strong><a href="https://www.childs.be/data/uploads/secure.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/secure.jpg" style="width: 235px; height: 130px; padding: 10px; float: right;" /></a>For me&nbsp;</strong><strong>being SSL secured</strong><strong>&nbsp;has always been the benchmark as having a bonafide website. That little green padlock next to your websites URL doesn&#39;t really mean much for a blog, but I always wanted one. At the start of last year I started thing about trying to get one.</strong></p> <p>Ever being a skinflint I wanted to pay nothing for it, but logic overcame this thinking as all the free ones either had massive catches that you had to manually renew them every thirty days or they were so free that browsers just didn&#39;t rattify them as being legit.</p> <p>I&#39;d decided at this point to drop the princely sum of $15 on a three year Comodo certificate from <a href="https://www.ssls.com/ssl-certificates/comodo-positivessl">these guys</a>. There was a possible stitch up of evorbadent fees come renewal time but my limited research showed up that like car insurance you just go somewhere else to pick up a bargain price again.</p> <p>Roll on one year and I still hadn&#39;t got round to doing it but in my quest to re-find where I&#39;d intended to buy when I came across <a href="https://letsencrypt.org/">LetsEncrypt.org</a>, free, auto-renewing and recognised by all the major browers - cool!</p> <p>So I&#39;ll crack on with how to get it on your machine in not time at all....</p> <h3>Instructions</h3> <p>So before we start, check the version of the operating system you are running as the install instructions do vary:</p> <pre>cat /etc/os-release</pre> <h3>Certbot</h3> <p>My RaspberryPi Model B is running wheezy so the install instructions from the&nbsp;<a href="https://certbot.eff.org/all-instructions/#debian-7-wheezy-apache">Certbot wesite</a> gives this this (check the rest of the page in the link for instructions for your OS if different):</p> <pre>wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto</pre> <h3>Authentification</h3> <p>There are two ways for you to prove ownership of the website:</p> <ul> <li>let Certbot automatically authenticate it by launching a standalone server temporarily &nbsp;</li> <li>or setting up a directory for it to place some files temporarily</li> </ul> <p>I did try the former byrunning the command</p> <pre>./certbot-auto</pre> <p>But for some reason I got an error back that there was already a server running on port 443 - fairly obvious really, and I would have thought that it could automatically stop the apache server for a moment to enable it to complete seeing as it&#39;d have to in the future to renew your licences. Having read back the instruction in writing this post perhaps I should have added a <code>--apache</code> switch, but too late now...</p> <h3>Webroot</h3> <p>As I said, the other method requires use of an available folder to serve up some files, as my website runs some pretty comprehensive Rewrites chances of it working were slim so after a quick google showed up this set-up in Apache&#39;s <code>generic.conf</code> - should be handy for me to be able to quickly get certificates to my other hosted sites later if all goes well. Here is the code you&#39;ll need to add for a <a href="https://community.letsencrypt.org/t/apache-multidomain-webroot/10663/2">multisite</a> webroot. To add it, fire up the config with:</p> <pre>sudo nano /etc/apache2/conf.d/generic.conf</pre> <p>and add this code:</p> <pre>Alias /.well-known/acme-challenge/ /var/www/html/.well-known/acme-challenge/ &lt;Directory &quot;/var/www/html/.well-known/acme-challenge/&quot;&gt; &nbsp;&nbsp;&nbsp; Options None &nbsp;&nbsp;&nbsp; AllowOverride None &nbsp;&nbsp;&nbsp; ForceType text/plain &nbsp;&nbsp;&nbsp; RedirectMatch 404 &quot;^(?!/\\\\.well-known/acme-challenge/[\\\\w-]{43}$)&quot; &lt;/Directory&gt;</pre> <p>To save and exit <tt>ctrl+o</tt>, enter then <tt>ctrl+x</tt>. Make sure to change the path to wherever your website is served from in then above then you&#39;ll have to reload to apache config at this point to go ahead and and run:</p> <pre>sudo service apache reload</pre> <p>then we can get on with running Certbot and following the instructions:</p> <pre>./certbot-auto certonly</pre> <p>all was reported back as having successfully completed after a short time so good to go.</p> <h3>Certificate install</h3> <p>This is the bit of the process that took the longest for me - I&#39;ll admit most of it was user error! I have been runnig a server on port 443 with a snakeoil certificate for my admin login portal for a while and it has to be said the the default apache host script for it is rather lengthly so it took a bit of head scratching before I realised that I was still getting &#39;get me out of here&#39; messages from my browser was that I hadn&#39;t removed all of the code from my previous config.</p> <p>To add it to apache&#39;s default config, :&nbsp;</p> <pre>sudo nano /etc/apache2/sites-available/default-ssl</pre> <p>update with the locations of your <a href="https://community.letsencrypt.org/t/apache-configuration-example/2338">certificates</a>:</p> <pre>SSLEngine on SSLCertificateFile&nbsp;&nbsp;&nbsp; /etc/letsencrypt/live/yourdomain.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem</pre> <p>reload apache&#39;s config:</p> <pre>sudo service apache reload</pre> <p>And head over to your site to see if it working. If it is not working at this point then check your site at this handy website for diagnostics on your auth status:</p> <p><a href="https://www.digicert.com/help/">https://www.digicert.com/help/</a></p> <h3>Renewal</h3> <p>Add <a href="https://forum.seafile.com/t/tutorial-for-using-free-ssl-tls-certificates-provided-by-letsencrypt/215">cron job</a> to auto renew</p> <pre>crontab -e </pre> <p>then add this</p> <p># Renew letsencrypt certificate 31 3 * * * /home/pi/bin/certbot/certbot-auto renew --quiet --no-self-upgrade --post-hook &quot;sudo service apache2 reload&quot;</p> <p>then we are all done, I&#39;ve still got a couple of months to wait to see of it actually workks, but stay posted and I&#39;ll let you know.</p> <h3>Additional domains</h3> <p>I was actually so pleased with the results that I went straight ahead and added my other domain philfish.co.uk to the certificate as well, I can report that the multiple webroot worked a charm and the whole process was finished in a couple of minutes just with the <code>--expand</code> switch with this bit of <a href="http://stackoverflow.com/questions/38302401/letsencrypt-add-domain-to-existing-certificate">code</a>.</p> <p>&nbsp;</p> <p>&nbsp;</p> RaspberryPi SSL,https,letsencrypt,apache,certificate How to make a clock for a raspberry pi with an OLED display Fri, 10 Feb 2017 08:00:00 +0000 https://www.childs.be/articles/post/how-to-make-an-clock-for-a-raspberry-pi-with-an-oled-display https://www.childs.be/articles/post/how-to-make-an-clock-for-a-raspberry-pi-with-an-oled-display My dream RaspberryPi project that I am slowly chipping away at is to create the ultimate alarm clock. It is a slow burner though as at it's inception I had none of the skills I needed to pull it off. I've now amassed all of the technical skills to pull it off and I'm just left with finalising the design and finding the time and the parts (not a <p><strong><a href="https://www.childs.be/data/uploads/DSC_1851.JPG" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/DSC_1851.JPG" style="width: 400px; height: 266px; float: right; padding: 10px;" /></a>My dream RaspberryPi project that I am slowly chipping away at is to create the ultimate alarm clock. It is a slow burner though as at it's inception I had none of the skills I needed to pull it off.</strong></p> <p>I've now amassed all of the technical skills to pull it off and I'm just left with finalising the design and finding the time and the parts (not a lot then!).</p> <p>An interim project along the way is whipping together the first prototype of the time display re-using some of the parts from an old Arduino project.</p> <h3>What you need</h3> <p>Pretty easy, you don't not a lot is required, obviously you'll need a:</p> <ul> <li>OLED display</li> </ul> <p>There is a range of available units in different colours and with different pin-outs. This tutorial is based on these are the instructions for the four pin variety - <code>vin</code>, <code>sda</code>, <code>scl</code> &amp; <code>gnd</code>.</p> <p>Some have five or more including <code>rst</code> but they'll require different libraries to the ones we'll be using here so I wouldn't go for one of those. Just head over to ebay and search for 'oled i2c' and for between £2 and £7 you'll be in business. I'd go for one with the header pins already soldiered for you as if you haven't got a soldering iron it will be a massive inconvenience.</p> <p>You will also need either:</p> <ul> <li>a bread board and 4 male/female breadboard wires;</li> <li>or 4 female/female breadboard wires.</li> </ul> <h3>Install the software</h3> <p>First up we'll update you RaspberryPi with the required packages, hopefully you are familiar with either the terminal window or SSH, I won't go through them here we will just crack straight on with it</p> <p>we'll be downloading packages to download projects from Github, Python and I2C:</p> <pre>sudo apt-get install git-core sudo apt-get install python python-dev python-setuptools sudo easy_install Pillow sudo apt-get install python3 python3-dev python3-setuptools sudo easy_install3 Pillow sudo apt-get install python-imaging python-smbus i2c-tools</pre> <p>I've included both Python 2 &amp; 3 here but you only really need one of them if you are short on space.</p> <h3>Libraries</h3> <p>Here we are going to create a folder in you'r home directory and download the python libraries we'll need to operate the display, these are the main display calls, a funky font which looks just like an LCD display and some code so we can run the scripts in the background as a system service (as I describe in <a href="https://www.childs.be/blog/post/how-to-run-a-python-script-as-a-service-in-background-as-a-daemon">this tutorial</a>)</p> <pre>cd ~ mkdir oled cd oled git clone&nbsp;https://github.com/BLavery/lib_oled96.git git clone&nbsp;https://github.com/keshikan/DSEG.git git clone https://github.com/metachris/python-posix-daemon.git git clone https://github.com/mc3k/OLED-Clock.git cp&nbsp;</pre> <h3>Wire up the pi</h3> <p>Probably the most daunting bit, but in the big scheme of GPIO this is about as simple as it gets - just refer to the&nbsp;</p> <p>Obviously the usual disclaimer applies - if you electrocute yourself, blow up you RPI or burn your house down - don't come to me with your law suit; you need consult a someone who is fully trained up in electronics to guide you through it if you are unsure about any aspect of what you are doing regardless of what I've written!</p> <p>Legalities out of the way, you just need to connect the four pins of your display to their corresponding pins on the pi - consult the header labels on your OLED with the pinout diagram. It is pretty straightforward in this case as they are all grouped together at the end of the header. The VCC pin can usually be connected to either 3.3v of 5v in the case of this component but check your specs to make sure.</p> <p><strong>Wiring diagram</strong></p> <p><a href="https://www.childs.be/data/uploads/OLED-clock_bb.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/OLED-clock_bb.jpg" style="width: 400px; height: 200px;margin: 10px" /></a></p> <p><strong>Pinout diagram</strong></p> <p>For the RPI2 &amp; 3, if you have a different version consult the relevant diagram for your model.</p> <p><a href="https://www.childs.be/data/uploads/RP2_Pinout.jpg" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/RP2_Pinout.jpg" style="width: 442px; height: 264px;padding:10px" /></a></p> <p>After you have checked and&nbsp;</p> <h3>Finalise the Pi setup</h3> <pre>sudo&nbsp;raspi-config</pre> <p>and enable i2c in the advanced menu, then reboot and <a href="https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c">see </a>if we can detect the screen:</p> <pre>sudo reboot sudo i2cdetect -y 1</pre> <p>after the last command you will get a readout telling you that your pi has picked up your display:</p> <pre>&nbsp; &nbsp; &nbsp;0&nbsp; 1&nbsp; 2&nbsp; 3&nbsp; 4&nbsp; 5&nbsp; 6&nbsp; 7&nbsp; 8&nbsp; 9&nbsp; a&nbsp; b&nbsp; c&nbsp; d&nbsp; e&nbsp; f 00:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --</pre> <p>You can see mine here popping up a 3c</p> <h3>Lets start the coding</h3> <p>So now we've got all the pre-requisites out of the way we can get on with firing up the display and getting coding. The way we'll go about it is to grab the various files we need from the libraries and copy them into the working directory.</p> <p>I'm doing it this way to keep it simple as there's an overwelming amount of files knocking about in the subfolders.</p> <p>First up is the OLED library and some bare bones code to get us started</p> <pre>cd /home/pi/oled cp lib_oled96/lib_oled96.py . cp OLED-Clock/python/clock-min.py .</pre> <p>then we can fire the script up to see if it works</p> <pre>python clock-min.py</pre> <p>hopefully you should be seeing the display pumping out the time and date along with a the time scrolling up on the command prompt. Jobs a good-un.</p> <p>To cancel just hit <code>ctrl+c</code>.</p> <p>If you want to have a look at the code just use the following command:</p> <pre>nano clock-min.py</pre> <p>Next up is a more fancy looking script:</p> <pre>cp lib_oled96/FreeSans.ttf . cp OLED_Clock/python/clock.py . python clock.py</pre> <p>The third is has a more traditional look of an LCD clock, this one also only updates once a minute instead of once per second - I've not test the performance overhead of these script but it may have less overhead:&nbsp;</p> <pre>cp DSEG/fonts/DSEG7-Modern/DSEG7Modern-Bold.ttf . cp OLED-Clock/python/clock-dseg.py . python clock-dseg.py .</pre> <h3>Running as a background service</h3> <p>As good as these scripts are they are pretty useless in their current state &nbsp;as they tie up the terminal/SSH session stopping you working and quitting the python job if you exit them. So what we need is to run them as a background service, fortunately this is pretty easy when you know how, first off copy the files:</p> <pre>cp python-posix-daemon/src/daemon2x.py . cp OLED-Clock/python/clock-dseg-d.py . cp OLED-Clock/python/clock-d.py .</pre> <p>We can start and stop the clock with these commands:</p> <pre>python clock-d.py start python clock-d.py stop python clock-dseg-d.py start python clock-dseg-d.py stop</pre> <p>As you see you it doesn't hog the bash prompt and you can even quit your terminal / SSH session.</p> <h3>Starting at boot</h3> <p>if you want to run the script at boot you'll need to</p> <pre>sudo nano /etc/rc.local</pre> <p>then type in</p> <pre># Start the OLED Clock if [ 'i2cdetect -y 1 | grep 3c' ];&nbsp; then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "Starting python logging daemon\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sudo python /home/pi/oled/clock-d.py start; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo "no"; fi;</pre> <h3>Further reading</h3> <p>there are some bits of code to embelish your project <a href="https://www.raspberrypi.org/forums/viewtopic.php?f=46&amp;t=150342">here</a>&nbsp;adding the ability to display a various number of different system parameters, I've programmed a number of them here:</p> <pre>OLED-Clock/system.py</pre> RaspberryPi OLED,display,raspberrypi,GPIO,python How to run a python script as a service / in background / as a daemon Thu, 02 Feb 2017 08:00:00 +0000 https://www.childs.be/articles/post/how-to-run-a-python-script-as-a-service-in-background-as-a-daemon https://www.childs.be/articles/post/how-to-run-a-python-script-as-a-service-in-background-as-a-daemon So you've written a killer python script and you want to run it in the background as a service because when you close the terminal window/SSH session it kills it. I originally worked it out when I wrote my Twitterbot app, and was going to write it up seperately then but it took me so long to get it running in the background and I tried so may <p><strong><a href="https://www.childs.be/data/uploads/opengraph-icon-200x200.png"><img alt="" src="https://www.childs.be/data/uploads/opengraph-icon-200x200.png" style="width: 150px; height: 150px; padding: 10px; float: right;" /></a>So you've written a killer python script and you want to run it in the background as a service because when you close the terminal window/SSH session it kills it. I originally worked it out when I wrote my <a href="https://www.childs.be/blog/post/how-to-make-set-up-a-twitter-bot-on-your-own-server-raspberry-pi">Twitterbot app</a>, and was going to write it up seperately then but it took me so long to get it running in the background and I tried so may things that I couldn't actually tell you how I eventually managed it!</strong></p> <p>It was only as I was working on my new project - an OLED clock for my new mediacentre pi that I finally worked out how easy it actually was; here are the instructions.</p> <p>First we'll get the code using a terminal window or SSH:</p> <pre>cd ~ git clone&nbsp;https://github.com/metachris/python-posix-daemon.git cd python-posix-daemon/scr ls</pre> <p>so you'll see the three files which do the business:</p> <pre>daemon2x.py daemon3x.py daemon-example.py</pre> <p>you'll obviously need python at this point tp do anything so I'll assume you have this, we can try the provided example file to see if everything is working:</p> <pre>python&nbsp;daemon-example.py start</pre> <p>and&nbsp;</p> <pre>python daemon-example.py stop</pre> <p>to stop it.</p> <p>At this point you'll notice that nothing really happened - thats because the sample dosen't actually do anything, we can have a look by openeing the file</p> <pre>nano&nbsp;daemon-example.py</pre> <p>it just sleeps for 1 second and then repeats.</p> <p>If you want to see an example of a script that does something you can use my example:</p> <script src="https://gist.github.com/mc3k/0d0f19d6a92387d2b564cbaec3cdcc54.js"></script> <p>It creates a log file ant writes the time to it every two seconds. Download the script:</p> <pre>wget&nbsp;https://gist.githubusercontent.com/mc3k/0d0f19d6a92387d2b564cbaec3cdcc54/raw/80a8a462de179dc7a0f359ac1a860a4d2e39b2d0/daemon-example2.py</pre> <p>and start it:</p> <pre>sudo python daemon-example2.py start</pre> <p>leave it for and few seconds then stop it:</p> <pre>sudo python daemon-example2.py stop</pre> <p>we can see the results using:</p> <pre>cat /var/log/daemon-example.log</pre> <p>and there you have it, everything is easy when you know how. If you want to put it in you library then you just need to put it in a python <a href="http://stackoverflow.com/questions/897792/pythons-sys-path-value">sys path</a>.</p> <p>if you want to run the script at boot you'll need to</p> <pre>sudo nano /etc/rc.local</pre> <p>then type in</p> <pre>echo "Starting python logging daemon" sudo python /home/pi/python-posix-daemon/scr/daemon-example2.py start</pre> <p>but I wouldn't recommend it for this script.</p> RaspberryPi pthython,script,backgroup,daemon,service How to pivot data by month in SQL and output to a temporary table Wed, 28 Dec 2016 08:00:00 +0000 https://www.childs.be/articles/post/how-to-pivot-data-by-month-in-sql-and-output-to-a-temporary-table https://www.childs.be/articles/post/how-to-pivot-data-by-month-in-sql-and-output-to-a-temporary-table There are some things that aren't easy to do in SQL as you'd like. I don't know why it has to make the seemingly simple things to complete in Excel so annoyingly tricky. Dynamic pivots is one of those things that is overcomplicated, sure there's plenty of tutorials on the t'internet , but what they all seem to lack is instructions of how to write <p><strong><img alt="" src="https://www.childs.be/data/uploads/sqlpivot.jpg" style="width: 300px; height: 231px; float: right; margin: 10px;" />There are some things that aren&#39;t easy to do in SQL as you&#39;d like. I don&#39;t know why it has to make the seemingly simple things to complete in Excel so annoyingly tricky. </strong></p> <p>Dynamic pivots is one of those things that is overcomplicated, sure there&#39;s plenty of tutorials on the t&#39;internet , but what they all seem to lack is instructions of how to write them to a temporary table, I&#39;m a big fan of temp tables in my workflows and on this occasion google has been drawing blanks.</p> <p>So if you are struggling to work it out you have to use a global temporary table as EXEC command you run actually uses a different process so your process won&#39;t see it after it has run. I also had a couple of attemps to get it in the right place - SQL isn&#39;t really helpful in this respect either - the code highlighting doesn&#39;t extend that far.</p> <p>Anyway, I&#39;ll get to the example so you can see for yourself:</p> <pre>Print &#39;Pivot transactions&#39; begin try drop table <strong>##mcTemp1</strong> end try begin catch end catch DECLARE @ColumnName AS NVARCHAR(MAX) DECLARE @Qry AS NVARCHAR(MAX) DECLARE @FromDate AS NVARCHAR(MAX) DECLARE @ToDate AS NVARCHAR(MAX) Set @ToDate=&#39;2015-10-31&#39; Set @FromDate=DateAdd(MONTH,-24,@ToDate)+1 SELECT @ColumnName= ISNULL(@ColumnName + &#39;,&#39;,&#39;&#39;) + QUOTENAME(Month) FROM (SELECT DISTINCT Convert(Date,[PAY_DATE]-DAY([PAY_DATE])+1) AS &#39;Month&#39; FROM [WHS_PAYMENT_HISTORY] WHERE PAY_DATE between @FromDate and @ToDate) AS Months ORDER BY MONTH Set @Qry = N&#39;SELECT ACCOUNT_NUMBER,&#39;+@ColumnName +&#39; <strong>INTO ##mcTemp1</strong> from ( SELECT ACCOUNT_NUMBER, [PAY_DATE]-DAY([PAY_DATE])+1 AS &#39;&#39;Month&#39;&#39; ,[PAY_VAL] As Payment FROM [WHS_PAYMENT_HISTORY] WITH(NOLOCK) WHERE PAY_DATE between &#39;&#39;&#39; + @FromDate + &#39;&#39;&#39; and &#39;&#39;&#39; + @ToDate + &#39;&#39;&#39; ) pd pivot ( SUM([Payment]) FOR [Month] in (&#39; + @ColumnName+&#39;) ) As Pvt&#39; EXEC sp_executesql @Qry SELECT * FROM ##mcTemp1 </pre> <p>&nbsp;</p> RaspberryPi SQL,pivot How to set up your Dell E310dw printer the really easy, bloat free way on windows Fri, 02 Dec 2016 08:00:00 +0000 https://www.childs.be/articles/post/how-to-set-up-your-dell-e310dw-printer-the-really-easy-bloat-free-way-on-windows https://www.childs.be/articles/post/how-to-set-up-your-dell-e310dw-printer-the-really-easy-bloat-free-way-on-windows One of the common themes of the computer industry is to try to install a load of bloat on your computer under the guise of making it easier for you, well when I first got my Dell E310dw and had a flick through the setup guide to head off any such shinangans I noticed they had some sort of 'universal' installer. Trying not to fall for that I <p><strong><a href="https://www.childs.be/data/uploads/725312-720904-800.jpg" id="fb" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/725312-720904-800.jpg" style="width: 200px; height: 150px; float: right; margin: 10px;" /></a>One of the common themes of the computer industry is to try to install a load of bloat on your computer under the guise of making it easier for you, well when I first got my Dell E310dw and had a flick through the setup guide to head off any such shinangans I noticed they had some sort of &#39;universal&#39; installer.</strong></p> <p>Trying not to fall for that I steamed ahead to wing it myself, turned out to be pretty easy really, just follow these steps:</p> <ol> <li>Unbox</li> <li>plug in ethernet cable from printer to router</li> <li>turn on</li> </ol> <p><strong>That&#39;s it, seriously!</strong> I went to the &#39;Devices and Pirnters&#39; screen in Windows 10 to go and try to install it as a network printer and it was the already waiting to go.</p> <p>I didn&#39;t actually believe it so I fired of a test page and it printed - magic!</p> <p>One of the option I was missing though was the booklet print option, so if you want to get to all the advanced settings you do need to install the dell drivers. You can do that easily&nbsp;</p> <ol> <li>Go to the <a href="http://www.dell.com/support/home/us/en/04/product-support/servicetag/B59R132/drivers">Dell download page</a> for the printer</li> <li>Download the latest Windows driver and unzip it</li> <li>Search for device &#39;Device Manager&#39; in the start menu</li> <li>Expand the printer option and right click on &#39;Dell Printer E310dw&#39;</li> <li>Click update Driver Software</li> <li>then &#39;Browse my computer for driver software&#39;</li> <li>then &#39;Let me pick from a list of drivers on my computer&#39;</li> <li>then the &#39;Have Disk&#39; button</li> <li>Then navigate to where you unpacked the divers and follow it through Drivers/PCL/32_64 and select&nbsp;DLOHL13A.INF</li> </ol> <p>Then you are good to go, fire up the printer properties pages and you get:</p> <p><a href="https://www.childs.be/data/uploads/Dell-E310dw-prefs.jpg" id="fb" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/Dell-E310dw-prefs.jpg" style="width: 400px; height: 251px; margin: 10px;" /></a></p> <p>For extra enjoyment, fire up you web browser and make your way over to the IP address of your printer and you&#39;ll find yourself up to you neck every option and bit of info you could think of including Google&#39;s Cloud print gubbings.</p> RaspberryPi dell,printer,windows,e310dw,bloatware,install How to install Dell Printer E310dw on your Raspberry Pi Thu, 24 Nov 2016 08:00:00 +0000 https://www.childs.be/articles/post/how-to-install-dell-printer-e310dw-on-your-raspberry-pi https://www.childs.be/articles/post/how-to-install-dell-printer-e310dw-on-your-raspberry-pi I'm always one for saving a bit of money and many years ago I came up with the plan that I could save a lot of money in printing costs if I didn't own a printer. It is a great idea, you'd be suprised at how much unnecessary printing you get up to and there's always the kick in the teeth of inkjet printer ink being more expensive than <p><strong>I&#39;m always one for saving a bit of money and many years ago I came up with the plan that I could save a lot of money in printing costs if I didn&#39;t own a printer. It is a great idea, you&#39;d be suprised at how much unnecessary printing you get up to and there&#39;s always the kick in the teeth of inkjet printer ink being more expensive than gold!</strong></p> <p>However, ever since I learned how you could refill some laser toner cartridges for next to nothing, I&#39;ve always wanted one of Brother&#39;s epic little mono laser printers. Over the years I&#39;ve been watching them add features such as the fully enclosed paper cartridge, ethernet conectivity and even WiFi.</p> <p>So when it came to our trip to Cambodia I had to bite the bullet as we were travelling around a bit we had far too many hotel, bus, tours, boat rides and flights that it was going to be a logistical nightmare to beg, steal and borrow printing capbility.</p> <p><a href="https://www.childs.be/data/uploads/692646-720904-800.jpg" id="fb" rel="fb"><img alt="" src="https://www.childs.be/data/uploads/692646-720904-800.jpg" style="width: 400px; height: 346px; float: right; margin:10px;" /></a>I was initially going to get on of the aforementioned Brother HL-L2XXX models, but a quick perusal on ebuyer.com sees that the ethernet version is the thick end of &pound;80. They did however have a seemingly better, wireless enabled Dell E310dw for a measly &pound;30. The reviews looked good and a new Dell high yield toner cartrtidge was only the same price as the extra the Brother would cost to buy + the cost of a refill kit. So if I couldn&#39;t refill the cartrigde I would be no worse off.</p> <p>So I took the plunge and couldn&#39;t be happier, I can print my favoured booklet print and the printer was super easy to set up without installing any bloatware.</p> <p>When it came to installing the printer on the raspberry pi it got a little trickier, Dell does list it as being linux compatible but only actually supplies it with drivers for Ubuntu. I tried a few of the tutorials of installing generic PCL drivers, i386 drivers and a bunch of other stuff but to no avail.</p> <p>It was during my scratching around the internet that I actually discovered that my Dell E310dw was actually a <a href="http://www.hotukdeals.com/deals/dell-e310dw-a4-wireless-mono-laser-printer-with-duplex-35-99-ebuyer-2507284">rebranded Brother HL-L2360</a>, magic. Unfortunatley there ain&#39;t no Brother Raspberry Pi either driver either but a bit of uncovering later led me to another option:</p> <ul> <li>Install CUPS on your Pi using these instructions</li> </ul> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.howtogeek.com/169679/how-to-add-a-printer-to-your-raspberry-pi-or-other-linux-computer/">http://www.howtogeek.com/169679/how-to-add-a-printer-to-your-raspberry-pi-or-other-linux-computer/</a></p> <ul> <li>Add printer by clicking the button on the administration webpage and when you get to the diver selection <a href="https://www.raspberrypi.org/forums/viewtopic.php?f=91&amp;t=109609">list</a>, go for:</li> </ul> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Brother &#39;HL-7050N-CUPS+Gutenprint&#39;</p> <p>Et voila.</p> <p>To test it out, set it as your default printer in the administration tab and then try this bit of <a href="http://askubuntu.com/questions/432746/print-from-command-line">code</a>:</p> <pre>echo &quot;test&quot; | lp</pre> RaspberryPi dell,printer,raspberrypi,e310dw,brother,install The easy way to find and delete duplicates in SQL Fri, 03 Jun 2016 08:00:00 +0000 https://www.childs.be/articles/post/the-easy-way-to-find-and-delete-duplicates-in-sql https://www.childs.be/articles/post/the-easy-way-to-find-and-delete-duplicates-in-sql Next in my series of helpful SQL code is duplicates, I seem to always be having issues with duplicates. This annoys me immensely as all of the issues comes from other peoples data I have to work with. No problem I hear you say, google is awash with ways of how to delete them. Trouble is these are all based on blindly deleting superfluous rows <p><strong>Next in my <a href="https://www.childs.be/blog/tag/SQL">series of helpful SQL code</a> is duplicates, I seem to always be having issues with duplicates. This annoys me immensely as all of the issues comes from other peoples data I have to work with.</strong></p> <p>No problem I hear you say, google is awash with ways of how to delete them. Trouble is these are all based on blindly deleting superfluous rows without care of how they got there and any specific criteria on the order of how to delete them.</p> <h3>Identifying duplicates</h3> <p>First up is you have to identify the duplicates in order to understand why they are duplicated in the first place, using this nufty bit of code we can pull up a table only containing the <a href="http://stackoverflow.com/questions/2112618/finding-duplicate-rows-in-sql-server">duplicates</a>:</p> <pre>select * from [#Table1] where [Person] in ( SELECT [Person] FROM [#Table1] group by [Person] HAVING (COUNT(*) &gt; 1) )</pre> <h3>Deleting rows</h3> <p>Having checked the duplicates we can proceed to getting rid of them. If the entries are pure duplicates and we just want to delete the extra we have two ways of proceeding. We can either</p> <ul> <li>delete the duplicates in situe or</li> <li>or filter out the duplicates in a query</li> </ul> <h4>Delete duplicates from a table</h4> <p>Firstly we add an automatically incrementing number field to the table, then delete the record that is not the first occurrence of item in the selected <a href="http://www.codeproject.com/Articles/157977/Remove-Duplicate-Rows-from-a-Table-in-SQL-Server">field</a>:</p> <pre>ALTER TABLE [#Table1] ADD AUTOID INT IDENTITY(1,1) DELETE FROM [#Table1] WHERE AUTOID NOT IN (SELECT MIN(AUTOID) FROM [#Table1] GROUP BY [Person]) </pre> <p>Nice and straight forward.</p> <h4>Filter out duplicates in a query</h4> <p>The trick with this one is that you just have to group by all the fields you want to un-duplicate, though this is invariably all of them!</p> <pre>select AccNo, Person, Bikes from #table1 group by AccNo, Person, Bikes</pre> <p>What you have to remember is that you need to know which fields are duplicated in the first place.</p> <h3>Smart deletion of duplicate records</h3> <p>This is the scenario where we&#39;ve looked at the duplicates and decided the course of action needed to weed out the duplicates. This is usually to route out the oldest date or the lowest values, this is the solution you need - sort the dataset into a new table then go ahead and delete the superfluous rows:</p> <pre>select * into #Table2 from #Table1 order by [Date1] desc, [Field1] asc ALTER TABLE #Table2 ADD AUTOID INT IDENTITY(1,1) DELETE FROM #Table2 WHERE AUTOID NOT IN (SELECT MIN(AUTOID) FROM #Table2 GROUP BY [Person]) ALTER TABLE #Table1 drop column AUTOID</pre> <p>Now all we need to do is get people to check their data for duplicates before they send it to save us hours of work!</p> RaspberryPi SQL,duplicates,dedup How to add an auto incrementing ID field in SQL server Thu, 12 May 2016 08:00:00 +0000 https://www.childs.be/articles/post/how-to-add-an-auto-incrementing-id-field-in-sql-server https://www.childs.be/articles/post/how-to-add-an-auto-incrementing-id-field-in-sql-server So it turns out that SQL is really quick to pick up, once you have the (very) basics down everything you need to do fall intuitively into place as it is all based on the first principals of a select statement. And even if you do get stuck all answers are a very rapid google search. The biggest trouble I have with starting off programming any new <p><strong>So it turns out that SQL is really quick to pick up, once you have the (very) basics down everything you need to do fall intuitively into place as it is all based on the first principals of a select statement. And even if you do get stuck all answers are a very rapid google search.</strong></p> <p>The biggest trouble I have with starting off programming any new languages is that I expect to hit the ground running and just jump into the complex stuff without going through the basic tutorials. THe problem with this is it can them be tricky to actually google the right term to get the answer to your problem. So in light of this I&#39;ve decided to log all the little bits and bobs which fall into this category as I come across them.</p> <p>So stay tuned for further posts in the series under tag <a href="https://www.childs.be/blog/tag/SQL">SQL</a>.</p> <p>One of the first things which fell into this category were row numbers. The normal way people tell you to deal with this it is to append a table with a new column with the row numbers in. Nice and easy:</p> <pre>ALTER TABLE #Table ADD AUTOID INT IDENTITY(1,1)</pre> <p>This is all well and good but what I need most regularly is to add row numbers into outputs of queries as I run them, I don&#39;t want to have to write the results to a table then append the row number on. Fortunately the code is simple and it will also let you order the results at the same <a href="http://stackoverflow.com/questions/961007/how-do-i-use-row-number">time</a>&nbsp;by using the <span style="font-family:courier new,courier,monospace;">OVER </span>function:</p> <pre>Print&#39;Add row numbers to an output&#39; select ROW_NUMBER() over (order by [FirstColumn]) as AUTOID , * from #Table</pre> RaspberryPi SQL,number,code How to add better comments into SQL server Tue, 26 Apr 2016 20:00:00 +0000 https://www.childs.be/articles/post/how-to-add-better-comments-into-sql-server https://www.childs.be/articles/post/how-to-add-better-comments-into-sql-server Whilst I'm firmly in the 'Tried and Test' camp for most things in life and I may only be new to SQL programming but there are just sometimes when I have to buck the mainstream trend and do it my way. One of these occasions is comments in SQL, the widely adopted way would be to use the prescribed double dash -- or the widely adopted across multiple <p><strong>Whilst I&#39;m firmly in the &#39;Tried and Test&#39; camp for most things in life and I may only be new to SQL programming but there are just sometimes when I have to buck the mainstream trend and do it my way.</strong></p> <p>One of these occasions is comments in SQL, the widely adopted way would be to use the prescribed double dash -- or the widely adopted across multiple languages slash-star:</p> <pre>-- comment here /* another type of comment */</pre> <p>However in this instance I&#39;m going to declare my way is best! I put my comments into a print statement (not in the middle of the code obviously)</p> <pre>Print&#39;Comment here&#39; Then code</pre> <p>Not only does it stand out better in your code editor&#39;s syntax highlighter but it makes the messages log more verbose when you are debugging or reconciling record numbers throughout your scripts.</p> RaspberryPi SQL,comment,code How to connect a photoresistor or light dependant resistor to an ESP8266-12E Fri, 01 Jan 2016 20:00:00 +0000 https://www.childs.be/articles/post/how-to-connect-a-photoresistor-or-light-dependant-resistor-to-an-esp8266-12e https://www.childs.be/articles/post/how-to-connect-a-photoresistor-or-light-dependant-resistor-to-an-esp8266-12e Having purchased my first Raspberry Pi a couple of years ago now I've still not got round to implementing some Internet of Things (IoT). The trouble was that I wasn't really convinced it was suitable for the job as I wanted something able to be battery operated to work in remote situations as the power draw was just too great. I liked the idea of <p><strong><img alt="" src="https://www.childs.be/data/uploads/NodeMCU_DEVKIT_1.0.jpg" style="width: 350px; height: 233px; float: right; margin: 10px;" />Having purchased my first Raspberry Pi a couple of years ago now I&#39;ve still not got round to implementing some Internet of Things (IoT). The trouble was that I wasn&#39;t really convinced it was suitable for the job as I wanted something able to be battery operated to work in remote situations as the power draw was just too great.</strong></p> <p>I liked the idea of the Arduino stuff but it was as expensive as RaspberryPis once you&#39;ve hooked it up with wifi and the like.</p> <p>A couple of weeks ago I stumbled across the awesome ESP8266 boards - just what I was looking for. Small, inexpensive and had wifi and an antenna built in. When I say inexpensive I really do mean it you can get going for just a couple of quid.</p> <p>For my first foray into the scene I opted for a <a href="https://github.com/nodemcu/nodemcu-devkit-v1.0">NodeMCU v1.0 development board</a> as it has a USB connection for uploading firmware and power and if you buy a slim one you can connect it to a breadboard for prototyping.</p> <p>I already own the <a href="http://camjam.me/?page_id=623">CamJam EduKit 2 - Sensors</a> lying around as I hadn&#39;t yet got round to hooking it up the Pi but I wanted to try it out on the &nbsp;ESP8266-12E. Trouble is there doesn&#39;t seem to be any decent instructions on the internet of how to hook up the light dependant resistor. After a bit of scratching around I found out the required resistor (10k ohm) and a circuit diagram from <a href="http://arduino-er.blogspot.co.uk/2014/08/arduino-example-self-adjust-analogread.html">here</a> and I was away.</p> <h2>What you need</h2> <p>List of parts required:</p> <ul> <li>ESP8266</li> <li>LDR / photoresistor</li> <li>10k ohm resistor</li> <li>breadboard</li> <li>computer with Arduino IDE with ESP8266 library installed</li> <li>USB cable</li> <li>Male-Male Dupont/breadboard wires</li> </ul> <h2>Circuit Diagram</h2> <p>The LDR actually has a an analogue output so it gets connected to the A0 pin. Quite simple really, just wire your prototype up like this:</p> <p><img alt="" src="https://www.childs.be/data/uploads/Light_bb.jpg" style="width: 500px; margin: 10px; height: 350px;" /></p> <p>&nbsp;</p> <h2>The code</h2> <p>Simple really, we will just use the example code in the Arduino IDE - go to</p> <p><strong>File/Examples/1.0Basics/ReadAnalogueVoltage</strong></p> <pre>// the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float voltage = sensorValue * (5.0 / 1023.0); // print out the value you read: Serial.println(voltage); }</pre> <h2>The output</h2> <p>All we need to do next is to fire up the serial monitor, select 9600 baud and watch away:</p> <pre>2.16 2.13 2.09 2.07 2.06 2.04 2.03 2.02 2.01 2.00 2.03 2.09 2.15 2.18 </pre> <p>You can also use the serial plotter to see a graph of your results:</p> <p><img alt="" src="https://www.childs.be/data/uploads/SerialMonitor.jpg" style="width: 400px; height: 333px;" /></p> <h2>Next...</h2> <p>You are then ready to integrate it into your own project.</p> RaspberryPi esp8266-12e,ldr,breadbord,lightdependantresistor,arduinoide,photoresistor Best way to optimise images and pictures to display on the web Thu, 19 Nov 2015 08:00:00 +0000 https://www.childs.be/articles/post/best-way-to-optimise-images-and-pictures-to-display-on-the-web https://www.childs.be/articles/post/best-way-to-optimise-images-and-pictures-to-display-on-the-web Conscious that hosting a website from a home internet connection from the Raspberry Pi may lead to slower load time than you'd want I've been working on speeding up its response. I've always been focused on server speed throughout its whole development in a bid to speed up load times. I think I've got it cracked – but the only thing I'm <p>Conscious that hosting a website from a home internet connection from the Raspberry Pi may lead to slower load time than you&#39;d want I&#39;ve been working on speeding up its response.</p> <p>I&#39;ve always been focused on server speed throughout its whole development in a bid to speed up load times. I think I&#39;ve got it cracked &ndash; but the only thing I&#39;m lacking is a decent workflow for optimising the file size of the images I&#39;m serving up.</p> <p>I played around with a few web and windows tools but the process all seemed to be time consuming and cumbersome.</p> <h3><strong>IrfanVIew</strong></h3> <p>After a while I settled upon an add in from a tried and tested bit of software that I&#39;ve been using since I can remember - IrfanView using the &#39;Save for web&#39; plugin. It is easy, quick and also tune-able whilst also providing a live view of what the output would look like.</p> <p>It is actually really quick if you&#39;ve associated it to automatically open image files, my workflow was to drop the required image into the folder on the web-server, hit enter, select the save for web - the GUI pops up and you just hit save to overwrite the file with the optimsed settings.</p> <p>The results were good, I was getting some good file size reductions. Although it doesn&#39;t take too long what is really needed is some automated way to transform your image in a single click.</p> <h3>ImageMagik</h3> <p>I&#39;ve been a user of imagemagick for a while now so this was my first port of call in testing. After a bit of playing around I soon realized that all I needed was to to just change the quality to 70. Easy peasy, just need to run the following code and you are done:</p> <pre>convert sample.jpg -quality 70 output.jpg</pre> <p>Note for windows users, if you try and run convert.exe without specifying a path the the executable it won&#39;t work, this is because there&#39;s another convert.exe system file which it uses in preference. To fix this I simply rename it to img_convert.exe and dump it into my windows directory. The code would now be</p> <pre>convert sample.jpg -quality 70 output.jpg</pre> <h3>Exiftool</h3> <p>The next trick is to remove all of the EXIF metadata attached to the image, you wouldn&#39;t probably think it isn&#39;t many bytes worth but a) they all add up and b) you&#39;d be suprised how much info the modern digital camera now spits out.</p> <p>So go ahead and install a Exiftool on you system and run the following code:</p> <pre>exiftool -all= output.jpg -overwrite_original -P</pre> <h3>Bringing it all together</h3> <p>Now all we have to do is clobber the code together and we are away.</p> <h4>Linux</h4> <p>go ahead and create a new file:</p> <pre>nano optimiser.sh</pre> <p>and paste the following code in:</p> <pre>convert $1 -quality 70 $2 &amp;&amp; exiftool -all= $2 -overwrite_original -q</pre> <p>we then have to make it executable with:</p> <pre>chmod +x optimiser.sh</pre> <p>and now we can run it using:</p> <pre>optimser.sh input.jpg output.jpg</pre> <h4>Windows</h4> <p>It is a similar story for windows, just create a file called</p> <pre>optimser.bat</pre> <p>open in notepad and paste the following:</p> <pre>img_convert %1 -quality 70 %2 exiftool -all= %1 -overwrite_original -P </pre> <p>Drag &amp; Drop</p> <p>With windows we can add an extra flourish - you can set up the batch file so that you can optimise your jpg by just dragging the image on the .bat and it will convert it automatically in the GUI without going near a command prompt:</p> <p>Create a new file:</p> <pre>optimiser_DD.bat</pre> <p>and enter this code:</p> <pre>@echo off copy %1 %~n1&quot;_&quot;%~x1 img_convert %1 -quality 70 %1 exiftool -all= %1 -overwrite_original -P</pre> <p>What the code does here is to copy the input.jpg to input_.jpg then optimise the original file.</p> <h3>The results</h3> <p>I was quite impressed by the results, I tried it on a plethera of files. The most notable reductions come from digicam images, here&#39;s a typical example</p> <pre>Original digicam jpg: 2843 kb Reduced to quality 70: 650kb then exif info removed: 595kb</pre> <div class="alert alert-success">As we can see, the reduction is an impressive 79% reduction.</div> <h3>Extra credit</h3> <p>Head over to GitHub for the extended versions of the scripts with multiple command line options which gives you control of the quality parameters and lets you also resize the image:</p> <p><a href="https://github.com/mc3k/web-optimiser">Web image optimiser on GitHub</a></p> <p>&nbsp;</p> RaspberryPi optimise,jpg,convert,exiftool,imagemagick,exif How to create real time graphs of CPU temperature on a Raspberry Pi Tue, 03 Nov 2015 08:00:00 +0000 https://www.childs.be/articles/post/how-to-create-real-time-graphs-of-cpu-temperature-on-a-raspberry-pi https://www.childs.be/articles/post/how-to-create-real-time-graphs-of-cpu-temperature-on-a-raspberry-pi Probably heavily linked with my inner analyst, for a while now I've wanted to create some real-time graphing of some of my raspberry pi stats. I've had a couple of stabs at it but getting it to actually work has eluded me until now. The below example guides you through how to plot your CPU temp as a graph to an image file, the code is in my github <p><strong>Probably heavily linked with my inner analyst, for a while now I&#39;ve wanted to create some real-time graphing of some of my raspberry pi stats. I&#39;ve had a couple of stabs at it but getting it to actually work has eluded me until now.</strong></p> <p>The below example guides you through how to plot your CPU temp as a graph to an image file, the code is in my github repository where I&#39;ll hopefully add further functionality in the future.</p> <h3>How to guide</h3> <p>First off you need to install Python3</p> <pre>sudo apt-get install python3 sudo apt-get install python-setuptools sudo apt-get install python3-pip</pre> <p>Next install GNUPlot</p> <pre>sudo apt-get install gnuplot-x11</pre> <p>Then we need to setup a working directory:</p> <pre>cd ~ mkdir plottemp cd plottemp</pre> <p>create the necessary files:</p> <pre>nano datagen.py</pre> <p>Paste in the following code:</p> <pre>#!/usr/bin/env python import sys, os, logging, urllib, datetime def fetchtemp(): cmd = &#39;/opt/vc/bin/vcgencmd measure_temp&#39; line = os.popen(cmd).readline().strip() output = line.split(&#39;=&#39;)[1].split(&quot;&#39;&quot;)[0]#+&#39; C&#39; return output format = &quot;%Y-%m-%d,%H:%M:%S&quot; today = datetime.datetime.today() s = today.strftime(format) output = s+&#39; &#39;+fetchtemp()+&#39;\\n&#39; print(output) with open(&#39;/home/pi/plottemp/tempdata.dat&#39;, &#39;a&#39;) as f: f.write(output)</pre> <p>Create this also</p> <pre>nano plottemp.sh</pre> <p>and paste the following:</p> <pre>#!/bin/bash echo &quot;set terminal png size 900, 300 set xdata time set xrange [ time(0) - 86400 : time(0) ]&nbsp;&nbsp;&nbsp; # 86400 sec = 1 day set timefmt &#39;%Y-%m-%d,%H:%M:%S&#39; set format x &#39;%H:%M&#39; set output &#39;/home/pi/plottemp/tempplot.png&#39; plot &#39;/home/pi/plottemp/tempdata.dat&#39; using 1:2 with lines&quot; | gnuplot</pre> <p>make it executable</p> <pre>chmod +x plottemp.sh</pre> <p>next all we have to do is to run the script every 5 minutes (or whatever interval you choose) with cron:</p> <pre>crontab -e</pre> <p>and add this line:</p> <pre>*/5 * * * * python3 /home/pi/plottemp/datagen.py &amp;&amp; /home/pi/plottemp/plottemp.sh &amp;&gt; /dev/null</pre> <p>and there we have it, it will generate a file called:</p> <pre>plottemp.png</pre> <h3>The result</h3> <p>If you have successfully implemented the instructions you should get something like this:</p> <p><a href="https://www.childs.be/data/uploads/plottemp.png" id="fb"><img alt="" src="https://www.childs.be/data/uploads/plottemp.png" style="width: 600px; height: 200px; margin:10px;" /></a></p> <h3>How it works</h3> <p>I&#39;ll very briefly walk you through how it works - there&#39;s a cron job running every five minutes which firstly runs a command line function which reports the CPU temp and saves it to a log file. Upon completion it then runs a GNUPlot command to generate a graph of the last 24 hours logging.</p> <h3>For extra credit</h3> <p>There will be a few formatting tweaks to the graph to come and I hope to include more stats so stay tuned folks!</p> <div class="alert alert-success">You can head over to my <a href="https://github.com/mc3k/graph-stats">graph-stats</a> Git repository for latest updates with extra embellishments</div> <p>Its thanks to this post at <a href="http://www.raspberrypi-spy.co.uk/2014/04/how-to-use-gnuplot-to-graph-data-on-the-raspberry-pi/">raspberrypi-spy</a> which eventually got me on my way. Thanks Matt</p> RaspberryPi plot,graph,cputemp,raspberrypi,gnuplot How to make and set up a twitter bot on your own server / Raspberry Pi Sun, 12 Jul 2015 08:00:00 +0000 https://www.childs.be/articles/post/how-to-make-set-up-a-twitter-bot-on-your-own-server-raspberry-pi https://www.childs.be/articles/post/how-to-make-set-up-a-twitter-bot-on-your-own-server-raspberry-pi As a follow up from my ealier post introducing my twitter bot I thought I'd tell you how I did it and how to set one up on you own RaspberryPi or other Linux server. How it works It's not that tricky when you think it through, it is just hooking a few existing processes together to create your working bot. The only real tricky part for me was that <p><strong><a href="https://www.childs.be/data/uploads/twitter-bot-icon.png" id="fb"><img alt="" src="https://www.childs.be/data/uploads/twitter-bot-icon.png" style="width: 192px; height: 192px; float: right; margin: 10px;" /></a>As a follow up from my ealier post introducing my twitter bot I thought I&#39;d tell you how I did it and how to set one up on you own RaspberryPi or other Linux server.</strong></p> <h3>How it works</h3> <p>It&#39;s not that tricky when you think it through, it is just hooking a few existing processes together to create your working bot. The only real tricky part for me was that I hadn&#39;t used Python before and had to learn it from scatch!</p> <p>Here&#39;s a quick run through of what I used:</p> <p><strong><a href="https://twitter.com/">Twitter</a> API</strong> - stating the obvious really but you need to use the api to do anything on twitter!</p> <p><strong><a href="https://github.com/ryanmcgrath/twython">Twython</a></strong> - a Python wrapper for the the twitter API, it takes all the hard work out of posting and reading tweets</p> <p><a href="https://www.python.org/"><strong>Python3</strong></a> - you&#39;ll need to do all your programming in python to make use of the Twython</p> <p><strong><a href="http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/">Python daemon</a></strong> - for running you script as in the background as a service</p> <p><strong><a href="https://www.wolframalpha.com/">Wolfram|Alpha</a> API</strong> - to answer questions</p> <p><strong><a href="https://en.wikipedia.org">Wikipedia</a> API</strong> - to get more answers</p> <p>&nbsp;</p> <h3>What you need to do</h3> <p>There is quite a lot of things to cover here so I&#39;ll not go into much detail about those tasks which are easy to complete with a little googling and I&#39;ll concentrate on the things which I struggled with.</p> <h4>Twitter</h4> <p>First off you&#39;ll need a twitter account, I started a new one just for my RaspberryPi to tweet from. Then you&#39;ll need to go ahead and create an app within your twitter account and generate some keys for use with the API.</p> <h4>Wolfram|Alpha</h4> <p>Same here, open an account and set up an app to get an API key</p> <h4>Set up your RPI</h4> <p><strong>Folder</strong></p> <p>You&#39;ll need a folder to put all your code in, I set mine up in a directory in my home drive, something like:</p> <pre>/home/usr/pi/bin/tweeter</pre> <p>Use these commands to get you going:</p> <pre>cd ~ md bin cd bin md tweeter cd tweeter</pre> <p><strong>Daemon service</strong></p> <p>Next up you need to download the Daemon class suitable for Python 3.x - <a href="http://www.jejik.com/files/examples/daemon3x.py">daemon3x.py</a> script and save it in the directory. You can do this in command prompt:</p> <pre>wget http://www.jejik.com/files/examples/daemon3x.py</pre> <p><strong>Install Python3</strong></p> <p>run the following in the command prompt:</p> <pre>sudo apt-get update sudo apt-get install python3</pre> <p><strong>Install Twython</strong></p> <p>run this from the command prompt:</p> <pre>sudo apt-get update sudo apt-get install python-setuptools sudo easy_install pip sudo pip install twython</pre> <p><strong>Install my tweetbot script</strong></p> <p>Download <a href="https://www.childs.be/data/uploads/tweetbot-d.py">tweetbot-d.py</a> and save it to your directory.</p> <pre>wget https://www.childs.be/data/uploads/tweetbot-d.py</pre> <p>Or you can get hold of the code over at GitHub:</p> <p><a href="https://github.com/mc3k/tweetbot">tweetbot code GitHub</a></p> <p>Open it up in your favourite text editor and add in your API keys for Twitter and Wolfram|Alpha, then change the twitter ID of the stream you want to follow and additionally the superuser id which will enable you to turn the tweetbot off remotely should you need to:</p> <pre>nano tweetbod-d.py</pre> <p>Save and exit:</p> <pre>Ctrl+O Ctrl+X</pre> <p>&nbsp;</p> <h3>Fire up your tweetbot</h3> <p>We should now be ready to start it up, you can use the following commands to start, stop and restart the bot</p> <pre>python3 tweetbot-d.py start python3 tweetbot-d.py stop python3 tweetbot-d.py restart</pre> <p><strong>Logging</strong></p> <p>By default the script will log all activity from the bot to a file named</p> <pre>tweetbot.log</pre> <p>you can check on everything your tweetbot has been up to in this file:</p> <pre>nano tweetbot.log</pre> <p><strong>Start the tweetbot when your Pi boots up</strong></p> <p>If you want to start the bot up automatically when the server boots up follow these commands:</p> <pre>sudo nano /etc/rc.local</pre> <p>then add these lines (obviously change the directory to the one you have saved your script in)</p> <pre># Start tweetbot service echo &quot;Starting tweetbot script&quot; python3 /home/pi/bin/tweeter/tweetbot-d.py start</pre> <p>&nbsp;</p> <h3>Using the tweetbot</h3> <p>The script runs in the background monitoring any tweet containing your @twitter_handle, it then kicks in to analyse the content of the tweet, on discovery of the following hashtags:</p> <pre>#cputemp #uptime</pre> <p>it will run a run some command line code to reply back to the user with the appropriate answer. On detection of:</p> <pre>#question</pre> <p>it will run a search through Wolfram|Alpha of the rest of the text in the tweet and reply with the answer. If Wolfram doesn&#39;t come back with anything it will try wikipedia as well.</p> <p>Should you need to turn the twitterbot off for some reason when you can&#39;t access the Pi by usual means there is a kill switch built in. Simply tweet:</p> <pre>#stoptweeting</pre> <p>from your specified superuser account and the tweetbot will shut itself down.</p> <p>&nbsp;</p> RaspberryPi raspberrypi,twitter,wikipedia,tweet,bot,wolframalpha The blog has now reached 50 posts! Tue, 02 Jun 2015 08:00:00 +0000 https://www.childs.be/articles/post/the-blog-has-now-reached-50-posts https://www.childs.be/articles/post/the-blog-has-now-reached-50-posts Well, I didn't think I had it in me to write so much, I'm generally not a person with much to say (this is a lot for me!). My general interest in all things tech had always since the early days compelled me to want to make my own website, trouble is you actually need to have some content to put on it. After a while toiling I'd decided that I'd <p><strong><img alt="" src="https://www.childs.be/data/uploads/50-today.jpg" style="width: 173px; height: 229px; float: right; margin: 10px;" />Well, I didn&#39;t think I had it in me to write so much, I&#39;m generally not a person with much to say (this is a lot for me!).</strong></p> <p>My general interest in all things tech had always since the early days compelled me to want to make my own website, trouble is you actually need to have some content to put on it.</p> <p>After a while toiling I&#39;d decided that I&#39;d like to use Blogger and write posts about excel. Great, I thought I was onto something here. I knocked my <a href="https://www.childs.be/blog/post/excel-unhide-all-sheets">first</a> <a href="https://www.childs.be/blog/post/excel-calculating-pi">two</a> posts out on the same day in 2008 (I&#39;ve re-published them on this site), but my third took another 6 months to appear then nothing after that.</p> <p>It was then another five years before I blogged again, this is when I had the idea that I could blog about my <a href="https://www.childs.be/cycle_link/">favorite bike rides</a>. Great as this also gave me the green light to get a <a href="https://www.childs.be/raspberry-pi/">RaspberryPi</a> - I had always wanted one but couldn&#39;t really justify it as I had really got a use for it.</p> <p>Now I was on, hosting my own web server and knocking up my own site. Ali weren&#39;t so happy in the early days - apart from cycling, eating and working I did little else (not much sleep either) as I had a lot on my plate. I&#39;d previously only lightly tinkered with Linux and I&#39;d yet to write a line of php so there was a lot to learn.</p> <p>It actually turns out that I had much more than bike rides to share (its all relative - much for me isn&#39;t that much), and hopefully I&#39;ve another 50 more posts in me. I don&#39;t think I&#39;ve a novel or even a short story in me, and I think there&#39;s zero hope of an autobiography!</p> RaspberryPi 50,today,blog,RPI The childs.be twitterbot is alive Sun, 17 May 2015 08:00:00 +0000 https://www.childs.be/articles/post/the-childsbe-twitterbot-is-alive https://www.childs.be/articles/post/the-childsbe-twitterbot-is-alive My latest project is now live, the @childs_be twitterbot is a go. The original idea was to have the pi tweet pictures from the barrelcam, at regular intervals. I had that running quite quickly and my attentions turned to adding functionality. I came up with being able to tweet the server's uptime and cpu temperature, but it seemed a bit lame <p><strong><a href="https://www.childs.be/data/uploads/twitter-bot-icon.png" id="fb"><img alt="" src="https://www.childs.be/data/uploads/twitter-bot-icon.png" style="width: 192px; height: 192px; float: right; margin:10px;" /></a>My latest project is now live, the <a href="https://twitter.com/childs_be">@childs_be</a> twitterbot is a go.</strong></p> <p>The original idea was to have the pi tweet pictures from the barrelcam, at regular intervals. I had that running quite quickly and my attentions turned to adding functionality.</p> <p>I came up with being able to tweet the server&#39;s <a href="https://www.childs.be/blog/post/display-your-server-uptime-on-your-website">uptime</a> and cpu temperature, but it seemed a bit lame really. So some more thinking later I decided that it would have to be interactive.</p> <p>So the idea of the twitterbot was born (OK, it&#39;s not the most original idea but hey). A few late nights and head scrathing later I had it up and running.</p> <p>In the initial version I&#39;d integrated all the functionality to automatically reply to a mentioned tweet, you can try it yourself by tweeting the Pi with these:</p> <pre>@childs_be #cputemp @childs_be #uptime @childs_be #barrelcam</pre> <p>or you can even string them <a href="https://twitter.com/martychilds/status/597061099658354688">altogether</a>:</p> <pre>@childs_be #cputemp #uptime #barrelcam</pre> <p>Heres an <a href="https://www.childs.be/data/uploads/tweetbot-twitter.jpg" id="fb">example output</a>.</p> <h4>Ask a question</h4> <p>Wanting to build on the functionality my thoughts turned to being able to respond to anything, so by hooking into to both <a href="https://www.wolframalpha.com/">Wolfram|Alpha</a> &amp; <a href="https://en.wikipedia.org">Wikipedia</a>&#39;s APIs I&#39;m now able to answer questions about a broad range of topics, you can try it youyself:</p> <pre>@childs_be #question what is a bicycle</pre> <p>Take a look at my post of how I did it and <a href="https://www.childs.be/blog/post/how-to-make-set-up-a-twitter-bot-on-your-own-server-raspberry-pi">how you can run your own tweetbot</a>.</p> <p>&nbsp;</p> RaspberryPi twitter,bot,uptime,cpu,temp,tweet,alive Display your server uptime on your website Thu, 23 Apr 2015 15:00:00 +0000 https://www.childs.be/articles/post/display-your-server-uptime-on-your-website https://www.childs.be/articles/post/display-your-server-uptime-on-your-website If you host your own server and website like myself, you'll probably want to distplay your current uptime somewhere on your site. You are in luck, it is easy.... It uses the Linux command uptime and strips the unecessary gubbins from the output string: $ uptime This results contains some useful info including number of users logged on and <p><strong><a href="https://www.childs.be/data/uploads/uptime59.png" id="fb"><img alt="" src="https://www.childs.be/data/uploads/uptime59.png" style="width: 229px; height: 100px; float: right; margin: 10px;" /></a>If you host your own server and website like myself, you&#39;ll probably want to distplay your current uptime somewhere on your site. You are in luck, it is easy....</strong></p> <p>It uses the Linux command <code><a href="http://www.cyberciti.biz/faq/server-uptime-command-to-find-out-how-long-the-system-has-been-running/">uptime</a></code>&nbsp;and strips the unecessary gubbins from the output string:</p> <pre>$ uptime</pre> <p>This results contains some useful info including number of users logged on and loads as well as the uptime:</p> <blockquote>18:10:45 up 39 days, 22:04,&nbsp; 1 user,&nbsp; load average: 0.07, 0.06, 0.08</blockquote> <p>All you have to do is to insert the following php code into your page and you are away.</p> <pre>&lt;?php $data = shell_exec(&#39;uptime&#39;); $first = strpos($data, &#39;up&#39;); $data = substr($data,$first); $first = strpos($data, &#39;,&#39;); $data = substr($data,0,$first); $data = str_replace(&#39;up&#39;,&#39;Powered by Raspberry Pi, &#39;,$data); echo $data . &#39; uptime&#39; ?&gt;</pre> <p>You can see the results from my site at the footer of the page.</p> <blockquote>Powered by Raspberry Pi, 39 days uptime</blockquote> RaspberryPi uptime,data,RPI How to log your own IP Sat, 04 Apr 2015 08:00:00 +0000 https://www.childs.be/articles/post/how-to-log-your-own-ip https://www.childs.be/articles/post/how-to-log-your-own-ip Call me paranoid but ever since the antics of ACS:Law in the noughties I've been logging my IP address, it is not because I'm am an illegal downloader, my intrigue came about from the thought of how you would prove that you didn't if I was wrongly accused. Stay with me here, but think of the things that can go wrong in the chain of collecting <h4><a href="https://www.childs.be/data/uploads/IP_address.png" rel="iplog"><img alt="" src="https://www.childs.be/data/uploads/IP_address.png" style="width: 187px; height: 87px; float: right; margin: 10px;" /></a>Call me paranoid but ever since the antics of <a href="http://en.wikipedia.org/wiki/ACS:Law">ACS:Law</a> in the noughties I&#39;ve been logging my IP address, it is not because I&#39;m am an illegal downloader, my intrigue came about from the thought of how you would prove that you didn&#39;t if I was wrongly accused.</h4> <p>Stay with me here, but think of the things that can go wrong in the chain of collecting torrentors IPs, requesting the info from the ISP and collating and issuing all the thousands of law suits - there are any number of times a transposition of an IP address or a time and date could happen. Hell, even the <a href="http://news.bbc.co.uk/1/hi/technology/8483482.stm">music industry</a> didn&#39;t like the way some people were doing it!</p> <p>So my solution was to log my IP address, I&#39;ve been doing it for five years now and even though my RaspberryPi is also logging my IP in a couple of different ways: through <a href="http://www.ronnutter.com/raspberry-pi-installing-a-syslog-server-using-syslog-ng/">Syslog-ng</a> by logging all of my router activity and through running a <a href="https://www.childs.be/blog/post/setting-up-your-webserver-with-your-own-domain-name-with-a-dynamic-ip-address-on-sky-broadband">cron job</a> to dynamically update its IP address to the DNS server.</p> <p>It is trickier than you think to get your external ip address, <code><span style="font-family:arial,helvetica,sans-serif;">ipconfig</span></code> will only tell you your internal ip:</p> <p><a href="https://www.childs.be/data/uploads/ipconfig.png" rel="iplog"><img alt="" src="https://www.childs.be/data/uploads/ipconfig.png" style="width: 400px; height: 124px;" /></a></p> <p>This is because of <a href="http://en.wikipedia.org/wiki/Network_address_translation#NAT_loopback">NAT Loopback</a> so we&#39;ll need to find another way. Google will tell you your IP address if you <a href="https://www.google.co.uk/search?q=ip">google</a> it, but it will be much simpler to get it from another source that returns just the IP address in plain text so we don&#39;t have to clean up the html. For this we are going to use <a href="http://ip.changeip.com/">ip.changeip.com</a>, I&#39;m not abusing their service here as I already use them as my <a href="https://www.childs.be/blog/post/setting-up-your-webserver-with-your-own-domain-name-with-a-dynamic-ip-address-on-sky-broadband">DNS</a>.</p> <h3><strong>Instructions</strong></h3> <p>These instructions are for windows users only, this is on the basis that if you are a linux user you&#39;ll either a) already know how to do this or b) know how to modify this for your own requirements.</p> <h4><strong>Set up your folder</strong></h4> <p>Create a new directory somewhere safe on your computer, I called mine <code><span style="font-family:arial,helvetica,sans-serif;">logmyip</span></code>, if you are using Windows 7 you may come into a few security issues when trying to change the contents of some of the files after you&#39;ve created so you may as well go ahead and get it all working in another directory within your documents for example.</p> <h4><strong>wget</strong></h4> <p>Wget is a software package for retrieving files using HTTP, HTTPS and FTP, it is run in the command line and comes as standard with any Linux distro. For windows its a little harder to get hold of because you are expected to compile it yourself from the source code but you can download the windows binary from <a href="http://gnuwin32.sourceforge.net/packages/wget.htm">gnuwin32</a> at sourceforge, <a href="http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-bin.zip">direct link</a> (currently 1.11.4). Extract wget.exe from the zip to your newly created folder.</p> <h4><strong>logmyip.bat</strong></h4> <p>Next all we need is to set up the logging script, we&#39;ll be using a batch command. Open Notepad (or similar) then paste the following text in then save as logmyip.bat. Make sure you do not save it as a text document as it won&#39;t work, choose &#39;All files&#39; in the save dialogue.</p> <pre>echo off CHOICE /T 10 /C ync /CS /D y wget http://ip.changeip.com -q -O %temp%\\\\ip.txt set /p var1=&lt;%temp%\\\\ip.txt echo %date% %time% %var1%&gt;&gt;iplog.txt del %temp%\\\\ip.txt pause</pre> <h4><strong>logmyip.vbs</strong></h4> <p>This next step is not compulsory but I prefer it as it will run the script &#39;silently&#39;, i.e. won&#39;t flash up any annoying boxes when it runs - we&#39;ll be using a bit of vbs for this. Same as above, fire up Notepad and get the code saved down:</p> <pre>dim fso dim curDir dim WinScriptHost set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;) curDir = fso.GetAbsolutePathName(&quot;.&quot;) set fso = nothing Set WinScriptHost = CreateObject(&quot;WScript.Shell&quot;) WinScriptHost.Run chr(34) &amp; curDir &amp; &quot;\\\\logmyip.bat&quot; &amp; chr(34), 0 set WinScriptHost = nothing</pre> <h4><strong>Scheduling</strong></h4> <p>There are a couple of choices here, depends how often you want to log you IP address. My Sky router is pretty stable and doesn&#39;t reset itself very often resulting in a change of IP - I only run it once a day. I&#39;ve scheduled this but just getting it to run at startup. This is easy to setup - right-click the vbs file you created above and copy, then right-click somewhere in your folder and paste a shortcut. Then all you do is drag this shortcut over to the start menu, then keeping the left click on navigate through &#39;All programs&#39; then into the startup folder. Job done &nbsp;- it will then run every time you boot up.</p> <p>If you need to log more often than this you can schedule it in <a href="http://windows.microsoft.com/en-gb/windows/schedule-task">Task Scheduler</a>.</p> <h4><strong>Running a <span style="font-family:courier new,courier,monospace;">my ip</span> script on your own server</strong></h4> <p>If you want to host your own IP revealer, just use this php code below:</p> <pre>&lt;?php $filepath=$_SERVER[&#39;QUERY_STRING&#39;]; parse_str($filepath); if ($td==&quot;y&quot;) { echo date(&quot;d/m/Y H:i:s&quot;, time()).&quot; - &quot;.$_SERVER[&#39;REMOTE_ADDR&#39;]; } else { echo $_SERVER[&#39;REMOTE_ADDR&#39;]; } ?&gt;</pre> <p>It is also coded that if you run the query string <span style="font-family:courier new,courier,monospace;">?td=y</span> then it will also spit out the server time and date, you can check it out <a href="http://childs.be/ip/?td=y">here</a>.</p> <p>&nbsp;</p> RaspberryPi log,ip,address,wget,torrent,batch,vbs,php How to display Flickr images on your own website Sat, 28 Mar 2015 08:00:00 +0000 https://www.childs.be/articles/post/how-to-display-flickr-images-on-your-own-website https://www.childs.be/articles/post/how-to-display-flickr-images-on-your-own-website I've struggled for a long time trying to find a way to elegantly and simply display my flickr photos on my site. Up 'til now I've had to stick with slideshow apps from other websites like flickriver. This is until I found this blueimp Gallery when I was looking for some lightbox coding for my website. I didn't end up using the blueimp lightbox <p><strong><a href="https://www.childs.be/data/uploads/flikralbum.jpg" id="fb"><img alt="Flickr album" src="https://www.childs.be/data/uploads/flikralbum.jpg" style="width: 300px; height: 300px; float: right; margin: 10px;" /></a>I&#39;ve struggled for a long time trying to find a way to elegantly and simply display my flickr photos on my site. Up &#39;til now I&#39;ve had to stick with slideshow apps from other websites like <a href="http://flickriver.com/badge/user/all/interesting/shuffle/medium-vert/ffffff/333333/34004662@N05.jpg" id="fb">flickriver</a></strong>.</p> <p>This is until I found this <a href="https://blueimp.github.io/Gallery/">blueimp Gallery</a> when I was looking for some <a href="http://en.wikipedia.org/wiki/Lightbox_%28JavaScript%29">lightbox</a> coding for my website. I didn&#39;t end up using the blueimp lightbox because I went with fancybox as it was already built into <a href="http://get-simple.info/">getsimple</a> I just had to enable it with a <a href="http://get-simple.info/extend/plugin/fancyboxplugin/404/">tiny plugin</a>. I did however utilise the code to gather a list of photos from Flickr.</p> <p>The code is great; it calls the Flikr API <code><span style="font-family:courier new,courier,monospace;"><a href="https://www.flickr.com/services/api/flickr.people.getPhotos.html">people.getPhotos</a></span></code> from ajax and neatly writes the thumbnail html into the blank div of your choosing.</p> <p>It took me a while to tweak it to show my own <a href="https://www.flickr.com/photos/-martin-/">photostream</a> from its default interingness list, but now I have it I&#39;m pretty pleased how simple, easy and effective it is.</p> <h4>Instructions</h4> <p><strong>Add the page code</strong></p> <p>In the place you want the thumbnails to appear insert the following div &amp; also place the link to the script in your html code:</p> <p><img alt="" src="https://www.childs.be/data/uploads/flickrhtml.jpg" style="width: 286px; height: 50px;" /></p> <p><strong>Install the JS file</strong></p> <p>Then save the javascript file down in the corresponding place (you can use the download link at the bottom), then change the user_id in the script to that of the one you want to display the images of.</p> <p><img alt="" src="https://www.childs.be/data/uploads/FlickrJS.jpg" style="width: 669px; height: 562px;" /></p> <p><a class="btn btn-primary btn-sm" href="/data/uploads/flickr.js">Download JS</a></p> <p>You can also tweak the thumbnail sizes by changing the underscored suffix in line 35, see the different settings <a href="https://www.flickr.com/services/api/misc.urls.html">here</a>. <code>_q</code> denotes 150x150px image. You can also change the size of picture the photo links to by changing the <code><span style="font-family:courier new,courier,monospace;">_b</span></code> on line 36.</p> <p>Additionally you can set the number of photos to get, the default is 100 but you can have up to 500 as required.</p> <h4>jQuery</h4> <p>Next you need to ensure you have a jQuery installed on your page, you can either do this via a <a href="http://jquery.com/download/#using-jquery-with-a-cdn">link to a CDN</a> or <a href="http://jquery.com/download/#downloading-jquery">host the script</a> file yourself.</p> <h4>Enjoy</h4> <p>If all went well, when you fire up your webpage you should see the thumbnails of your Flikr phhotostream.</p> RaspberryPi flickr,thumbnails,export,website Raspberry Pi - record uptime Tue, 17 Feb 2015 20:14:06 +0000 https://www.childs.be/articles/post/raspberry-pi-record-uptime https://www.childs.be/articles/post/raspberry-pi-record-uptime Well, i had pre-written a post celebrating a whole year of uptime for my RaspberryPi - guess I shouldn't have jinxed it! On Friday I came home to find the Pi unresponsive to web access, putty & vnc. There was noting for it and I had to suck up the loss and kill the power, oh well I shouldn't be to disappointed, 345 days is a respectable <p><strong>Well, i had pre-written a post celebrating a whole year of uptime for my RaspberryPi - guess I shouldn&#39;t have jinxed it! On Friday I came home to find the Pi unresponsive to web access, putty &amp; vnc. </strong></p> <p><a href="https://www.childs.be/data/uploads/uptime.png" id="fb"><img alt="" id="" src="https://www.childs.be/data/uploads/uptime.png" style="width: 399px; height: 156px; float: right; margin: 10px" /></a>There was noting for it and I had to suck up the loss and kill the power, oh well I shouldn&#39;t be to disappointed, 345 days is a respectable acheivement. Looking on the brightside, it gave me a window to swap to a larger SD card to allow me to do some software updates.</p> <p><strong>Well done RaspberryPi!</strong></p> RaspberryPi raspberry,pi,uptime,record philfish.co.uk is launched - Phil Cam is live! Sun, 11 May 2014 08:00:00 +0000 https://www.childs.be/articles/post/phil-cam-is-live https://www.childs.be/articles/post/phil-cam-is-live The momentous day for Phil has been reached, his tank hosted server has launched! His Samsung Galaxy S2 server is live and pumping out his very own website. Phil is said to be delighted with his web 2.0 upgrade  and is looking forward share the images of the tank to the whole world. He says he's not finished yet and is working in the <h4><a href="https://www.childs.be/data/uploads/philfishcouk.jpg" id="fb"><img alt="" src="https://www.childs.be/data/uploads/philfishcouk.jpg" style="width: 250px; float: right; margin: 10px; height: 179px;" /></a>The momentous day for <a href="http://philfish.co.uk/phil.html">Phil</a> has been reached, his tank hosted server has launched!</h4> <p>His Samsung Galaxy S2 server is live and pumping out his <a href="http://philfish.co.uk/">very own website</a>.</p> <p>Phil is said to be delighted with his web 2.0 upgrade&nbsp; and is looking forward share the images of the tank to the whole world. He says he&#39;s not finished yet and is working in the background to bring you some enhancements but in the meantime you can enjoy the wonders of <a href="http://philfish.co.uk/barrel.html">webcam </a>and <a href="http://philfish.co.uk/flappy.html">Flappy Phil game</a>.</p> <p>He also notes that he has a number of vacanies available to become a <a href="http://philfish.co.uk/friends.html">friend of Phil</a> and is currently accepting applications.</p> RaspberryPi philfish.co.uk,philthefish Set up a Wireless IP Webcam for free Sat, 03 May 2014 08:00:00 +0000 https://www.childs.be/articles/post/set-up-a-wireless-ip-webcam-for-free https://www.childs.be/articles/post/set-up-a-wireless-ip-webcam-for-free This a hack for repurposing an old android handset as an ip webcam - all you need is your old unused android smartphone and the free app IP Webcam. Heres a rundown own the steps you need to go through, I'll take you through more of the detail below. Steps Find the old android device you'll be using and connect it to your wireless <h4><img alt="IP Webcam" src="https://www.childs.be/data/uploads/IP-cam.jpg" style="width: 200px; height: 199px; float: right; margin: -10px;" />This a hack for repurposing an old android handset as an ip webcam - all you need is your old unused android smartphone and the free app <a href="https://play.google.com/store/apps/details?id=com.pas.webcam">IP Webcam</a>.</h4> <p>Heres a rundown own the steps you need to go through, I&#39;ll take you through more of the detail below.</p> <h4>Steps</h4> <ol> <li>Find the old android device you&#39;ll be using and connect it to your wireless network;</li> <li>Download the free IP Webcam app from the Play store;</li> <li>Fire up the app, you&#39;ll see a few configuration options but you can skip these for now and scroll to the bottom and hit start server;</li> <li>You phone&#39;s camera should start up and on the screen you&#39;ll see the URL that you can view from your browser;</li> <li>Go to the browser on a computer on the same newtork and type in the address (probably something like 192.168.XX.XX:8080);</li> <li>Enjoy!</li> </ol> <h4>Further steps</h4> <p>If you want to be able to view your webcam from the internet outside your home network, there are a couple of other steps you&#39;ll need to take:</p> <ol> <li>Configure a static IP address for your phone (either through the router config or on the phone itself);</li> <li>Configure your router to route (by default port 8080) traffic from the internet to your phone;</li> <li>Set up static access to your home network if your broadband link has a dynamically assigned IP address.</li> </ol> <h4>Port 80 android limitation</h4> <p>Theres a limitation with the android OS we have to get around round first though. All ports below 100 are restricted so by default you&#39;ll have to serve your site through port 8080. To get around this you&#39;ll either have to</p> <ul> <li>root your device and install iptables (I&#39;ve not found a way to do this yet);</li> <li>use some router configuration to pass port 80 requests onto port 8080;</li> <li>or you can use another server as a proxy.</li> </ul> <h4>Router configuration</h4> <p>Most routers don&#39;t have much in the way of configuration options so unless you are using <a href="http://www.dd-wrt.com">dd-wrt</a> or similar, its unlikely that you&#39;ll be able to redirect traffic to port 8080. I have a guide here on how to<a href="https://www.childs.be/blog/post/setting-up-your-webserver-with-your-own-domain-name-with-a-dynamic-ip-address-on-sky-broadband"> set-up a domain name with your router</a>, but unfortunately you&#39;ll probably be stuck with an address to access you webcam like:</p> <pre>yoursite.com:8080</pre> <p>unless you can find a service to do this for you or you have access to another server to do this.</p> <h4>Apache Proxy</h4> <p>If you have access to an apache server you can easily set up a ProxyPass to forward traffic to your webcam. You can capture the requests via a subdomain and then forward them on to your webcams network IP address (e.g. 192.168.0.23):</p> <pre>&lt;VirtualHost *:80&gt; &nbsp;&nbsp;&nbsp; ProxyPass / http://Internal-IP:8080/ &nbsp;&nbsp;&nbsp;&nbsp;ProxyPassReverse / http://Internal-IP:8080/ &nbsp;&nbsp;&nbsp;&nbsp;ServerName webcam.yoursite.com &lt;/VirtualHost&gt;</pre> <p>Once this has all been setup you will be seamlessly served your webcam images through your sub-domain URL.</p> RaspberryPi wireless,ipwebcam,android,website Setting up your own domain name with a dynamic IP address on Sky Broadband Thu, 17 Apr 2014 08:00:00 +0000 https://www.childs.be/articles/post/setting-up-your-webserver-with-your-own-domain-name-with-a-dynamic-ip-address-on-sky-broadband https://www.childs.be/articles/post/setting-up-your-webserver-with-your-own-domain-name-with-a-dynamic-ip-address-on-sky-broadband Most broadband connections will nowdays dynamically assign you with an IP address. This means that every few days or every time you restart your router you will be assigned a new IP address. Consequently if you want to host a website using your domain name then you are going to encounter a problem. What you need to do is get a static IP address <p><a href="https://www.childs.be/data/uploads/skyrouter.png" id="fb"><img alt="" class="thumbnail" src="https://www.childs.be/data/uploads/skyrouter.png" style="width: 251px; height: 151px; float: left; margin-right:10px; margin-bottom:0" /></a><strong>Most broadband connections will nowdays dynamically assign you with an IP address. This means that every few days or every time you restart your router you will be assigned a new IP address. Consequently if you want to host a website using your domain name then you are going to encounter a problem.</strong></p> <p>What you need to do is get a static IP address (typically an ISP will charge for this <em>if</em> they even allow it), or find some way of updating your name server with every change of IP address. Your typical domain name seller doesn&#39;t want to offer this service as they want to sell you a hosting package so you will have to find another way around.</p> <h4>Dynamic IP woes</h4> <p>Most routers will have some sort of option to update a dynamic DNS service with your ip address and assign you a CNAME/URL that you can use, its not very pretty but it is one step closer closer to the goal.</p> <p>For Sky Broadband customers the only configuration option here is to use <a href="http://dyn.com/dns/">DynDNS</a>, unfortunately this service is no longer free and at $30 per year is too much for this tight-wad. [Note: they do offer a free option but the hostname expires every 30days so its of no real use]</p> <h4>Get a static hostname</h4> <p>One free dynamic DNS service is changeip.com, they try to hide the free option but it is there and it does work. So after you have signed up, select your sub-domain name and head over to the <a href="http://www.changeip.com/accounts/dnsmanager.php">DNS Manager</a> page select you new domain and manually update it with your IP address you are away. Just bang in your new URL into a web browser and you are one step closer:</p> <pre>http://yournewsubdomain.dynamic-dns.net</pre> <p>they even helpfully provide a <a href="http://www.changeip.com/accounts/downloads.php?action=displaycat&amp;catid=2">shell script</a> you can set as a cron job to automate the updating of your IP address, it works a treat and helpfully keeps a log of your IP address as it changes also.</p> <h4>Pointing your domain name</h4> <p>Now the final step is to change to nameserver entry on your own domain name, your service provider should have the option in your account settings somewhere to change your DNS entries. You have to take care here as you could screw things up. I started out by testing the waters by setting up a subdomain of childs.be first to test that out.</p> <p>What you need to do is change your DNS record for your selected [sub]domain to CNAME and then set the value as your new yournewsubdomain.dynamic-dns.net. Thats it, you are away, your domain name URL will now always be pointed at your dynamic ip.</p> <p>I&#39;ve been using this method for several months now and I rate the service as excellent.</p> <h3>Another sneaky way</h3> <p>If you&#39;ve googled the subject enough you may have discovered that while DynDNS isn&#39;t free, <a href="http://www.dlinkddns.com">D-Link DNS</a> is. It is only for D-Link router users only and once you have created an account you can log into both D-Link DNS and DynDNS with the same details.</p> <p>This makes it very easy as setting up your router to automatically update your dynamic IP in this way and is a doddle!</p> <p>I must stress though, using this service without a D-Link router is against its TOS, but it is reported that does work in this way.</p> <p><strong>Edit 24-July-2014:</strong> Looks like Dyn.com are making D-Link users verfiy their ownership to continue use of their service, <a href="http://dyn.com/dlink-faqs/">see here</a>, still you could always buy a used on from <a href="http://www.ebay.co.uk/sch/?_nkw=d-link%20router">ebay</a> to keep you going but that might only get you another 6 months before you have to pay.</p> <p><strong>Edit 22-Oct-2014:</strong> Dyn.com have now deleted unverified accounts.</p> <p>&nbsp;</p> RaspberryPi dynamicIP,skybroadband,hostname,websitehosting Hosting your own webserver on port 80 with Sky broadband Sat, 05 Apr 2014 08:00:00 +0000 https://www.childs.be/articles/post/hosting-your-own-webserver-on-port-80-with-sky-broadband https://www.childs.be/articles/post/hosting-your-own-webserver-on-port-80-with-sky-broadband One of the first things I needed to check before ordering my Raspberry Pi was if it was technically feasable to host my own webserver from my Sky Broadband. In the past its been known by ISPs to block certain ports which makes it difficult and usually adds extra cost. One of the ways round the issue of your desired ports are blocked would be to <p><a href="https://www.childs.be/data/uploads/skyrouter.png" id="fb"><img alt="" class="thumbnail" src="https://www.childs.be/data/uploads/skyrouter.png" style="width: 250px; height: 151px; float: right; margin-bottom:0px;" /></a><strong>One of the first things I needed to check before ordering my Raspberry Pi was if it was technically feasable to host my own webserver from my Sky Broadband. In the past its been known by ISPs to block certain ports which makes it difficult and usually adds extra cost.</strong></p> <p>One of the ways round the issue of your desired ports are blocked would be to use some sort of service which relays incoming port 80 traffic to another port to your server. Its messy and is probably going to cost for this service&nbsp; and given one of the reasons why I&#39;ve got a RPi was to have practically free hosting.</p> <p>It seems there is no information on the internet as to whether Sky blocks port 80 for their broadband users. I&#39;ll cut to the chase if you can be bothered to read the rest of the article to say that:</p> <div class="alert alert-success">Ports 80 and 8080 are not blocked on Sky ADSL Broadband.</div> <p>Now we have established this, its just a case of setting up your router to forward internet traffic to your Pi webserver. There&#39;s a helpful page on Sky&#39;s support website explaining how to do this:</p> <p><a href="http://helpforum.sky.com/t5/Broadband-Setup-Connection-WiFi/Sky-Hub-How-to-Configure-Port-Forwarding/ta-p/707150">Sky Hub : How to Configure Port Forwarding</a></p> <p>Well thats the easy part, next you&#39;ve got to get around that whole dynamic DNS thing, but luckily for you I&#39;ve got a tutorial for that:</p> <p><a href="https://www.childs.be/blog/post/setting-up-your-webserver-with-your-own-domain-name-with-a-dynamic-ip-address-on-sky-broadband">Setting up your own domain name with a dynamic IP address on Sky Broadband</a></p> <p>&nbsp;</p> RaspberryPi sky,broadband,port80,8080,hosting,webserver New childs.be website launched Sat, 22 Mar 2014 19:53:00 +0000 https://www.childs.be/articles/post/new-childsbe-website-launched https://www.childs.be/articles/post/new-childsbe-website-launched The new website has now gone live. With the acquisition of my Raspberry Pi comes a whole host of possibilities. My Pi is currently running as the server for this website. Unfortunately the Pi is not powerful engough to run Wordpress or Joomla (who'd of thought they were processor intensive) - it does run, but a four to six second delay in spitting <p><a href="https://www.childs.be/data/uploads/childs-be.png" id="fb"><img alt="" src="https://www.childs.be/data/uploads/childs-be.png" style="width: 288px; height: 192px; float: right; padding-left: 10px;" /></a><strong>The new website has now gone live. With the acquisition of my <a href="https://www.childs.be/blog/post/the-raspberry-pi-is-alive">Raspberry Pi</a> comes a whole host of possibilities.</strong></p> <p>My Pi is currently running as the server for this website. Unfortunately the Pi is not powerful engough to run Wordpress or Joomla (who&#39;d of thought they were processor intensive) - it does run, but a four to six second delay in spitting out a page is way too long.</p> <p>What I&#39;ve gone for on my first crack is a flat-file CMS with blogging functionality as a plugin running stock Bootstrap and Bootstrap-theme CSS. I&#39;m pretty pleased with the first real attempt. It needed some mods out of the box but I&#39;m happy with it for the moment.</p> <p>Here&#39;s a rundown of the software specs it&#39;s rocking:</p> <div class="table-border"> <div class="table-border-title">Software rundown</div> <table class="table table-striped"> <thead> <tr> <th>Raspberry Pi</th> <th>Model B</th> </tr> </thead> <tbody> <tr> <td>OS</td> <td>Linux: wheezy-raspbian</td> </tr> <tr> <td>Webserver</td> <td>Apache / PHP5 / MySQL</td> </tr> <tr> <td>CMS</td> <td><a href="http://get-simple.info/">Get Simple CMS</a></td> </tr> <tr> <td>CSS</td> <td><a href="http://get-simple.info/extend/theme/bootstrap-theme/587/">Bootstrap for GetSimple CMS</a> with Bootstrap-theme and some other modifications</td> </tr> <tr> <td>Blogging</td> <td><a href="http://get-simple.info/extend/plugin/gs-blog/462/">GS Blog</a> with <a href="http://www.ordnancesurvey.co.uk/business-and-government/help-and-support/web-services/code-playground.html">OS Openspace API</a> for mapping</td> </tr> <tr> <td>FTP</td> <td>vsftpd</td> </tr> <tr> <td>Filesharing/SMB</td> <td>Samba</td> </tr> <tr> <td>Logging</td> <td>syslog-ng</td> </tr> <tr> <td>Other</td> <td>Uptimed</td> </tr> </tbody> </table> </div> <p>&nbsp;</p> <p>I&#39;m hoping to post some more articles on the trickier things I&#39;ve come across when setting up the RPi.</p> <p>As a bonus in the mean time, I&#39;ve reposted some posts from Blogger from a long while ago when I first though I&#39;d start a blog but quickly ran out of stuff to blog about!</p> <p>You can check out the Raspberry Pi&#39;s specs <a href="https://www.childs.be/raspberry-pi/">here</a></p> <p>&nbsp;</p> RaspberryPi raspberrypi,website,childsbe the Raspberry Pi is alive Tue, 04 Mar 2014 01:14:00 +0000 https://www.childs.be/articles/post/the-raspberry-pi-is-alive https://www.childs.be/articles/post/the-raspberry-pi-is-alive The new server has now gone live, the Rasberry Pi is sitting quietly in the corner of my living room serving up my website to the internet. I know I've backdated this post, but it is to mark the moment in history - I'll give the Pi one final good luck reboot and it is ready to go with the aim of surviving a whole year of uptime. For many years <p><a href="https://www.childs.be/data/uploads/Raspi-logo.png" id="fb"><img alt="Raspberry Pi logo" src="https://www.childs.be/data/uploads/Raspi-logo.png" style="width: 288px; height: 163px; float: left; padding-right: 10px" /></a><strong>The new server has now gone live, the Rasberry Pi is sitting quietly in the corner of my living room serving up my website to the internet.</strong></p> <p>I know I&#39;ve backdated this post, but it is to mark the moment in history - I&#39;ll give the Pi one final good luck reboot and it is ready to go with the aim of surviving <a href="https://www.childs.be/blog/post/raspberry-pi-record-uptime">a whole year of uptime</a>.</p> <p>For many years I&#39;ve been wanting more functionality from my paid hosting company but being too tight to fork out the hundreds of pounds a year it would cost as I wasn&#39;t quite sure if I&#39;d actually get my monies worth out of it.</p> <p>I&#39;ve been keeping an eye on the Raspberry Pi project for a few years now, I even had an invite to buy one from the very early batches however I really wasn&#39;t sure I&#39;d ever put it to good use. As time has gone on and my skills have improved as I dabble ever more with WAMP, I decided to take the plunge.</p> <p>At only &pound;30 with a bundled case from ebay it couldn&#39;t have been cheaper. A couple of days and a few internet tutorials later and I&#39;m in business.</p> <p><a href="https://www.childs.be/about-me/#rpi">You can check out the Raspberry Pi&#39;s technical specs here</a></p> <p>It is said that the Pi is great for kids and newbs, however you&#39;ve got to take that with a pich of salt. Complete beginners might have a tricky time with the various processes and while it is true you can have its running as a webserver in no time, actually implementing it running your own site is a fair bit trickier.</p> <p>What you get with the Pi initially is very minimal - just a circuit board! So you will have to invest or scrounge a couple of things to get you started:</p> <div class="row"> <div class="col-md-8"> <div class="list-group"><a class="list-group-item active">My kit list</a> <div class="list-group-item">Raspberry Pi Model B</div> <div class="list-group-item">Spare micro USB mains charger (700mA recommended)</div> <div class="list-group-item">4Gb Class 6 SD card (borrowed from my ASUS EeePC)</div> <a class="list-group-item active">Required for initial setup only</a> <div class="list-group-item">TV / Monitor with appropriate VGA / HDMI cable</div> <div class="list-group-item">USB Keyboard &amp; mouse</div> <div class="list-group-item">4Gb Class 6 SD card (borrowed from my ASUS EeePC)</div> </div> </div> </div> <p><br /> &nbsp;</p> RaspberryPi raspberrypi,website,childsbe