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

<channel>
	<title>gj |</title>
	<atom:link href="https://blog.gaiterjones.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/category/uncategorized/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Thu, 07 Jun 2018 12:19:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Home Automation with the Sonoff TH10/TH16 with PHP, FHEM, JSON and how to FLASH!</title>
		<link>https://blog.gaiterjones.com/home-automation-with-the-sonoff-th10-th16-with-php-fhem-json-and-how-to-flash/</link>
					<comments>https://blog.gaiterjones.com/home-automation-with-the-sonoff-th10-th16-with-php-fhem-json-and-how-to-flash/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Thu, 07 Jun 2018 10:35:33 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1910</guid>

					<description><![CDATA[In 2016 I started developing my own Home Automation systems (HA) using a Raspberry PI, PHP and FHEM. Initially I wanted to just control a few lights using cost efficient...<a class="more-link" href="https://blog.gaiterjones.com/home-automation-with-the-sonoff-th10-th16-with-php-fhem-json-and-how-to-flash/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>In 2016 I started developing my own Home Automation systems (HA) using a Raspberry PI, PHP and <a href="https://blog.gaiterjones.com/how-to-run-fhem-as-a-docker-container-on-a-raspberry-pi/">FHEM</a>. Initially I wanted to just control a few lights using cost efficient RF sockets and this worked really well. Since then I have enjoyed developing my HA system and am always looking for cheaper alternatives to the sometimes extremely expensive solutions you find online or in DIY stores. Last year (2017) I started looking for smart WiFi enabled sockets as a network controlled smart socket is much more reliable and has a wider transmission range than RF sockets. I also wanted to measure air and water temperature and found that the Sonoff TH smart switches were ideal for this.</p>
<p>The Sonoff TH10/TH16 are 90-250V (50/60hz) temperature and humidity monitoring WiFi smart switches supporting a maximum current of 10A (2200W) or 16A (3500W) with two purpose built sensors, one for temperature and one for humidity. Compared to most retail Wifi enabled switches they are extremely cost effective with an <a href="https://www.itead.cc/sonoff-th.html">online</a> price under USD 10. The switches are designed to be controlled by a free IOS or Android app but what makes them perfect for developing your own HA system is that they use an ESP8266 chip which means you can flash them with custom firmware and do just about whatever you want with them!</p>
<p>Recently (2018) I bought a couple of new TH16&#8217;s and found that a lot had changed since I first used them so here are are the steps currently required to FLASH, program and use a Sonoff TH16 as a Home Automation smart switch and temperature sensor controlled by <a href="https://blog.gaiterjones.com/amazon-alexa-php-hello-world-example/">PHP</a> or <a href="https://blog.gaiterjones.com/how-to-run-fhem-as-a-docker-container-on-a-raspberry-pi/">FHEM</a>.</p>
<h1>Sonoff TH16</h1>
<figure id="attachment_1912" aria-describedby="caption-attachment-1912" style="width: 449px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/sonoff-th16-th10-smart-wifi-switch-monitoring-1.jpg" alt="" width="449" height="441" class="wp-image-1912" /><figcaption id="caption-attachment-1912" class="wp-caption-text">Sonoff TH16 WiFi Smart Switch and Sensors</figcaption></figure>
<p>You can purchase the Sonoff TH16 at all your favourite online retailers including Amazon and eBay, whilst it is possible to build your own sensors if you want to monitor temperature or humidity then it&#8217;s easiest to also purchase the corresponding Sonoff sensor, for temperature I used the Sonoff Temp Sensor-DS18B20 which costs about USD 5. The temperature sensor is waterproof.</p>
<h1>FLASH Firmware with ESPEasy</h1>
<p><a href="https://www.letscontrolit.com/wiki/index.php/ESPEasy">ESPEasy</a> is open source firmware for ESP8266. &#8220;The ESP Easy firmware can be used to turn the ESP module into an easy multifunction sensor device for Home Automation solutions&#8221; in our case the ESP module is within the TH16, the ESPEasy firmware replaces the code supplied with the TH16 with the ESPEasy firmware version you choose to flash.</p>
<p>To flash the TH16 with new firmware you need to enable serial communication between a Windows PC and the TH16, you can do this by using a USB to TTL dongle CH340G (FT232RL or PL2303 based will also do) these are easily obtainable online. The dongle connects to a USB port on your PC creating a serial interface. You then connect the dongle to the TH16.</p>
<p>Before you can connect the dongle you must open up the TH16 and solder a header to the power, TX and RX pins on the TH16 circuit board. Header pins are easily available online, you will also need a soldering iron, solder and a steady hand.</p>
<figure id="attachment_1926" aria-describedby="caption-attachment-1926" style="width: 600px" class="wp-caption aligncenter"><img decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp7.jpg" alt="" width="600" height="450" class="size-full wp-image-1926" /><figcaption id="caption-attachment-1926" class="wp-caption-text">TH16 Power (3.3v), RX, TX, GND before soldering header pins</figcaption></figure>
<p>&nbsp;</p>
<figure id="attachment_1925" aria-describedby="caption-attachment-1925" style="width: 600px" class="wp-caption aligncenter"><img decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp5.jpg" alt="" width="600" height="450" class="size-full wp-image-1925" /><figcaption id="caption-attachment-1925" class="wp-caption-text">TH16 Header Pins Soldered to Circuit Board</figcaption></figure>
<p>&nbsp;</p>
<figure id="attachment_1924" aria-describedby="caption-attachment-1924" style="width: 600px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp6.jpg" alt="" width="600" height="346" class="size-full wp-image-1924" /><figcaption id="caption-attachment-1924" class="wp-caption-text">USB Dongle Power (3.3v), TX, RX, GND</figcaption></figure>
<table>
<thead>
<tr>
<th>Pin</th>
<th>Sonoff</th>
<th>USB</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>VCC</td>
<td>3V3</td>
</tr>
<tr>
<td>2</td>
<td>tx</td>
<td>RX</td>
</tr>
<tr>
<td>3</td>
<td>rx</td>
<td>TX</td>
</tr>
<tr>
<td>4</td>
<td>GND</td>
<td>GND</td>
</tr>
</tbody>
</table>
<p><em>Note, you may need to swap TX and RX round. The Sonoff circuit board version used here was v2.1</em></p>
<p>The currently advertised <em>stable</em> firmware is version 120 which is at least 2 years old, I recommend you flash the TH16 with the latest MEGA dev firmware which has nightly builds available from the github at <a href="https://github.com/letscontrolit/ESPEasy/releases">https://github.com/letscontrolit/ESPEasy/releases</a></p>
<p>Download the ESPEasy_mega-XX.zip file and extract it. You will see various firmware binary images, we need a 1MB ESP8266 binary image so the DEV image ESP_Easy_mega-2018XXXX_dev_ESP8266_1024.bin is the image we will use to flash the TH16.</p>
<p>We need software to communicate with the TH16 and flash the new firmware to the 8266 chip, the esptool software supplied with the ESPEasy firmware no longer works with the latest versions of the Sonoff TH smart switches (v2.1). Download the nodemcu flasher here</p>
<p>For 32 bit Windows : <a href="https://github.com/nodemcu/nodemcu-flasher/blob/master/Win32/Release/ESP8266Flasher.exe">https://github.com/nodemcu/nodemcu-flasher/blob/master/Win32/Release/ESP8266Flasher.exe</a><br />
For 64 bit Windows : <a href="https://github.com/nodemcu/nodemcu-flasher/blob/master/Win64/Release/ESP8266Flasher.exe">https://github.com/nodemcu/nodemcu-flasher/blob/master/Win64/Release/ESP8266Flasher.exe</a></p>
<p>When you have all the software saved and the TH16 connections ready start the ESP8266Flasher. Now holding down the tall white button on the TH16 plug the TH16/USB dongle into your PC and release the tall white button this will configure the TH16 8266 chip for flash mode.</p>
<p>The nodemcu firmware programmer (ESP8266Flasher) should now detect the serial COM port connected to the TH16. If the port is not detected check in Windows device manager that the USB dongle is detected as a serial device and has been assigned a COM port.</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/nodemcu1.png" alt="" width="574" height="332" class="aligncenter size-full wp-image-1913" /><br />
Click on the Advanced tab and configure the following settings</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/nodemcu2.png" alt="" width="561" height="314" class="aligncenter size-full wp-image-1914" /></p>
<p>Click on the Config tab and select the 1MB ESP8266 binary image from the downloaded ESPEasy image folder</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/nodemcu3.png" alt="" width="568" height="128" class="aligncenter size-full wp-image-1915" /></p>
<p>Now go back to the Operation tab and click the blue FLASH button to begin the flash process, a progress bar will be displayed and the process will take a couple of minutes to complete.</p>
<p>When the flash operation is complete you can disconnect the TH16 from your PC.</p>
<h1>ESPEasy WLAN Configuration</h1>
<p>You now need to power on the TH16 from the mains, so you first need to connect a mains cable (90-250v) to the device and power it up</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/mains1.jpg" alt="" width="524" height="825" class="aligncenter wp-image-1916" /></p>
<p>When the TH16 is powered on after flashing it becomes a Wireless Access Point to allow you to connect to it and configure initial WLAN settings for the device. With a smart phone or other device connect to the WLAN name <strong>ESP_Easy_0</strong> with the password <strong>configesp.</strong></p>
<p>You should see a browser page asking for WLAN credentials. Select the WLAN you want the TH16 to connect to and enter the password. The TH16 should connect to the WLAN and inform you which IP address it has been assigned. I recommend you create a DHCP reservation for this address so that it is permanent.</p>
<p>You can now manage and configure the TH16 from a web browser using the url http://x.x.x.x where x.x.x.x is the IP address assigned to the TH16.</p>
<p>If you do not see the ESP_Easy_0 WLAN then the flashing process was not successful. Attempt to flash the device again, some users report that you should press and hold the tall white TH16 button and continue to hold it until the flashing process is complete.</p>
<h1>ESPEasy Configuration</h1>
<p>The TH16 is now powered on, connected to the WLAN with the DS18B20 temperature sensor plugged in. Note that the sensor plugs in using a small jack plug, the plug should push in and <em>click</em> into the socket. With my TH16 the hole in the casing prevented the sensor plug from clicking firmly into place and was not detected. I had to enlarge the casing hole in order for the sensor to connect properly and be detected.</p>
<p>Open a browser and enter the url of the TH16 to open the web based configuration : http://x.x.x.x</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp1.jpg" alt="" width="400" height="300" class="aligncenter wp-image-1917" /></p>
<p>First give the device a name by clicking the Config tab and entering a Unit Name. If you are using FHEM (or another supported HA system) click on the Controllers tab and edit the credentials for your HA Controller server. For FHEM select FHEM HTTP from the Protocol list and enter the IP address of your FHEM server and the port used by the FHEM ESPEasy bridge (usually 8383 is used).</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp2.jpg" alt="" width="515" height="191" class="aligncenter wp-image-1918" /></p>
<p>Click on the Devices tab</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp3.jpg" alt="" width="509" height="186" class="aligncenter wp-image-1919" /></p>
<p>I have three devices configured</p>
<ol>
<li>Generic System Info is reporting the WLAN signal strength &#8211; this is used as a presence controller by FHEM.</li>
<li>Switch Input is reporting the state of the built in power switch which is controller by GPIO 12</li>
<li>Environment DS18b20 is reporting the state (temperature) of the DS18b20 sensor which is controlled by GPIO14
<ol>
<li>if the sensor is not detected by the TH16 make sure if is connected properly</li>
</ol>
</li>
</ol>
<p>To configure these devices click the edit button and select the device type you want to configure from the drop down box, here is my configuration for the temperature sensor</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/esp4.jpg" alt="" width="438" height="467" class="aligncenter wp-image-1920" /></p>
<p>Make sure you check the enabled box before you save the device. You can see that I am also sending this data to the controller (FHEM). The interval determines how often the device value will be updated. Explore the other configuration options available, you may want to add an access password or an NTP time server for example.</p>
<p>With the three devices configured and working you will see the corresponding values displayed, switch status (1=ON, 0=OFF), temperature etc.</p>
<h1>Retrieving Data and Controlling the Switch</h1>
<p>The easiest way to retrieve data from the TH16 is via an http request that returns JSON data, simply browse to</p>
<p>http://x.x.x.x/json</p>
<p>Here you will see a nicely formatted json array of status data for the TH16 including the switch status and temperature sensor value</p>
<pre class="brush: plain; title: ; notranslate">
&quot;TaskValues&quot;: &#x5B;
{&quot;ValueNumber&quot;:1,
&quot;Name&quot;:&quot;Temperature&quot;,
&quot;NrDecimals&quot;:2,
&quot;Value&quot;:29.50
}]
</pre>
<p>This makes retrieving data from the TH16 really simple if your are using PHP for example you can do something like this to get the data using curl and return it as a php array.</p>
<pre class="brush: php; title: ; notranslate">
$_data=$this-&amp;amp;gt;curlAjaxRequest('http://x.x.x.x/json');

	public function curlAjaxRequest($_url)
	{

		try {
			$_curl = curl_init(); 
	
			$_header&#x5B;0] = &quot;Accept: text/xml,application/xml,application/xhtml+xml,&quot;; 
			$_header&#x5B;0] .= &quot;text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&quot;; 
			$_header&#x5B;] = &quot;Cache-Control: max-age=0&quot;; 
			$_header&#x5B;] = &quot;Connection: keep-alive&quot;; 
			$_header&#x5B;] = &quot;Keep-Alive: 300&quot;; 
			$_header&#x5B;] = &quot;Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7&quot;; 
			$_header&#x5B;] = &quot;Accept-Language: en;q=0.5&quot;;
			$_header&#x5B;] = &quot;Pragma: &quot;;
			
			curl_setopt($_curl, CURLOPT_URL, $_url); 
			curl_setopt($_curl, CURLOPT_USERAGENT, 'My Home Automation'); 
			curl_setopt($_curl, CURLOPT_HTTPHEADER, $_header); 
			curl_setopt($_curl, CURLOPT_ENCODING, 'gzip,deflate'); 
			curl_setopt($_curl, CURLOPT_AUTOREFERER, true); 
			curl_setopt($_curl, CURLOPT_RETURNTRANSFER, 1); 
			curl_setopt($_curl, CURLOPT_TIMEOUT, 10); 
			
			$_object = curl_exec($_curl); // execute the curl command 
			curl_close($_curl); // close the connection 

		}
		
		//catch exception
		catch(Exception $e) {
			
			// do nothing with $e
			return false;
		  
		}
		
			return json_decode($_object,true);

	}
</pre>
<p>We can also control the TH16 using JSON commands. For example to turn the switch on or off using GPIO12 we can use</p>
<p>ON : http://x.x.x.x/control?cmd=GPIO,12,1<br />
OFF : http://x.x.x.x/control?cmd=GPIO,12,0</p>
<p>Again using curl you can send these commands via PHP.</p>
<h1>FHEM Configuration</h1>
<p>If you are using FHEM there is already a FHEM module that supports the ESPEasy firmware. To configure FHEM you need to enable the ESPEasy bridge, this is done with the following commands</p>
<pre class="brush: plain; title: ; notranslate">
define espBridge ESPEasy bridge 8383
attr espBridge authentication 0
attr espBridge combineDevices 0
attr espBridge group ESPEasy Bridge
attr espBridge room ESPEasy
</pre>
<p>You can see here we enable a bridge called espBridge listening on TCP port 8383.</p>
<p>If you have configured FHEM with autocreate enabled you should now see the TH16 switch automatically configured when it next sends it&#8217;s data update. It will appear in FHEM under ESPEasy.</p>
<p><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/fhem1.jpg" alt="" width="372" height="328" class="aligncenter wp-image-1923" /></p>
<p>I configured FHEM with the following configuration for each TH16</p>
<pre class="brush: plain; title: ; notranslate">
# ESP3 - OFFICE
define ESPEasy_ESP3_OFFICE_Switch_input ESPEasy x.x.x.x 80 espBridge ESP3_Switch_input
attr ESPEasy_ESP3_OFFICE_Switch_input IODev espBridge
attr ESPEasy_ESP3_OFFICE_Switch_input Interval 300
attr ESPEasy_ESP3_OFFICE_Switch_input devStateIcon on:ios-on-green:on off:ios-off:ff absent:10px-kreis-rot:statusRequest .*:ios-NACK:check
attr ESPEasy_ESP3_OFFICE_Switch_input event-on-change-reading .*
attr ESPEasy_ESP3_OFFICE_Switch_input eventMap /gpio 12 on:on/gpio 12 off:off/status gpio 12:check/
attr ESPEasy_ESP3_OFFICE_Switch_input group ESPEasy Device
attr ESPEasy_ESP3_OFFICE_Switch_input icon ge_wht_steckdose
attr ESPEasy_ESP3_OFFICE_Switch_input presenceCheck 1
attr ESPEasy_ESP3_OFFICE_Switch_input readingSwitchText 1
attr ESPEasy_ESP3_OFFICE_Switch_input room ESPEasy
attr ESPEasy_ESP3_OFFICE_Switch_input setState 3
attr ESPEasy_ESP3_OFFICE_Switch_input stateFormat {ReadingsVal($name,&quot;presence&quot;,&quot;&quot;) eq &quot;absent&quot; ? &quot;absent&quot; : ReadingsVal($name,&quot;Switch&quot;,&quot;&quot;)}

define ESPEasy_ESP3_OFFICE_System_Info ESPEasy x.x.x.x 80 espBridge ESP3_System_Info
attr ESPEasy_ESP3_OFFICE_System_Info IODev espBridge
attr ESPEasy_ESP3_OFFICE_System_Info Interval 300
attr ESPEasy_ESP3_OFFICE_System_Info group ESPEasy Device
attr ESPEasy_ESP3_OFFICE_System_Info icon WLAN_Status.1
attr ESPEasy_ESP3_OFFICE_System_Info presenceCheck 1
attr ESPEasy_ESP3_OFFICE_System_Info readingSwitchText 1
attr ESPEasy_ESP3_OFFICE_System_Info room ESPEasy
attr ESPEasy_ESP3_OFFICE_System_Info setState 3

define ESPEasy_ESP3_OFFICE_Temperature___DS18b20 ESPEasy x.x.x.x 80 espBridge ESP3_Temperature___DS18b20
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 IODev espBridge
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 Interval 300
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 group ESPEasy Device
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 icon temp_temperature
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 presenceCheck 1
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 readingSwitchText 1
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 room ESPEasy
attr ESPEasy_ESP3_OFFICE_Temperature___DS18b20 setState 3
</pre>
<p>I can now also use FHEM to control the switch by clicking on the GUI or using the commands</p>
<pre class="brush: plain; title: ; notranslate">
set ESPEasy_ESP3_OFFICE_Switch_input on
set ESPEasy_ESP3_OFFICE_Switch_input off
</pre>
<figure id="attachment_1929" aria-describedby="caption-attachment-1929" style="width: 356px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2018/06/poolwatertemp1.jpg" alt="" width="356" height="274" class="wp-image-1929 size-full" /><figcaption id="caption-attachment-1929" class="wp-caption-text">TH16 with DS18b20 sensor measuring Pool Water Temperature</figcaption></figure>
<h1>Conclusions</h1>
<p>Even the cheapest WIFI enabled smart switches are at least three or four times expensive as the Sonoff and that does not include any kind of sensor. Using the TH16 with ESPEasy software is a really cheap and reliable way to deploy WiFi smart switches and sensors in your Home and if you are an electronic engineer then there are many more options available for building and connecting your own sensors to the TH16.</p>
<h1>Resources</h1>
<p>&nbsp;</p>
<ul>
<li style="list-style-type: none;">
<ul>
<li><a href="https://www.itead.cc/sonoff-th.html">https://www.itead.cc/sonoff-th.html</a></li>
<li><a href="https://www.letscontrolit.com/wiki/index.php/ESPEasy">https://www.letscontrolit.com/wiki/index.php/ESPEasy</a></li>
<li><a href="https://www.amazon.com/s/ref=nb_sb_noss_2/134-0162784-3379579?url=search-alias%3Daps&amp;field-keywords=sonoff+th16">https://www.amazon.com/s/ref=nb_sb_noss_2/134-0162784-3379579?url=search-alias%3Daps&amp;field-keywords=sonoff+th16</a></li>
<li><a href="https://github.com/letscontrolit/ESPEasy/releases">https://github.com/letscontrolit/ESPEasy/releases</a></li>
</ul>
</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/home-automation-with-the-sonoff-th10-th16-with-php-fhem-json-and-how-to-flash/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to run FHEM as a Docker Container on a Raspberry Pi</title>
		<link>https://blog.gaiterjones.com/how-to-run-fhem-as-a-docker-container-on-a-raspberry-pi/</link>
					<comments>https://blog.gaiterjones.com/how-to-run-fhem-as-a-docker-container-on-a-raspberry-pi/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Wed, 31 May 2017 17:58:27 +0000</pubDate>
				<category><![CDATA[Docker]]></category>
		<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[fhem]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[raspberry pi]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1640</guid>

					<description><![CDATA[I use FHEM as the engine for home automation tasks on my Raspberry Pi. This is how to build and run FHEM as a container in Docker on your Raspberry...<a class="more-link" href="https://blog.gaiterjones.com/how-to-run-fhem-as-a-docker-container-on-a-raspberry-pi/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>I use <a href="http://fhem.de">FHEM</a> as the engine for home automation tasks on my Raspberry Pi. This is how to build and run FHEM as a container in Docker on your Raspberry Pi Zero, Pi2 or Pi3.</p>
<p><img decoding="async" src="https://blog.gaiterjones.com/dropbox/docker-fhem-container-installation.gif" alt="fhem docker container installation" class="aligncenter" /></p>
<h1>Install Docker</h1>
<p>Installing Docker is a no brainer</p>
<pre class="brush: plain; title: ; notranslate">
curl -sSL get.docker.com | sh
sudo usermod your-username -aG docker
reboot
</pre>
<h1>Install docker-compose</h1>
<p>Docker-compose makes building, starting and stopping Docker containers really simple.</p>
<pre class="brush: plain; title: ; notranslate">
apt-get -y install python-pip
pip install docker-compose
</pre>
<h1>Build the container</h1>
<p>Pull the container build files from github and run docker-compose build to build the container image.</p>
<pre class="brush: plain; title: ; notranslate">
git clone https://github.com/gaiterjones/docker-rpi-fhem
cd docker-rpi-fhem
docker-compose build
</pre>
<h1>Start the container</h1>
<pre class="brush: plain; title: ; notranslate">
docker-compose up -d
</pre>
<h1>Connect to FHEM</h1>
<p>Enter the following url into your browser to connect to FHEM.</p>
<p><strong>http://my.pi:8803/fhem</strong></p>
<p>Update FHEM by entering with the <em>update </em>command.<br />
Restart FHEM by entering the <em>shutdown restart</em> command.</p>
<p>FHEM is now running and up to date.</p>
<p>You can start configuring it or copy your existing FHEM config or editing the <em>fhem.cfg</em> file in <em>./fhem</em>. This is a Docker volume on the host mapped to <em>/opt/fhem</em> in the container. Docker host volumes will persist when you bring down the container (docker-compose down) or clear the volume caches (docker-compose down -v) so you will not lose your configuration or logs when the container restarts or is rebuilt.</p>
<h1>Customising</h1>
<p>Take a look at docker-compose.yml</p>
<pre class="brush: plain; title: ; notranslate">
# RPI
# FHEM CONTAINER
#
version: &quot;3&quot;

services:
    server:
        build: ./build/
        hostname: fhem
        domainname: home.com
        privileged: true
        ports:
          - &quot;8083:8083&quot;
          - &quot;7072:7072&quot;
        expose:
            - 8083
            - 7072
        volumes:
            - ./fhem:/opt/fhem
            #- /dev/ttyUSB0:/dev/ttyUSB0
        networks:
            - server
        restart: always
        healthcheck:
           test: &#x5B;&quot;CMD-SHELL&quot;, &quot;echo 'QUIT' | nc -w 5 localhost 7072 &gt; /dev/null 2&gt;&amp;1 &amp;&amp; echo 'FHEM OK'&quot;]
           interval: 15m
           timeout: 10s
           retries: 3
networks:
    server:
</pre>
<p>You can see we are configuring global ports 8083 and 7072 on the host as well as exposing them on the container. I have an SSL certificate installed on my Pi and use Nginx as a frontend proxy to my Docker containers, this lets me connect to FHEM using SSL</p>
<p><strong>https://my.pi/fhem</strong></p>
<p>To remove the global host ports delete or comment out the ports config leaving just the expose config. Nginx can be configured to proxy to fhem using the following configuration:</p>
<pre class="brush: plain; title: ; notranslate">
# FHEM
location /fhem {
  proxy_pass http://fhem_container_1:8083/fhem;
}
</pre>
<p>The container runs in privileged mode which gives it access to the hosts hardware and devices. If you are using external USB devices connected to the Pi you must add them as a volume in the container i.e.</p>
<p><strong>&#8211; /dev/ttyUSB0:/dev/ttyUSB0</strong></p>
<p>Make sure the fhem user running in the container has the same user id as your host user, in this case uid 1001.</p>
<pre class="brush: plain; title: ; notranslate">	 	 
user@raspberrypi:/dev# id your-user-name	 	 
uid=1001(your-user-name) gid=1001(your-user-name) groups=1001(your-user-name),27(sudo),996(docker)	 	 
</pre>
<p>This will ensure there are no permission problems when the container tries to access devices on the host.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/how-to-run-fhem-as-a-docker-container-on-a-raspberry-pi/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Magento Product Attribute Search and Filter</title>
		<link>https://blog.gaiterjones.com/magento-product-attribute-search-and-filter/</link>
					<comments>https://blog.gaiterjones.com/magento-product-attribute-search-and-filter/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Fri, 08 Aug 2014 13:26:31 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Magento Attribute Export]]></category>
		<category><![CDATA[Magento Product Attribute Search]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1216</guid>

					<description><![CDATA[The Magento product database is pretty flexible when it comes to extracting product information. Sometimes however, extracting all the information you want for a product is not so easy. For...<a class="more-link" href="https://blog.gaiterjones.com/magento-product-attribute-search-and-filter/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>The Magento product database is pretty flexible when it comes to extracting product information. Sometimes however, extracting all the information you want for a product is not so easy.</p>
<p>For example you want to extract the main product info, price, title, SKU etc <em>and</em> all the product attributes names <em>and</em> the product category. This might require multiple product / collection calls and when you multiply this by a search across 1000&#8217;s of products can become slow.</p>
<h2>Magento Product Attribute Search and Filter</h2>
<p>I wanted to provide a quick and easy way to <strong>search and filter magento products by attributes</strong>, in this case by colour, so customers could quickly narrow product selection down by selecting a <strong>colour</strong> and a filtering by <strong>category</strong>.</p>
<p>To extract the data I developed my<a title="Magento Product Data and Attribute Exporter" href="https://blog.gaiterjones.com/magento-product-data-attribute-exporter/"> Magento Product Data and Attribute exporter</a>. This let me initially see how many attributes I had to work with, in this case how many different product colours were already configured.</p>
<p>To make colour selection simpler I created a new Magento attribute <em>product_primary_colour</em> and added a primary colour to each product so that I ended up with about 16 main colours that would provide a match to all the existing product attribute colours.</p>
<p>Once I had all my exported product data in a tab delimited text file I quickly realised that it would be relatively simple to search and filter this data via ajax requests.</p>
<p>I had initially thought it would be more effective to do the search within Magento using product collections but the speed of the search against the delimited txt data file made me think again. When I then added cached search results using Memcache I was happy that this solution would work.</p>
<p>The benefits of using the flat txt file are that it is quick and can run completely external from Magento in another webapp or in WordPress or Facebook.</p>
<p>The Magento attribute search and filter is easily customiseable and can search the data created by the export script filtering results from any of the product data columns in the export file. This could be colour, size, type etc, there are no limits.</p>
<p>If your product data is changing regularly simply export the data regularly via a cron job to keep it up to date.</p>
<p>if you need to filter your data by a completely new attribute simply pull the export data into Excel, create your new attribute data and corresponding Magento attribute and import the data back into Magento. Now you can export this data and easily search and filter it.</p>
<p>Here is an example of the attribute search running in an iframe using the Magento test product data. Here I have exported the color attribute, and am filtering against existing product categories like Womens, Mens and Shirts (note Mens matches Wo<strong>mens, </strong>some refinement needed there!). This will also easily run in Magento when setup in a static block containing the iframe data.</p>
<p>You can see how quickly the data is filtered and returned, try a search for Red to see some data. Click around the categories and check the <strong>debug footer</strong> which shows if the results were cached or not and how long the ajax query took to run.</p>
<h2>Data from Magento DEV Store running Magento 1.9.x</h2>
<div class="iframe-container"><iframe src="https://blog.gaiterjones.com/dropdev/magento-attribute-search"></iframe></div>
<div></div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-product-attribute-search-and-filter/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Live Website / WordPress Data logging with Memcache</title>
		<link>https://blog.gaiterjones.com/live-data-logging-with-memcache/</link>
					<comments>https://blog.gaiterjones.com/live-data-logging-with-memcache/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Tue, 20 Aug 2013 12:16:14 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1024</guid>

					<description><![CDATA[Memcache is a bit like Jesus, all things to all men. Blasphemy aside, I love using Memcache for PHP application solutions. It is versatile, simple to use and very fast....<a class="more-link" href="https://blog.gaiterjones.com/live-data-logging-with-memcache/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1001" alt="" src="http://www.titan-pro.co.uk/docs/pageimages/logs.jpg" width="159" height="128" /></p>
<p>Memcache is a bit like Jesus, all things to all men. Blasphemy aside, I love using Memcache for PHP application solutions. It is versatile, simple to use and very fast.</p>
<p>This year I have used memcache for a whole bunch of great solutions. I wrote a <a title="PHP Memcache &amp; MYSQL Wrapper Classes" href="https://blog.gaiterjones.com/php-memcache-mysql-wrapper-classes/">memcache database wrapper class</a> to automatically use memcache to cache database queries &#8211; this increased the page loading time of a website considerably.</p>
<p>I used memcache for simple <a title="Efficient Page View Counter using PHP and Memcache" href="https://blog.gaiterjones.com/efficient-page-view-counter-using-php-and-memcache/">counters</a>, i.e. page visits and media plays &#8211; much faster than using a database.</p>
<p>I used it  to cache media playlists in memory for quick lookup and matching of current playing tracks on a <a title="Media Player for Apple Darwin Live Audio Streams" href="https://blog.gaiterjones.com/media-player-for-apple-darwin-live-audio-streams/">live darwin media stream</a> and I used it to cache <a title="Magento External – Display Magento Products on External Sites" href="https://blog.gaiterjones.com/magento-external-display-magento-products-on-external-sites-amazon-ebay/">Magento product data</a> used on eBay listings.</p>
<p>Today I have been using it to cache logging data (eBay product views) that can be quickly retrieved and displayed live using Ajax. My PHP logging class can be called from any PHP app to log any sort of data using memcache for super fast cached storage and retrieval.</p>
<p>The class logs data in arrays and saves them to memcache, the data can be set to expire whenever you like, the client then sets a timerange i.e. 30 minutes and queries memcache for all log data stored in that time range and displays it in real time using Ajax requests.</p>
<p>Because all the logging is done in memory it is very fast to log and to extract the data &#8211; much faster than using a database or writing to a logfile. At the moment I am not interested in storing the data so when the cache TTL expires the data is gone, but If required the data could be extracted asynchronously via a cronjob to a more permanent storage medium.</p>
<p>This method of caching log data and viewing it live could be used for any data you like not just web related stats, e.g. live orders, live product stocks, live tweets, etc. etc.</p>
<p>In the example below you see live logging data for the last 30 mins from this WordPress blog &#8211; the logging class is being called by WordPress every time a page loads, the iframe is loading a simple webpage that uses jQuery and Ajax to retrieve the log data every 10 seconds. Look at all those pesky bots!</p>
<div class="iframe-container"><iframe src="https://blog.gaiterjones.com/dropdev/PAJ/www/DataLogger/client/index.html"></iframe></div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/live-data-logging-with-memcache/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Deep Urban Monkey</title>
		<link>https://blog.gaiterjones.com/deep-urban-monkey/</link>
					<comments>https://blog.gaiterjones.com/deep-urban-monkey/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Thu, 08 Aug 2013 18:04:53 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1012</guid>

					<description><![CDATA[WordPress 3.6 now automatically embeds Soundcloud URLs in an HTML5 media player.]]></description>
										<content:encoded><![CDATA[<p>WordPress 3.6 now automatically embeds Soundcloud URLs in an HTML5 media player.</p>
<div class="hang-2-column">
<iframe loading="lazy" width="550" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?visual=true&#038;url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F3362722&#038;show_artwork=true&#038;maxwidth=550&#038;maxheight=825"></iframe>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/deep-urban-monkey/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Magento External &#8211; Display Magento Products on External Sites</title>
		<link>https://blog.gaiterjones.com/magento-external-display-magento-products-on-external-sites-amazon-ebay/</link>
					<comments>https://blog.gaiterjones.com/magento-external-display-magento-products-on-external-sites-amazon-ebay/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Wed, 10 Jul 2013 14:06:01 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=992</guid>

					<description><![CDATA[           Magento External allows you to extend your Magento shop to external sites such as eBay or Blogs like WordPress  by providing a simple AJAX interface...<a class="more-link" href="https://blog.gaiterjones.com/magento-external-display-magento-products-on-external-sites-amazon-ebay/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><a href="https://blog.gaiterjones.com/wp-content/uploads/2013/07/magento-icon.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1001" alt="magento-icon" src="https://blog.gaiterjones.com/wp-content/uploads/2013/07/magento-icon.png" width="140" height="140" /></a>           Magento External allows you to extend your Magento shop to external sites such as eBay or Blogs like WordPress  by providing a simple AJAX interface to your Magento Database and a new product attribute collection to use for describing products on external sites or blogs.</p>
<p>I  developed Magento External for use with eBay listings as a solution to listing many products with multi language descriptions controlling all the content from a central database &#8211; Magento.</p>
<p>Magento External lets you produce simple product description pages using data from your Magento shop database. If you are selling the same products across multiple retail platforms such as Amazon and eBay it makes sense to keep your product data centralised, and if you already have a Magento shop then using the information you already have in Magento for external sites makes a lot of sense.</p>
<figure id="attachment_1003" aria-describedby="caption-attachment-1003" style="width: 438px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2013/07/screenshot_01.jpg"><img loading="lazy" decoding="async" class=" wp-image-1003" title="Attributes for products available on Magento External" alt="" src="https://blog.gaiterjones.com/wp-content/uploads/2013/07/screenshot_01.jpg" width="438" height="312" srcset="https://blog.gaiterjones.com/wp-content/uploads/2013/07/screenshot_01.jpg 625w, https://blog.gaiterjones.com/wp-content/uploads/2013/07/screenshot_01-440x313.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2013/07/screenshot_01-620x442.jpg 620w" sizes="(max-width: 438px) 100vw, 438px" /></a><figcaption id="caption-attachment-1003" class="wp-caption-text">Attributes for products available on Magento External</figcaption></figure>
<p>&nbsp;</p>
<p>For eBay listings you can then also update your product info from your Magento admin, making it far easier to manage product listings.</p>
<p>The code utilises memcache to cache requests reducing load on your db.</p>
<ul>
<li><span style="line-height: 12px;">multi language</span></li>
<li>custom javascript menus</li>
<li>cross browser support (cross domain xdr supported)</li>
<li>custom images and header images</li>
<li>memcache support</li>
<li>supports simple, grouped, configurable products</li>
</ul>
<p>Here is an example eBay listing running here in an iframe. To see a live Magento external eBay listing send me an email.</p>
<div class="iframe-container"><iframe src="http://dev.gaiterjones.com/dropdev/magento-external/template.html"></iframe></div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-external-display-magento-products-on-external-sites-amazon-ebay/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>What is Facebook Edgerank?</title>
		<link>https://blog.gaiterjones.com/what-is-facebook-edgerank/</link>
					<comments>https://blog.gaiterjones.com/what-is-facebook-edgerank/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Sat, 15 Jun 2013 07:51:03 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=979</guid>

					<description><![CDATA[&#160; Facebook is a great social media marketing tool, first goal &#8211; get those likes. Second goal, improve your Edgerank to reach more customers with your meaningful Social Media content....<a class="more-link" href="https://blog.gaiterjones.com/what-is-facebook-edgerank/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Facebook is a great social media marketing tool, first goal &#8211; get those likes. Second goal, improve your Edgerank to reach more customers with your meaningful Social Media content.</p>
<p>You thought that Googles Pagerank was complicated, read on&#8230;</p>
<p><a href="https://blog.gaiterjones.com/wp-content/uploads/2013/06/edgerank-101-972.jpg"><img loading="lazy" decoding="async" class="hang-2-column           alignnone" alt="edgerank-101-972" src="https://blog.gaiterjones.com/wp-content/uploads/2013/06/edgerank-101-972.jpg" width="583" height="5526" /></a></p>
<p>&nbsp;</p>
<p>Courtesy of <a href="http://getpostrocket.com/" target="_blank">Postrocket</a>.</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/what-is-facebook-edgerank/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Media Player for Apple Darwin Live Audio Streams</title>
		<link>https://blog.gaiterjones.com/media-player-for-apple-darwin-live-audio-streams/</link>
					<comments>https://blog.gaiterjones.com/media-player-for-apple-darwin-live-audio-streams/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Wed, 17 Apr 2013 14:30:05 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=938</guid>

					<description><![CDATA[&#160; &#160; I am a great fan of the Apple Darwin Media Streaming server and use it for streaming live mp3 audio content. (by live I mean content that is...<a class="more-link" href="https://blog.gaiterjones.com/media-player-for-apple-darwin-live-audio-streams/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<p>&nbsp;</p>
<p><img loading="lazy" decoding="async" class="hang-2-column     alignnone" src="http://images.anandtech.com/doci/6313/photo2.PNG" alt="counter-icon" width="161" height="161" />I am a great fan of the <a title="Apple Darwin Streaming Server Compilation &amp; Installation for Linux" href="https://blog.gaiterjones.com/how-to-install-apple-darwin-streaming-server/">Apple Darwin Media Streaming server </a>and use it for streaming live mp3 audio content. (by live I mean content that is heard concurrently by all listeners).</p>
<p>I use the <a href="http://www.jplayer.org/" target="_blank">jQuery Player media player </a>which is a great cross browser compatible media player and have adapted it to work with Darwin audio streams. The latest version is specifically designed to provide audio content via a Facebook page tab. The application uses PHP and jQuery to provide a Facebook Tab cross browser compatible media player that can play live darwin media streams. It includes the ability to require page likes to listen to content,  display playlist information from an XSPF playlist, including track name, links to further content i.e. buy the track and a simple track like counter.</p>
<p>You can see it running as a Desktop Facebook Tab application <a href="https://www.facebook.com/pages/gaiterjones/243428839036258?sk=app_532513610126393&amp;app_data" target="_blank">here</a> and a standalone demo is available below. Mobile version is also available.</p>
<p>&nbsp;</p>
<div class="iframe-container"><iframe src="http://www.medazzaland.co.uk/facebook/darwinmediatab/?nolike=true&amp;standalone=true&amp;autoplay=false"></iframe></div>
<figure id="attachment_952" aria-describedby="caption-attachment-952" style="width: 226px" class="wp-caption alignnone"><a title="Mobile Version" href="http://www.medazzaland.co.uk/facebook/darwinmediatab/?mobile&amp;nolike&amp;standalone"><img decoding="async" class="wp-image-952 size-medium" src="https://blog.gaiterjones.com/wp-content/uploads/2013/04/iphone-media-player-226x440.jpg" alt="iphone-media-player" width="25%" srcset="https://blog.gaiterjones.com/wp-content/uploads/2013/04/iphone-media-player-226x440.jpg 226w, https://blog.gaiterjones.com/wp-content/uploads/2013/04/iphone-media-player-318x620.jpg 318w, https://blog.gaiterjones.com/wp-content/uploads/2013/04/iphone-media-player.jpg 368w" sizes="(max-width: 226px) 100vw, 226px" /></a><figcaption id="caption-attachment-952" class="wp-caption-text">Mobile version</figcaption></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/media-player-for-apple-darwin-live-audio-streams/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
