tag:blogger.com,1999:blog-196403982024-03-14T17:48:42.422+00:00Barry's BlogMy personal blog about stuff that happens which I can't fit on twitter or when I want to keep a diary.Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-19640398.post-28450118014989017152017-05-15T13:50:00.000+00:002017-05-15T13:53:50.615+00:00BBC Micro:bit Toothbrush TimerA few months back I bought a BBC Micro:bit at the Science Centre in Glasgow and it's been fun building apps with the single board device. I thought I'd write a blog entry about the latest project which will be a more permanent installation in our bathroom.<br />
<br />
A toothbrush timer!
<br />
<br />
Kitronik sell an add on board which provides power from a coin cell battery and a piezo buzzer called a Mi:power, they also sell a Mi:power case which is designed to fit around a Micro:bit fitted with the Mi:power. This assembly combined with some code offers a neat toothbrushing timer. By using the display on the front we provide a short countdown - with a little tune through the buzzer. The program show 6 areas of the mouth to brush each for 20 seconds before showing a toothy grin and a finishing tune. Each time the area of the mouth changes it plays a 'level up' style jingle.<br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3f9uij5vYoDLEZ-7_bq2mO-ggKkZEYYyuZIxqpIax0anJ8_J2qR7pALMTXJLq4kkQP0zsWxFQu4i0fN5ZkSAx7cpofT7pI3VzacVK3UQbGrKMjYuwog-VzSckwiV0Msou4lqWiA/s1600/IMG_20170515_142113312.jpg" imageanchor="1"><img border="0" height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3f9uij5vYoDLEZ-7_bq2mO-ggKkZEYYyuZIxqpIax0anJ8_J2qR7pALMTXJLq4kkQP0zsWxFQu4i0fN5ZkSAx7cpofT7pI3VzacVK3UQbGrKMjYuwog-VzSckwiV0Msou4lqWiA/s320/IMG_20170515_142113312.jpg" width="320" /></a>
<br />
<br />
Links to the parts:<br />
Mi:power <a href="https://www.kitronik.co.uk/5610-mipower-board-for-the-bbc-microbit.html">https://www.kitronik.co.uk/5610-mipower-board-for-the-bbc-microbit.html</a><br />
Mi:power case <a href="https://www.kitronik.co.uk/c5611-mipower-case-for-the-bbc-microbit.html">https://www.kitronik.co.uk/c5611-mipower-case-for-the-bbc-microbit.html</a><br />
<br />
Javascript Code:<br />
Create a new project at https://pxt.microbit.org/, choose the javascript tab and paste this code in.
<br />
<br />
<script src="https://gist.github.com/bazwilliams/b444417d623d5330c304c29400ebc5a2.js"></script>
Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-69846470694548971242016-01-29T19:17:00.002+00:002016-01-30T00:15:26.385+00:0012 Factor Config for .Net on Mono in a DockerRecently I've been thinking about how to run a .Net application using Mono inside a Docker, along with this we'd like to use <a href="http://12factor.net/config">Twelve Factor config</a>.<br />
<div>
<br /></div>
<div>
Whilst it is possible to use some library to access environment variables instead of using <span style="font-family: "courier new" , "courier" , monospace;">appSettings</span> it becomes difficult for database and message broker URLs which other libraries may expect to find within the <span style="font-family: "courier new" , "courier" , monospace;">App.config</span> or <span style="font-family: "courier new" , "courier" , monospace;">Web.config</span> file.<br />
<div>
<br /></div>
<div>
The solution I came up with follows:</div>
<div>
<br /></div>
<div>
Build the application <i>without</i> an <span style="font-family: "courier new" , "courier" , monospace;">App.config</span> moving the existing configuration file renaming it <span style="font-family: "courier new" , "courier" , monospace;">App.config.template</span>. </div>
<div>
<br /></div>
<div>
Substitute any environment variables you want with <span style="font-family: "courier new" , "courier" , monospace;">${}</span>. E.g:</div>
<div>
<br /></div>
<div>
<table class="highlight tab-size js-file-line-container" data-tab-size="8" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #333333; font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 13px; line-height: 18.2px; tab-size: 8;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td class="blob-code blob-code-inner js-file-line" id="LC15" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 12px; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre; word-wrap: normal;"><amqp>
<span style="line-height: 18.2px;"> <connections>
</span> <<span style="line-height: 16.8px;">connection name="rabbit" server="${RABBITMQ_URL}" password="${RABBITMQ_PASSWORD}" /></span>
<span style="line-height: 18.2px;"> </connections></span>
</amqp></td></tr>
</tbody></table>
</div>
</div>
<div>
<br /></div>
<div>
Include within the Docker image a script named <span style="font-family: "courier new" , "courier" , monospace;">sub.sh</span> similar to this and add it to <span style="font-family: "courier new" , "courier" , monospace;">/conf</span>:</div>
<div>
<br /></div>
<div>
<pre class="lang-sh prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="com" style="border: 0px; color: grey; margin: 0px; padding: 0px;">#!/bin/sh</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">while</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> read line
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">do</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">eval</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;"> echo </span><span class="str" style="border: 0px; color: maroon; margin: 0px; padding: 0px;">"$line"</span><span class="pln" style="border: 0px; color: black; margin: 0px; padding: 0px;">
</span><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">done</span></code></pre>
</div>
<div>
Add your config template to <span style="font-family: "courier new" , "courier" , monospace;">/conf</span></div>
<div>
<br /></div>
<div>
Then in the DockerFile, if your CMD is:</div>
<div>
<br /></div>
<div>
<pre class="lang-sh prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">CMD ["mono", "/app/foo.exe" ]</span></code></pre>
</div>
<div>
Change it to:</div>
<div>
<br /></div>
<div>
<pre class="lang-sh prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; color: #393318; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-size: 13px; margin-bottom: 1em; max-height: 600px; overflow: auto; padding: 5px; width: auto; word-wrap: normal;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; margin: 0px; padding: 0px; white-space: inherit;"><span class="kwd" style="border: 0px; color: darkblue; margin: 0px; padding: 0px;">CMD /conf/sub.sh /conf/App.config.template > /app/App.config; mono /app/foo.exe</span></code></pre>
</div>
<div>
Now when you run your Docker image, pass in your environment variables as usual. In this case, I'd set the <span style="font-family: "courier new" , "courier" , monospace;">RABBITMQ_URL</span> and the <span style="font-family: "courier new" , "courier" , monospace;">RABBITMQ_PASSWORD</span>. </div>
<div>
<br /></div>
<div>
You can also configure these in a file and pass it into the <span style="font-family: "courier new" , "courier" , monospace;">docker run </span>command using <span style="font-family: "courier new" , "courier" , monospace;">--env-file</span></div>
Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com1tag:blogger.com,1999:blog-19640398.post-81066430074409799422016-01-21T23:05:00.002+00:002016-01-21T23:11:20.509+00:00Howto: Node-RED Change Hue Lights Temporarily On Door Open<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
We fitted a LightwaveRF magnetic sensor to a door to detect whether it is open or closed. The main driver behind this was to increase the level of the hallway lights for a predetermined period of time whenever the door was opened. Since we’re using coloured lights it makes sense to put the light back to how it was once the time period as elapsed.
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
Node-RED does not offer a node as a means of storing state between, but it does offer functions which have access to a context object which can be used to store state between flows.
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
I’ve created a flow which listens to the `domoticz/out` MQTT topic filters messages based on their Domoticz IDX value and furthers filters on the door switches `nvalue` where 1 indicates door open and 0 indicates door closed.
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj41u0nzKM9Zsdi7_RCvrCUzsp0vrE8Jov-kL6R53btn9Sgh4GNv7NmVp0cG9oB-EnyKkdLf1mqJNPo8jaqFSUILd_OP7k4a8mB-6P3vIXK7102tR3UHG_kzKOiY_xDLOwxW7FEqg/s1600/Screen+Shot+2016-01-21+at+22.41.40.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj41u0nzKM9Zsdi7_RCvrCUzsp0vrE8Jov-kL6R53btn9Sgh4GNv7NmVp0cG9oB-EnyKkdLf1mqJNPo8jaqFSUILd_OP7k4a8mB-6P3vIXK7102tR3UHG_kzKOiY_xDLOwxW7FEqg/s640/Screen+Shot+2016-01-21+at+22.41.40.png" width="640" /></a></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<a href="https://dl.dropboxusercontent.com/u/174818/FrontDoorLight.json"></a><a href="https://dl.dropboxusercontent.com/u/174818/FrontDoorLight.json?dl=1">https://dl.dropboxusercontent.com/u/174818/FrontDoorLight.json</a></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
On Door Open:
</div>
<ol style="font-family: 'Helvetica Neue'; font-size: 14px;">
<li>Retrieve state of current light and if nothing already stored, store the current bulb state in the context. </li>
<li>Change the state of the bulb to a bright white. </li>
<li>Reset the timer in place if a door close event was received whilst the light is already bright. This would occur if the door is opened again whilst the light is in a brightened state. By not replacing the stored light state, we also avoid overwriting the original colour with the temporary brighter state. </li>
</ol>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
On Door Close:
</div>
<ol style="font-family: 'Helvetica Neue'; font-size: 14px;">
<li>Instruct the ‘Record or Despatch’ node to restore the original state which sends the original light colour to the timer. </li>
<li>If the timer has expired, the original state is sent onto the hallway bulb</li>
<li>A reset context message sent to the ‘Record or Despatch’ node to clear any saved light state. </li>
</ol>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
The ‘Record or Despatch’ node is a function with the following code:
</div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">if (msg.restore) {
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> node.send({payload: context.previousState});
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">} if (msg.reset) {
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> delete context.previousState;
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">} else {
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if (!context.previousState) {
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> context.previousState = msg.payload;
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }
</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace; font-size: xx-small;">}
</span></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
Feel free to download the full flow here: </div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<a href="https://dl.dropboxusercontent.com/u/174818/FrontDoorLight.json?dl=1">https://dl.dropboxusercontent.com/u/174818/FrontDoorLight.json</a></div>
Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-80487995614520219242016-01-21T21:51:00.003+00:002016-01-21T21:52:35.098+00:00Howto: Node Red Subflow for Hue BulbsWhen writing some flows for Node-RED controlling my Philips Hue bulbs; I wanted to read from a bulb do some work then write that same colour back to the bulb. When you perform a GET on a bulb, you get all of the information, whilst good this means it is a bit more inconvenient to PUT that back into a bulb as that API has a slightly different resource shape where the colour mode is determined by which values are submitted.<br />
<br />
After using a group of nodes in one flow which did exactly this, I needed the same block in another flow. So I created a sub flow by selected those nodes, clicking the hamburger menu in the top right and choosing 'Subflows > Selection to Subflow'. This replaces the selected nodes with a single node which you can edit in a 'subflows' menu group in the left pane.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizLBFeQUHJBs6AzIJCel5NL1tKsgRjefVTiQPyBD0K889hIBWyRnigtTWrndfg0iB_7EwamdW2Zw-eQ6xLi27jMFG_Csa0Nzua8FvMYR4pxD2ls2KJrcCoA0FRL2iZgzHNgFJImQ/s1600/Screen+Shot+2016-01-21+at+21.47.21.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizLBFeQUHJBs6AzIJCel5NL1tKsgRjefVTiQPyBD0K889hIBWyRnigtTWrndfg0iB_7EwamdW2Zw-eQ6xLi27jMFG_Csa0Nzua8FvMYR4pxD2ls2KJrcCoA0FRL2iZgzHNgFJImQ/s640/Screen+Shot+2016-01-21+at+21.47.21.png" width="640" /></a></div>
Download this selection and make your own subflow:<br />
<a href="https://dl.dropboxusercontent.com/u/174818/HueInputToOutput.json?dl=1">https://dl.dropboxusercontent.com/u/174818/HueInputToOutput.json?dl=1</a>Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-79159272847355705072016-01-20T21:37:00.000+00:002016-01-21T10:04:44.344+00:00Automatic Kitchen Lights<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
</div>
<br />
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
We recently purchased Hue bulbs for our Kitchen they’re great, but since we already have an RFXCom 433 unit (as per my blog on automating hifi), we wanted to automate the lights and invested in a Lightwave PIR motion sensor.
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAaL-SVZbzGUdBd6MIwP2U8a8tlByIwyrDCz5XWcA51erp_CBLZInq4HYu1tILSJBmecxDQ46IDnuliQLTxHy6ZrPW9SxUppB-3BRMwOsM8Tn9KtcxSZQFDeTOdil8f2Zu7Ljgmw/s1600/JSJSLW107SS_main.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAaL-SVZbzGUdBd6MIwP2U8a8tlByIwyrDCz5XWcA51erp_CBLZInq4HYu1tILSJBmecxDQ46IDnuliQLTxHy6ZrPW9SxUppB-3BRMwOsM8Tn9KtcxSZQFDeTOdil8f2Zu7Ljgmw/s200/JSJSLW107SS_main.jpg" width="200" /></a></div>
<div style="font-family: 'Helvetica Neue'; font-size: 14px;">
<br /></div>
<div style="font-size: 14px;">
<div style="font-size: 14px;">
<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
I downloaded Domoticz [<a href="http://domoticz.com/">http://domoticz.com/</a>] on an SD Card for my Raspberry PI and also installed node-red [<a href="http://nodered.org/">http://nodered.org/</a>] a tool for filtering and processing MQTT messages. </div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br clear="none" /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
Domoticz is used to store the state of the motion sensor and is configured to emit an MQTT message whenever the state changes.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br clear="none" /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
We also wanted the lights to have a different colour depending on the time of day we enter the kitchen, for example during the evening we might want a relaxing light, meal times a white light above the dining table and during the day some multi coloured lights, but not change them if they've already on.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br clear="none" /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
For each of the time slots of the day, a template has been created containing the settings of each of the main and dining lights and will send these on to the relevant light bulbs.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br clear="none" /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
When motion is triggered, the node-red flow decides which template to use and as an additional requirement, switches the lights off after a configurable delay once no motion has been detected.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
The flow is pictured below (click to download):<br />
<a href="https://dl.dropboxusercontent.com/u/174818/TimedKitchenLights.json?dl=1"><br /></a>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnF4S-zM1eh_MWm01BH6wo5xgFh60lOKWXkaK34tcD7MUBzxHiTm2jNMML0M2fWVnyTCy2lw6cTjVvATx36lsG1QU5XUmPonw7cjsjHSY85qje0nQKrKZx8ojDdFgcZf_QsqWQnQ/s1600/4C6F9A16-D8AE-4452-A07A-9749F68D0F69.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnF4S-zM1eh_MWm01BH6wo5xgFh60lOKWXkaK34tcD7MUBzxHiTm2jNMML0M2fWVnyTCy2lw6cTjVvATx36lsG1QU5XUmPonw7cjsjHSY85qje0nQKrKZx8ojDdFgcZf_QsqWQnQ/s640/4C6F9A16-D8AE-4452-A07A-9749F68D0F69.png" width="640" /></a></div>
<a href="https://dl.dropboxusercontent.com/u/174818/TimedKitchenLights.json?dl=1"><br /></a>
<a href="https://dl.dropboxusercontent.com/u/174818/TimedKitchenLights.json?dl=1"><br /></a>
<a href="https://dl.dropboxusercontent.com/u/174818/TimedKitchenLights.json?dl=1">Download the flow!</a><br />
<br /></div>
</div>
<div>
No Motion:
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
The PIR will send an 'off' signal when it detects no motion, a switch on the back can be used to configure this and I've set it to 2 seconds. If Domoticz receives an 'off' signal, then an MQTT message is sent and all messages received on ‘domoticz/out’ are received by this flow. The messages are filtered by the IDX value of the switch in Domoticz and a filter detecting motion indicated by the payload.nvalue. When the nvalue is 1, the message is directed to a trigger node which will delay it for 5 minutes. After 5 minutes, the trigger node will emit the same message to a 'turn light off' template the result of which is sent to both the dining table and main kitchen light.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
Motion:
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
The PIR will send an 'on' signal when it detects motion. If Domoticz receives an 'on' signal, then an MQTT message is sent and received by this flow filtered by the IDX value of the kitchen sensor in Domoticz and a filter detecting motion indicated by the payload.nvalue. When the nvalue is 0; this does 2 things.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
1: The message is directed to the 'Reset Timer' template node which generates a new message with a 'reset' attribute set to true, this is passed into the trigger node cancelling any timeout in process. This is useful if someone leaves the kitchen, the timer will start a countdown to switching the lights off after 5 minutes, but then cancel that countdown if someone walks back in before the lights have switched off.
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br /></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
2: The message is also directed to the 'Scene Chooser' which runs a function evaluating the current time and emitting a message on each of the applicable channels to template nodes which will generate some JSON to control the relavant dummy switches in Domoticz switching them off. The function has 5 outputs representing each scene we want:
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br />
00 - 06: Evening<br />
06 - 09: Breakfast<br />
09 - 12: Coloured<br />
12 - 14: Lunch<br />
14 - 17: Coloured<br />
17 - 20: Dinner<br />
20 - 22: Evening<br />
22 - 00: Coloured</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<br />
I've made the flow available to download from here:<br />
<span style="font-family: "helvetica neue";"><span style="font-size: 14px;"><a href="https://dl.dropboxusercontent.com/u/174818/TimedKitchenLights.json?dl=1">https://dl.dropboxusercontent.com/u/174818/TimedKitchenLights.json</a></span></span><br />
<span style="font-family: "helvetica neue";"><br /></span></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
Resources:
</div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<a href="https://www.npmjs.com/package/node-red-contrib-hue">https://www.npmjs.com/package/node-red-contrib-hue</a></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
<a href="https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's#Get_all_lights.2Fswitches"></a><a href="https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's#Get_all_lights.2Fswitches">https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's</a></div>
<div style="font-family: 'helvetica neue'; font-size: 14px;">
</div>
Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-34810231492269754102015-01-17T22:06:00.001+00:002015-01-17T22:06:51.331+00:00Linn DS Homebrew RCU with Playlist SupportAfter installing a hidden Linn DS for my bathroom, I found controlling it tricky, whilst using the phone is okay, I'd still like the convenience of a remote to switch off the music on the way out.<br />
<br />
I worked around this problem by extending the alarm clock functionality already in use for my kitchen to include a 'set standby' option. This would place the bathroom DS into standby mode at known times. Not ideal, but more useful.<br />
<br />
The Linn solution to this is a control panel on the wall which offers volume, power and a remote IR sensor. Whilst this gives me the ability to switch off on the way out. It would mean having a remote control in the bathroom to change source and not something I'd like. Since I'd added functionality to schedule stored playlists to start as well as the radio I convinced myself I also wanted the ability to preload a known selection of music at the press of a button. I'm a coder and after watching the RI Christmas lectures on 'hacking your home' I felt this was something I should do myself.<br />
<br />
After some online digging around I was going to go for a home grown button panel solution hooked up to a RaspberryPi in the loft; until a work colleague <a href="https://twitter.com/kylegordon">@kylegordon</a> suggested a home automation solution might be an alternative. After discovering the <a href="http://www.rfxcom.com/store/Transceivers/14103">RFXCom433 </a>and the <a href="http://www.lightwaverf.co.uk/LighwaveRF-Home-Automation-Lighting-Master-Wall-switch.html">LightwaveRF Mood Switch</a> I realised I could make this happen. Kyle also recommended a Node.js library <a href="https://github.com/bigkevmcd/node-rfxcom">https://github.com/bigkevmcd/node-rfxcom</a> which had support for everything I needed and would advertise the LightwaveRF button clicks as events.<br />
<br />
I ordered an RFXcom433 and a LightwaveRF Mood Switch/LightwaveRF inline relay bundle; the original idea was to replace the bathroom light switch tying the 'on' and 'off' buttons of the Mood switch to trigger the in-line relay (switching the bathroom light).<br />
<br />
On Friday I received all the bits.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKxe5TVlfSkVj2A4vnrjZ-HiIqpH8tVKvmOo_qtA6KNyLafTZ8-3BulaNmTkLui2YCuFImFFVyOZKaM8xrrcD-YY0aXw5JgdWx29_SQtPSOp0Z1SoWcz9I0_YP53gfqGO4CeCUIA/s1600/20150117_093252.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKxe5TVlfSkVj2A4vnrjZ-HiIqpH8tVKvmOo_qtA6KNyLafTZ8-3BulaNmTkLui2YCuFImFFVyOZKaM8xrrcD-YY0aXw5JgdWx29_SQtPSOp0Z1SoWcz9I0_YP53gfqGO4CeCUIA/s1600/20150117_093252.jpg" height="240" width="320" /></a></div>
<br />
I initially installed the Windows drivers and upgraded the firmware for the RFXcom, although it already had support for everything I wanted. I had a few issues getting the node-rfxcom package installed on windows due to a serialport dependency node-gyp which required python. Updating the package.json for node-rfxcom to a newer version of serialport (~1.4) solved this problem on windows.<br />
<br />
I then wrote a quick node.js app using the node-rfxcom library to send a LightwaveRF switch command on initialisation so I could pair the lightswitch, then display a console message on each button click afterwards.<br />
<br />
Once paired and working I transferred the RFXcom to my Debian Linux Microserver, where I found I needed no drivers for the RFXcom transceiver. The node.js app was updated to send HTTP calls to the <a href="https://github.com/bazwilliams/upnp-playlist-service">DS playlist service</a> to toggle standby and preload 1 of 3 named playlists.<br />
<br />
The code I wrote is on Github <a href="https://github.com/bazwilliams/home-automation">https://github.com/bazwilliams/home-automation</a>.<br />
<br />
After trying it out, I realised I didn't want to just toggle standby, I wanted to override the standby button to play radio if it was already off.<br />
<br />
'GroupOff' = Switch Off or Switch On and Play Radio<br />
'Mood 1' = Play 'preset1' playlist<br />
'Mood 2' = Play 'preset2' playlist<br />
'Mood 3' = Play 'preset3' playlist<br />
<br />
After installing this on the wall next to the lightswitch I realised, the top buttons could be refashioned as volume controls and I could leave the existing 'manual' light switch. I added some new endpoints to the upnp-playlist-service to increase or decrease the volume of a Upnp device via a RESTful HTTP call and reconfigured the home-automation app to call these when the buttons are pressed.<br />
<br />
After just a day, I've got a fully functional control pad on the wall, controlling my bathroom DS giving me, power, volume, radio and preset playlist support!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOlrNVXNJgcjNzh4MOKivX0baP7pR6OGKMh2TpF7wJ4vB2I2Q1z2WVmjz9hNfxuPt2BhUODy4MoXnHBbW1ecIyCk7zWT5QE1pNYbKxZzGw1mrmDNV7nOTC3tPYXulDreQ_TnBHAw/s1600/20150117_215603.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOlrNVXNJgcjNzh4MOKivX0baP7pR6OGKMh2TpF7wJ4vB2I2Q1z2WVmjz9hNfxuPt2BhUODy4MoXnHBbW1ecIyCk7zWT5QE1pNYbKxZzGw1mrmDNV7nOTC3tPYXulDreQ_TnBHAw/s1600/20150117_215603.jpg" height="240" width="320" /></a></div>
<br />
I've also got a spare radio controlled relay burning a hole in my pocket for installation somewhere - I'm thinking my outdoor light could do with some geofence based control!Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-65195405778361854052014-05-15T18:04:00.002+00:002014-05-15T18:09:47.901+00:00Test Driven DevelopmentRecently I watched David Heinemeier Hanson's controversial railsconf keynote and I thought I'd express my views.<br />
<br />
His main argument suggests TDD is dead. Oddly I agree with many of his headline views which I try to document below. I just not convinced of his supporting arguments.<br />
<br />
DHH appears to have a dim view on TDD practicing developers; whom he generalises write simple unit tests having 100% code coverage, use many mocks, but test nothing real. His example was a bug in Basecamp which lost customer data, their code had 100% code coverage, but still didn't work. I really doubt there are many developers who just stop when they hit 100% unit test coverage?<br />
<br />
I'm not going to speak for everyone else; I only started using TDD (not exclusively) about 18 months ago despite 12 years developer experience writing some really cool stuff, some well designed and some not so well...<br />
<br />
The well designed stuff has tended to be driven by TDD. I've never used code metrics, I use TDD to help focus my mind on the current thing to write. By factoring a problem down into smaller chunks I can focus very well and avoid 'coders block'. I've never approached factoring from a test perspective, I've tended to think how the architecture should be sculpted and broken down. I can usually find a bite-size component to write a test for and implement, it also ensures you can optimally test many permutations of a system using more than 1 unit. More importantly, the tests I write provide a specification for what I expect that thing to do.<br />
<div>
<br /></div>
This practice has a danger that you might forget what you originally started to break down - 'the story'. I'm not going to pretend I've never had 100% tests pass and no working system, in fact recently I wrote an email sending service, but forgot to include a real template so the email would be sent to the correct people, but with no body (I'd mocked the template in a test and asserted the correct data was received), this system was never deployed but if I'd concentrated solely from a point of unit tests it could have been. In this and other cases you still need a guiding light to ensure you don't write a suite of insufficient tests or even direct development in the wrong direction. In this example an integration test using the real template was sufficient. This provided me with confidence the the units were being invoked correctly and if the template were to be broken in the future I am confident the test would fail.<br />
<br />
Where I work we use integration tests to ensure the services use unit tested modules correctly and ultimately acceptance testing to ensure things do work as the user expected using real databases and real services; only in very rare cases components are faked for acceptance testing if absolutely required (say to avoid sending real emails).<br />
<br />
I like decoupled unit tests with an encompassing system level test. Testing only at integration level would lead to far too many permutations of code paths which could lead to poorer test quality.<br />
<br />
I am also happy that acceptance tests take a while to run too, with automated tools like Selenium you can perform this within a few minutes before a push. The integration tests run in less than 10 seconds and the unit tests are pretty fast.<br />
<br />
A big danger when using mocks during testing is where your assumptions have changed, say a field is removed or renamed in a web service or database response. If this data has been stubbed in your test, your test will always pass despite never being able to work for real. These types of problems I'd never really encountered before using TDD. It makes code reversibility difficult as the production code migrates to a new style of architecture the tests might not be properly aligned meaning problems occur in user testing that really should have been caught during the code redevelopment.<br />
<br />
I admit in a few cases I've wondered why some unit tests run slowly and I will investigate the production code to see if it something that can be optimised. Sometimes something I have no control over but has a known and fixed interface can be safely mocked out. However if it the test is slow because of the production code, I'm not going to cut corners just to make the test suite run faster, that reduces the usefulness of the test. Architecture and production code should become the first priority once the associated tests give a certain level of confidence.<br />
<br />
DHH further generalises his view of a developer to one that then 'sprinkles some design patterns' on their code once their tests pass.<br />
<br />
I only recently started reading about design patterns and I realised I'd already been using them for many years only now I had a name for the shape of the code and could describe an implementation with a common language.<br />
<br />
Toward the end of his talk DHH advocates readability which I wholeheartedly agree with, I really like using functions which read like 'reject where x is y' rather than 'filter x is not y' or 'unless x' in favour of 'if not x'. I'd rather the code explains what it does than have a comment which may not age well.<br />
<br />
Finally, the way DHH got a clap for mentioning the delete key is the best way to improve code reminded me of Steve Jobs getting applause for announcing an HDMI cable in an Apple keynote...<br />
<br />
I watched this Hangout with interest:<br />
https://plus.google.com/events/ci2g23mk0lh9too9bgbp3rbut0k<br />
<br />
And will be watching the second part too:<br />
https://plus.google.com/u/0/events/couv627cogaue9dahj08feoa6b8<br />
<br />Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-70097445833776417072013-12-20T10:36:00.000+00:002014-09-22T19:17:15.545+00:00Linn DS Alarm Function<i><b>Update 2014</b> - An alternative to this is available on GitHub which uses Node.js and should be cross platform. <a href="https://github.com/bazwilliams/upnp-playlist-service">Linn DS Playlist and Alarm Server</a></i>
<br/>
<br/>
Switching the radio on in the kitchen in the morning is a low priority amongst setting table, pouring cereals, carrying children, etc. The Sonos has an alarm clock facility which allows you to switch on the radio at a set time avoiding hassle of starting a controller.
<br />
<br />
When I upgraded to my Linn Sneaky DS, I no longer had this function, though the remote control made it easy if I forgot to take my phone downstairs with me.
<br />
<br />
Last week I decided to figure it out. I have a Linux machine which runs Ubuntu and runs all the media servers, backups and network shares. I decided to investigate how to control my DS from the command line.
<br />
<br />
Conveniently, the DS can be controlled via a web api, so after reading the docs and a few examples I was able to switch off and on and change source via Postman (Chrome REST client).
<br />
<br />
I then set about writing a curl script to send the commands and package this up as a shell script.
<br />
<br />
One final problem was discovering the IP address of the DS which I solved by using gupnp-tools which has a scanner; this scans my network for UPNP devices and since I know the UUID of the DS I can extract the correct IP address.
<br />
<br />
By adding the script to my Linux box' crontab, the DS starts on the radio each weekday morning.<br />
<br />
<h4>
How it works</h4>
<br />
Need to install <span style="font-family: Courier New, Courier, monospace;">gupnp-tools</span> which provides <span style="font-family: Courier New, Courier, monospace;">gssdp-discover</span>.
<br />
<br />
I created a script called <span style="font-family: Courier New, Courier, monospace;">discover.sh</span> which takes a parameter of the UUID of a Upnp device and returns the IP address:
<br />
<br />
<pre>#!/bin/sh
gssdp-discover -t ${1} -n 3 | grep Location | sed 's/.*http:\/\///' | sed 's/:.....\/.*//'
</pre>
<br />
Next is a script called <span style="font-family: Courier New, Courier, monospace;">source.sh</span> to set the source of the DS:
<br />
<br />
<pre>#!/bin/sh
curl -X POST -d @${2} $1/Ds/Product/control --header "Content-Type:text/xml" --header "Accept:text/xml" --header "SOAPAction:urn:av-openhome.org:service:Product:1#SetSourceIndex"
</pre>
<br />
This takes in 2 parameters, the first is the IP address of the device you want to control and the second is a file containing an XML body containing details of which source to set on the device, in this case, it is the radio function (source Id 1):
<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">radio.xml</span><br />
<pre><?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<u:SetSourceIndex xmlns:u="urn:av-openhome.org:service:Product:1">
<Value>1</Value>
</u:SetSourceIndex>
</s:Body>
</s:Envelope>
</pre>
<br />
Finally it's all put together in the following script. Set the SCRIPTS property to where you've saved the files above. Set the UUID property to the UUID of your DS - you'll need to scan your network to find this. In Windows, my DSs appear in the network view of Windows Explorer and I can see the unique identifier (UUID) if I right click the DS and view properties.
<br />
<br />
<pre>#!/bin/sh
SCRIPTS=/home/barry/scripts/ds
RADIO=${SCRIPTS}/radio.xml
UUID=uuid:4c494e4e-0026-0f21-d74b-013330780171
DS=`${SCRIPTS}/discover.sh ${UUID}`
${SCRIPTS}/source.sh ${DS} ${RADIO}
</pre>
<br />
Now just add it to your crontab:<br />
<pre>45 6 * * 1-5 /home/barry/scripts/kitchen_radio.sh
</pre>
<br />
Enjoy one less thing to do in the morning :)
<br />
<br />
Here's the api documentation for the DS:
<br />
<a href="http://docs.linn.co.uk/wiki/index.php/Developer:Davaar">http://docs.linn.co.uk/wiki/index.php/Developer:Davaar</a>Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com9tag:blogger.com,1999:blog-19640398.post-90275507043224435252013-02-01T23:17:00.002+00:002013-03-02T23:25:37.700+00:00Asus AT37N7A-I Nvidia ION Linux ConfigurationI've been using this excellent motherboard for about 2 years, it has now been disassembled as I had less of a need for a silent PC in the living room after retiring my use of MythTV.<br />
<br />
I had Ubuntu installed on this PC and during its lifetime was subjected to many performance tweaks. Rather than delete this work, I've decided to put the files online for other people to use.<br />
<h3>
Sound</h3>
I wanted digital sound over the HDMI cable so it can be played by either my TV or AV amp; I've played back DTS HD with this configuration, my TV had issues with some sample rates which is why the rate is configured explicitly.<br />
<h4>
asoundrc</h4>
<pre>pcm.!default front
pcm.analog-hw {
type hw
card 0
device 0
}
pcm.analog-hw-formatted {
type plug
slave {
pcm analog-hw
rate 48000
}
}
pcm.digital-hw {
type hw
card 0
device 3
}
pcm.digital-hw-formatted {
type plug
slave {
pcm digital-hw
rate 48000
}
}
pcm.hdmi_softvol {
type softvol
slave.pcm digital-hw-formatted
control.name hdmi_volume
control.card 0
}
</pre>
<h3>
Video </h3>
These are my xorg.conf settings for use with my Sharp Aquos 32" TV, this has been optimised for use with MythTV specifically playback of 1080p playback at 50Hz, 60Hz and 24Hz.<br />
<h4>
xorg.conf</h4>
<pre>Section "ServerLayout"
Identifier "Default Layout"
Screen "Default Screen" 0 0
EndSection
Section "Monitor"
#Sharp AQUOS Screen Dimension: 701mm x 394mm
Identifier "Television"
VendorName "Sharp"
ModelName "LC32LE600E"
DisplaySize 701 394
EndSection
Section "Device"
Identifier "ION-HDMI"
Driver "nvidia"
Option "NoLogo" "true"
# If not disabled I can't select 24Hz or 60Hz refresh rates
Option "DynamicTwinView" "false"
Option "NoFlip" "false"
Option "FlatPanelProperties" "Scaling = Native"
Option "ModeValidation" "NoVesaModes, NoXServerModes, NoPredefinedModes"
Option "ModeDebug" "true"
# Options for MythTV performance
Option "TripleBuffer" "True"
Option "UseEvents" "True"
Option "HWCursor" "False"
# Removes non selected modes
Option "IncludeImplicitMetaModes" "false"
Option "ExactModeTimingsDVI" "True"
Option "DPI" "100 x 100"
EndSection
Section "Screen"
Identifier "Default Screen"
Device "ION-HDMI"
Monitor "Television"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
Modes "1920x1080_50" "1920x1080_24_0" "1920x1080_60_0"
EndSubSection
EndSection
Section "Extensions"
Option "Composite" "Disable"
EndSection
</pre>
<h4>
nvidia-settings </h4>
On startup, nvidia-settings is called with the following parameters:
<br />
<br />
<pre>nvidia-settings -a "SyncToVBlank=1" -a "AllowFlipping=1" -a "FSAAAppControlled=1" -a "OpenGLImageSettings=3" -a "LogAniso=0" -a "GPUScaling[DFP-0]=1,1"; nvidia-settings -r</pre>
<h4>
Mplayer</h4>
Here are the mplayer-config settings for smooth playback using the GPU:
<br />
<br />
<pre>fs="1"
ao=alsa:device=hdmi
vo=vdpau
vc=ffmpeg12vdpau,ffh264vdpau,xvid
</pre>
<h4>
MythTV</h4>
There is extensive documentation on the MythTV wiki so I won't repeat that here, for reference though:<br />
<br />
http://www.mythtv.org/wiki/Frame_display_timing<br />
http://www.mythtv.org/wiki/Vdpau<br />
http://www.mythtv.org/wiki/User_Manual:JudderFreeBarryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-1375612034625155202012-11-30T20:46:00.000+00:002012-11-30T20:49:11.709+00:00Letters and Press ButtonWe purchased an iPad last year for my son to use and in the year he has become eerily proficient with the touchscreen interface. The educational applications have been very good and still use it for this purpose; however more recently it is being used as a video player... Whilst I'm not particularly against this, I would rather he start creating content rather than merely consuming it.<br />
<br />
One problem with being used to touchscreen is the keyboard and mouse paradigm is alien - it must be really weird to have to press a keyboard key located somewhere else. I imagine using a keyboard for the first time would be like writing notes on a piece of paper but the ink actually appears on a different pad.<br />
<br />
Anyway, keyboards are here to stay and I want my son to learn how to use a keyboard as well as learn the alphabet (he is already pretty good at numbers). Therefore as part of my Raspberry Pi setup, I purchased a <a href="http://duragadget.com/products/large-coloured-child-proof-usb-computerlaptoppc-keyboard--w-big-keys-for-kids.html">Duragadget keyboard</a> for my son to use, this has large keys, lower case letters and coloured for vowels, consonants, numbers and symbols.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://duragadget.com/products/large-coloured-child-proof-usb-computerlaptoppc-keyboard--w-big-keys-for-kids.html"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq6CmC_LqoVKks_VUzGuaX_s0XcCdk5BMuq9In4tECW6Tx9DJCLoyjfRVJyCnIl-7pyBfLqlP_ZHZON6fJuNy-vuikHXRcKTPo-3ty_wEFp6YGfZxw7RQWN8n7tP0K9IcbKfhxxw/s320/lrgscale624_4.jpeg" width="320" /></a></div>
<br />
<br class="Apple-interchange-newline" />
Since I've learned Javascript over the past few weeks it seemed to make sense to use this as a platform for the application. It is a simple program to display an alphabet letter using the same font face as the keyboard (apparently Comic Sans is easier for children to read). The letter is enclosed within a shape coloured the same as the keyboard and will change when the correct key is pressed.<br />
<br />
The program will prioritise those characters which have been incorrectly typed already thus helping practice those. After three wrong attempts a new character is displayed, also holding a key down won't generate repeat attempts.<br />
<br />
Some future changes include a mode change to allow the display to be driven by the keyboard - i.e. select a key and see it on the screen. Also when 3 incorrect keys are pushed, I'd rather replace it with a character which has had a higher success rate.<br />
<br />
The scoring system is all in place, but isn't used for anything other than biasing key selection, I'd like some kind of reward system on the page - perhaps a space rocket lifting off or something...<br />
<br />
I was very pleased that my son was very receptive to it, even this early version. I felt extremely proud when he wanted to play "Letters and Press Button" instead of watching Peppa Pig!!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH08jSR6XpoxjDL0nqQhGb3hTij2PbQNOy4mP8dgL4jsNrWhj7Elyejf8yrirGNDrF5MiSlVDyVcOwOMdYCxaGlGjMVfH4q8bktXW4S2qJZUSAn1afSu5htGrpjfH94wSFbAwuag/s1600/untitled+shoot+-+_B304888.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH08jSR6XpoxjDL0nqQhGb3hTij2PbQNOy4mP8dgL4jsNrWhj7Elyejf8yrirGNDrF5MiSlVDyVcOwOMdYCxaGlGjMVfH4q8bktXW4S2qJZUSAn1afSu5htGrpjfH94wSFbAwuag/s320/untitled+shoot+-+_B304888.jpg" width="320" /></a></div>
<br />
The program is hosted on GitHub at <a href="https://github.com/bazwilliams/bazapp">https://github.com/bazwilliams/bazapp</a><br />
<br />
A live running version of the program is at: <a href="http://bazwilliams.github.com/bazapp/characters.html">http://bazwilliams.github.com/bazapp/characters.html</a>Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-53939834261293588982011-12-05T09:10:00.005+00:002011-12-18T14:59:44.487+00:00Initial Thoughts on an iPad 2 for ToddlersI'm a bit late to the game here, but I've been swithering over the iPad 2 as an educational device for my son.<br /><br />Whilst I've been an Apple Mac OS X user since 2005, the iPhone and subsequent iOS devices have never appealed and I prefer the Android ecosystem. However in terms of applications - specifically educational ones - nothing can beat iOS, in fact, I wouldn't even consider purchasing an Android tablet.<br /><br />A combination of my son soon being two and the recent black friday sales at the Apple store I felt the time was right to go ahead and purchase one. So I purchased a white iPad 2 with the green smart cover.<br /><br />We've had it in the house now for 1 week and I think it is a great device. I have a few issues, for example why can't the keyboard keys show capitalisation so you see what case you have? There is no haptic feedback unlike HTC when pressing an active part of the screen which means sometimes you don't know if that is really a button or not. Also my son loves pressing that home button - an option to disable it would be useful.<br /><br />Quickly overcoming these I searched the app store to see what apps I could purchase for my toddler.<br /><br />At this point things became a bit more difficult as Apple's app store doesn't appear to be well laid out for finding applications targeted for specific preschool age groups. The 'popular' apps were all aimed at spelling and maths which Ethan is a bit young for. So the point of the next few posts is to highlight iPad applications which my 19 month old son has shown a positive interest in. Some initial applications are below, but over the next few posts I'll go into them in a bit more detail with direct links to the iTunes store once I work that bit out!<br /><ul><li>Abby's Magic Laptop for Preschool and Toddlers</li><li>Shapes Toddler Preschool (Toy Box function)</li><li>Toddler's Seek & Find: My Animals</li><li>Toddler's Seek & Find: My Little Town</li><li>Zoo Train (for building trains and recognising objects)</li><li>Fisher-Price Laugh & Learn Range</li></ul><br />Update:<br />We've had the iPad now for 2 weeks and it is spooky how quickly he has adapted to it. He knows to press the home button and how to swipe to choose a different app. Some apps have further subsections (Zoo train) and he hovers over each icon to choose which activity to do. Then when he gets bored has worked out where the 'back' arrow is to choose another activity.<br /><br />Ethan seems to prefer the musical section of Zoo Train at the moment and will dance along to the rhymes.<br /><br />A few more recommended apps:<br /><ul><li>Ladybird: First Words (British accent too a major plus)</li><li>ClickySticky</li><li>JukeBox (Americanised nursery songs, Ethan likes it)<br /></li></ul>Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com0tag:blogger.com,1999:blog-19640398.post-51930922300676108302009-08-13T22:09:00.008+00:002013-01-16T23:46:00.165+00:00Dell 5530 / Ericsson f3507g 3G Signal Monitor on LinuxA few months back I made a python script available which monitored the Dell 5530 / Ericsson f3507g mobile broadband modem in Linux providing network, access type and signal information to a file for other programs (such as Conky) to pick up and display the data. <br />
<br />
I've since updated this program to now use PyGTK to display a status icon indicating the signal strength and the access type. Through this icon the radio state can be changed to enforce 3G only, GPRS only or 3G preferred connections (aswell as turning the radio off). <br />
<br />
The script should work in tandem to network-manager so you can still get online using something you already use. The only addition is a new status icon with your signal strength - something ModemManager should resolve when it becomes available as standard in a few months time. If you can't wait that long and want signal monitoring, then this is for you! <br />
<br />
Additionally, if you use vnstat to monitor your bandwidth, clicking the status icon will display your current months usage for ppp0. <br />
<br />
Dell 5530 / Ericsson f3507g 3G Signal Monitor for Linux<br />
<br />
<i>Update: Now lives on GitHub at <a href="https://github.com/bazwilliams/dell5530mon">https://github.com/bazwilliams/dell5530mon</a></i><br />
<br />
Hopefully someone may find this program useful! If you do, why not consider donating to <a href="http://www.justgiving.com/Anne-and-Louise/">Multiple Sclerosis</a>? There is a sponsorship button on the front page of my blog or at <a href="http://www.justgiving.com/Anne-and-Louise/">JustGiving</a>Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com1tag:blogger.com,1999:blog-19640398.post-76329543757589001212009-03-12T08:28:00.003+00:002013-03-04T08:53:49.592+00:00Dell 5530/Ericsson f3507g on LinuxA few months back I posted a howto guide on getting this mobile broadband card working with Linux, what I failed to mention was I continued to work on these scripts. I feel it is appropriate to post a status update on what I use now especially given there appears to be no further updates on the NetworkManager front.<br />
<br />
I no longer use <code>UMTSMon</code> as I found it relied on <code>AT+CSQ</code> for the signal quality and during UMTS and HSPA connections, the f3507g/dell 5530 returns either the previous GPRS value or <code>99,99</code> which <code>UMTSMon</code> considers as no connection available.<br />
<br />
I've used a simplified <code>wvdial.conf</code> scripts and now do the rest of the radio work using python.<br />
<br />
<b>wvdial.conf</b><br />
<code><br /># Author: Barry John Williams<br /># Creative Commons Attribute-Share Alike 2.5 UK:Scotland Licence<br /><br />[Dialer defaults]<br />New PPPD = yes<br />Stupid Mode = 1<br />Modem Type = ACM Modem<br />Modem = /dev/ttyACM1<br />Init1 = AT<br />Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0<br />Init3 = AT+CGDCONT=1,"ip","internet"<br />Baud = 460800<br />ISDN = 0<br />Phone = *99***1#<br />Password = web<br />Username = web</code><br />
<br />
You will need to update the <code>Init3</code> command for your own provider and the password and username for your service. In this case it is set up for Vodafone UK.<br />
<br />
To dial up to the web I currently use <code>ppptray</code> which is a python app and displays an icon in your notification area which you click to toggle connectivity. Behind the scenes it calls <code>pon</code> and <code>poff</code> which in turn use <code>wvdial</code> to enable the connection.<br />
<br />
I modify my <code>pon</code> and <code>poff</code> scripts to just call the default <code>wvdial configuration</code>. You can find <code>pon</code> and <code>poff</code> in <code>/usr/bin</code>.<br />
<br />
<b>pon</b><br />
<code><br />#!/bin/sh<br /><br /># Author: Barry John Williams<br /># Creative Commons Attribute-Share Alike 2.5 UK:Scotland Licence<br /><br />PATH=/bin:/usr/bin:/usr/sbin:/sbin<br />wvdial >> /var/log/ppp.log 2>&1</code><br />
<br />
<b>poff</b><br />
<code><br />#!/bin/sh<br /><br /># Author: Barry John Williams<br /># Creative Commons Attribute-Share Alike 2.5 UK:Scotland Licence<br /><br />PATH=/bin:/usr/bin:/usr/sbin:/sbin<br />kill `lsof /dev/ttyACM1 | grep wvdial | awk '{print $2}'`</code><br />
<br />
I have written a python program (<code>dell5530_mon.py</code>) which monitors the broadband card on <code>/dev/ttyACM0</code>. It polls the card every few seconds requesting the current network provider, access type and signal quality (even for UMTS connections). This information is made available in the <code>/tmp</code> directory:<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<table><tbody>
<tr><td><code>MB_NETWORK</code></td><td>The current network provider (e.g. Vodafone UK)</td></tr>
<tr><td><code>MB_SIGNAL</code></td><td>The current signal strength represented using characters from the 'PizzaDude Bullet' font (downloadable from dafont.com)</td></tr>
<tr><td><code>MB_TYPE</code></td><td>The current network access type (GPRS, 3G, 3G+, NONE)</td></tr>
</tbody></table>
<br />
<br />
These files are only updated if there is a change from the previous value, additionally my <code>/tmp</code> folder is on a ramdisk to save SSD writes so you may want to either do this or move the files to another volatile location.<br />
<br />
<code>dell5530_mon.py</code> also uses <code>pynotify</code> to display a notification if the network provider changes or the connection type changes. This is useful if you are travelling through different signal areas, you are notified when the signal is lost or moves from 3G to 3G+ for example.<br />
<br />
I run the monitor on startup automatically switching the radio on, it also enables the radio whenever I resume my machine from standby, this just leaves clicking the ppptray button to go online. I intend to bring this functionality within <code>dell5530_mon.py</code> but haven't done so yet. My goal is to automatically connect to the web if no other connection is available and provide the signal strength in the notification area (with ability to toggle radio and connection states from a context menu).<br />
<br />
In the meantime, I use conky to read the values stored in the <code>/tmp</code> directory to display the current network operator, connection type and signal quality in addition to receiving the notifications.<br />
<br />
I hope people find this useful, all the code is made available under a creative commons licence and can be downloaded below:<br />
<br />
<strike>Dell 5530 Python Monitor (dell5530_mon.py)</strike><br />
<br />
<span style="font-weight: bold;">Note, A newer version of the script with a Notification Area GUI is available here: </span><a href="http://blog.bjw.me.uk/2009/08/dell-5530-ericsson-f3507g-3g-signal.html" style="font-weight: bold;">http://blog.bjw.me.uk/2009/08/dell-5530-ericsson-f3507g-3g-signal.html</a><br />
<br />
Note this also comes with a <code>radio.py</code> library which can be used as a standaline program to get the status of the radio and enable/disable it. At the moment I've configured <code>dell5530_mon.py</code> to enable the radio in 3G only mode (since mine kept falling back to a GPRS signal despite 3G being available). If you want it to connect to both types of networks, you will need to change a line in <code>dell5530_mon.py</code> from <code>radio.on(ser,radio.UMTS)</code> to <code>radio.on(ser,radio.PREFER)</code>.<br />
<br />
Once the monitor has detected a network operator, it tries to enable the GPS functionality on <code>/dev/ttyACM2</code>. However, this appears to be a bit hit and miss...<br />
<br />
Useful Links:<br />
<ul><br />
<li><a href="http://blog.bjw.me.uk/2008/12/howto-ubuntu-810-dell-5530-3gwwan-and.html">My older dell 5530 howto</a></li>
<br />
<li><a href="http://www.dafont.com/search.php?psize=m&q=pizzadude+bullets">Pizzadude Bullet Font (For displaying signal quality in Conky</a></li>
<br />
<li><a href="http://www.natisbad.org/E4300/">Linux on Dell Latitude E4300 - a guide on setting the Dell 5530 up using its ethernet functionality instead of ppp</a></li>
<br />
<li><a href="http://www.natisbad.org/E4300/Dell_Wireless_5530_AT_cmd_ref.html">A comprehensive guide on the AT Commands available on the Dell 5530</a></li>
</ul>
Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com13tag:blogger.com,1999:blog-19640398.post-39358579423957141782008-12-01T21:16:00.004+00:002013-03-04T08:53:53.176+00:00Howto: Ubuntu 8.10, Dell 5530, 3G/WWan and GPS<i>There is an updated howto on the Dell 5530 using my own python based monitoring tool at <a href="http://blog.bjw.me.uk/2009/03/dell-5530ericsson-f3507g-on-linux.html">http://blog.bjw.me.uk/2009/03/dell-5530ericsson-f3507g-on-linux.html</a></i><br />
<br />
<span style="font-weight: bold;">Introduction</span><br />
<br />
Here is a Howto document for getting the Dell 5530 wwan card working along with the onboard GPS under Ubuntu 8.10. This card does not work conveniently with the bundled Network Manager software, but replacing NetworkManager with other utilities will give the ability to get online using a pretty GUI and not have to resort to using wvdial and the command line... <br />
<br />
It should also work with the Ericsson f3507g as I believe the Dell 5530 is a rebadged version of this module. <br />
<br />
<span style="font-weight: bold;">Check Hardware</span><br />
<br />
First you need to check the modem is detected correctly. On my computer, the modem is detected out of the box by the cdc_acm module and exposes three serial ports (/dev/ttyACM[0,1,2]) for communication. Check by running:<br />
<br />
<code>dmesg | grep ACM</code><br />
<br />
Mine shows the following:<br />
<br />
<code><br />[ 34.385302] cdc_acm 1-6:1.1: ttyACM0: USB ACM device<br />[ 34.390039] cdc_acm 1-6:1.3: ttyACM1: USB ACM device<br />[ 34.401983] cdc_acm 1-6:1.9: ttyACM2: USB ACM device</code><br />
<br />
<span style="font-weight: bold;">Install and Configure wvdial</span><br />
<br />
Next, you need to ensure you can get online using the terminal and wvdial - you will only need to use wvdial to switch the radio on and off - something that can easily be added to Ubuntu's Gnome menu. <br />
<br />
Using apt, install wvdial:<br />
<br />
<code>sudo apt-get install wvdial</code><br />
<br />
I have written a wvdial script which uses /dev/ttyACM0 for reading the signal quality and switching the device on and off. /dev/ttyACM1 is used exclusively for ppp and /dev/ttyACM2 is used exclusively for the GPS. <br />
<br />
<code><br />[Dialer Defaults]<br />New PPPD = yes<br />Stupid Mode = 1<br />Modem Type = USB Modem<br /><br />#[Dialer PIN]<br />#Init1 = AT+CPIN=<br /><br />[Dialer signal]<br />Modem = /dev/ttyACM0<br />Init1 = AT+CSQ<br />Init2 = AT+COPS?<br /><br />[Dialer gps]<br />Modem = /dev/ttyACM2<br />Init1 = AT*E2GPSCTL=1,2,1<br />Init2 = AT*E2GPSNPD<br /><br />[Dialer on]<br />Modem = /dev/ttyACM0<br />Init1 = AT+CFUN=1<br /><br />[Dialer off]<br />Modem = /dev/ttyACM0<br />Init1 = AT+CFUN=4<br /><br />[Dialer connect]<br />Modem = /dev/ttyACM1<br />Init1 = AT <br />Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0<br />Baud = 460800<br />ISDN = 0<br />Phone = *99***1#<br />Password = web<br />Username = web</code><br />
<br />
This script allows the following commands to be run:<br />
<br />
<br /><br /><br /><br /><br /><table><tbody>
<tr><td><code>wvdial on</code></td><td>Switch Radio On</td></tr>
<tr><td><code>wvdial off</code></td><td>Switch Radio Off</td></tr>
<tr><td><code>wvdial signal</code></td><td>Show signal quality, network provider and signal connection (HSPA/3g/GPRS)</td></tr>
<tr><td><code>wvdial connect</code></td><td>Connects to the mobile network</td></tr>
<tr><td><code>wvdial gps</code></td><td>Enables GPS NMEA message output on /dev/ttyACM2 outputting a new message every 2 seconds</td></tr>
</tbody></table>
<br />
<br />
Make sure you can switch your radio on and connect to the internet. If so, you should also be able to switch the GPS on without effecting your network connection. As a final check, run <code>wvdial signal</code> and you should get information about the signal strength - this is crucial that you can get this information whilst the connection is open as it will help later with UMTSMon. <br />
<br />
If you find you cannot connect to the network with <code>wvdial connect</code> without being root or using sudo. Ensure you are in the 'dip' group. You can do this through the "Users and Groups" application in the the Adminstration menu, make sure you unlock to get superuser privileges, highlight your login and press the "Properties" button. In the "User Privileges" tab you can tick the box next to "Use Modems", I also clicked a few more like "Dial out using a modem" which I think adds you to the 'dialout' group which appears to be completely irrelevant to pppd and I presume NetworkManager since it's unchecked by default - WTF?<br />
<br />
You might need to logout and back in again or re-source your shell. Check you can dial out using wvdial. This is important so you don't need to run UMTSMon as sudo. <br />
<br />
<span style="font-weight: bold;">Install UMTSMon</span><br />
<br />
Download a pre-built binary of UMTSMon for Debian from the following page:<br />
<a href="http://people.debian.org/~winnie/umtsmon/">http://people.debian.org/~winnie/umtsmon/</a>. Note I had to use dpkg to install this file, the graphical gdebi failed for some reason. <br />
<br />
<code>sudo dpkg -i umtsmon_0.9-1_i386.deb</code><br />
<br />
Once it is installed it should appear in your "Internet" Gnome application sub-menu. <br />
<br />
Before you run umtsmon, switch your radio on using <code>wvdial on</code>. <br />
<br />
I initially ran umtsmon from the command line so run it using <code>umtsmon</code>. During first run it will setup an rc file in your home directory at ~/.umtsmon/umtsmonrc. You may have to add a profile for your network provider - I use Vodafone and found the information I needed online. Once you have the information you need, add it using the Connection>Manage Profiles... menu item. Add a new profile and fill in the information you need. Additionally you can set usage limits for this profile on this page. <br />
<br />
Hopefully you will see signal strength in the umtsmon window, but don't click connect just yet as you want to ensure wvdial and umtsmon are compatible. This is so you can switch the radio off, use GPS and view signal strength whilst connected. The first time I used UMTSMon, it used the same serial port for everything and I couldn't see signal strength or switch the card off once online. Close UMTSMon and in the command line edit the following file <code>~/.umtsmon/umtsmonrc</code> using your favourite editor! Ensure the device section entries for ATPortName and PPPPortName looks like this:<br />
<br />
<code><br />ATPortName=/dev/ttyACM0<br />PPPPortName=/dev/ttyACM1</code><br />
<br />
This ensures the UMTSMon config is compatible with wvdial. <br />
<br />
Add the following entries to your Gnome menu:<br />
<br />
<code><br />wvdial on<br />wvdial off<br />wvdial gps</code><br />
<br />
All with options to run in the terminal. The last GPS option will hold onto the terminal for the moment, but once you kill it, the GPS will continue to write NMEA statements for read on /dev/ttyACM2. <br />
<br />
<span style="font-weight: bold;">GPS</span><br />
<br />
You will need to install gpsd using apt, then run using <code>gpsd /dev/ttyACM2</code>. <br />
<br />
I used tangoGPS which I installed from their website at <a href="http://www.tangogps.org/">http://www.tangogps.org</a>. Tango can also be configured to use Google Maps data in addition to OpenStreetMap. <br />
<br />
<span style="font-weight: bold;">NetworkManager alternative</span><br />
<br />
To stop the NetworkManager applet nagging you about the new card it can't use, get rid of it and try Wicd - a much cleaner and faster utility for accessing WiFi networks. <br />
<a href="http://wicd.sourceforge.net/">http://wicd.sourceforge.net/</a><br />
<br />
<span style="font-weight: bold;">Credits</span><br />
<br />
<a href="http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=941079">http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=941079</a><br />
<a href="http://ubuntuforums.org/showthread.php?t=979587">http://ubuntuforums.org/showthread.php?t=979587</a><br />
<a href="http://www.nabble.com/X301-Ericsson-Modul-f3507g-AT-Command-reference-td20152955.html">http://www.nabble.com/X301-Ericsson-Modul-f3507g-AT-Command-reference-td20152955.html</a><br />
<a href="http://www.pharscape.org/vodafone-3g-umts-how-to.html#_Toc83808170">http://www.pharscape.org/vodafone-3g-umts-how-to.html#_Toc83808170</a>Barryhttp://www.blogger.com/profile/00882986958587182887noreply@blogger.com29