<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Rupstjarn 55</title>
	
	<link>http://domotica.ronnkvist.nu</link>
	<description>Domotica - Home Automation</description>
	<lastBuildDate>Thu, 05 Nov 2009 09:57:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/rupstjarn55" /><feedburner:info uri="rupstjarn55" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Speak</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/11/05/speak/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/11/05/speak/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 09:57:40 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[Powershell Scripts]]></category>
		<category><![CDATA[Speak]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=185</guid>
		<description><![CDATA[An easy way to get your computer to speak is the object SAPI.SpVoice
A small Powershell-file:

$spv = new-object -com SAPI.SpVoice
$spv.speak($args)
$spv = $null

Then call it like &#8220;.\speak.ps1 Say something&#8221;
]]></description>
			<content:encoded><![CDATA[<p>An easy way to get your computer to speak is the object SAPI.SpVoice</p>
<p>A small Powershell-file:</p>
<pre class="brush: powershell;">
$spv = new-object -com SAPI.SpVoice
$spv.speak($args)
$spv = $null
</pre>
<p>Then call it like &#8220;.\speak.ps1 Say something&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/11/05/speak/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated web-visit</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/19/automated-web-visit-2/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/19/automated-web-visit-2/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 06:46:31 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[VBScripts]]></category>
		<category><![CDATA[Eventghost]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=182</guid>
		<description><![CDATA[I have a webservice that I need to visit to get it to catch new stuff from RSS-feeds. But since it is hosted on a server where I cant run a cron-job I made a small script that i run from Eventghost.

On Error Resume Next

Set oXml = CreateObject(&#34;Microsoft.XMLHTTP&#34;)
oXml.Open &#34;GET&#34;, &#34;http://lifestream.ronnkvist.nu/cron/blaha/blaha&#34;, False
oXml.Send &#34;&#34;

'Remove comment to output [...]]]></description>
			<content:encoded><![CDATA[<p>I have a <a href="http://lifestream.ronnkvist.nu/">webservice</a> that I need to visit to get it to catch new stuff from RSS-feeds. But since it is hosted on a server where I cant run a cron-job I made a small script that i run from Eventghost.</p>
<pre class="brush: vb;">
On Error Resume Next

Set oXml = CreateObject(&quot;Microsoft.XMLHTTP&quot;)
oXml.Open &quot;GET&quot;, &quot;http://lifestream.ronnkvist.nu/cron/blaha/blaha&quot;, False
oXml.Send &quot;&quot;

'Remove comment to output the response
'wscript.echo oXml.ResponseText
</pre>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/19/automated-web-visit-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send text to Squeezecenter</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/18/send-text-to-squeezecenter/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/18/send-text-to-squeezecenter/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 10:46:35 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[VBScripts]]></category>
		<category><![CDATA[CallerID]]></category>
		<category><![CDATA[Squeezecenter]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=180</guid>
		<description><![CDATA[This VBScript will send a text to your squeezecenter and the text will be displayed on your Squeezebox.
I use it to show who is calling.
It uses w3Sockets from http://www.dimac.com/default3.asp?M=FreeDownloads/Menu.asp&#038;P=FreeDownloads/FreeDownloadsstart.asp, so download and register it before trying this out.

Option Explicit
Dim i, oTelnet, outString, slimHost, slimPort, txtDuration, sendStop, headString, maxLengthHead, headPaddingChar, headPadding

slimHost = &#34;192.168.100.50&#34;	' IP-address to Squeezecenter
slimPort [...]]]></description>
			<content:encoded><![CDATA[<p>This VBScript will send a text to your squeezecenter and the text will be displayed on your Squeezebox.</p>
<p>I use it to show who is calling.</p>
<p>It uses w3Sockets from <a href="http://www.dimac.com/default3.asp?M=FreeDownloads/Menu.asp&#038;P=FreeDownloads/FreeDownloadsstart.asp">http://www.dimac.com/default3.asp?M=FreeDownloads/Menu.asp&#038;P=FreeDownloads/FreeDownloadsstart.asp</a>, so download and register it before trying this out.</p>
<pre class="brush: vb;">
Option Explicit
Dim i, oTelnet, outString, slimHost, slimPort, txtDuration, sendStop, headString, maxLengthHead, headPaddingChar, headPadding

slimHost = &quot;192.168.100.50&quot;	' IP-address to Squeezecenter
slimPort = &quot;9090&quot; ' Portnumber on the Squeezecenter (Standard is 9090)
txtDuration = &quot;120&quot; ' Seconds to show the text
sendStop = False ' Stop music?

headString = &quot;Incoming call&quot; ' Text to show on top row
maxLengthHead = 44 ' Max-length on top row
headPaddingChar = &quot;*&quot; ' On the sides of the text

Dim playerMac(1) ' Se example below
playerMac(0) = &quot;00:04:20:00:aa:bb&quot;	' Kitchen
playerMac(1) = &quot;4d:22:6a:00:aa:bb&quot;	' Soft squeeze
' ------------------------------------------------------------------------------------------------
' Example for 1 player
' Dim playerMac(0)
' playerMac(0) = &quot;11:22:33:44:55:66&quot;
'
' Example for 3 players
' Dim playerMac(2)
' playerMac(0) = &quot;11:22:33:44:55:66&quot;
' playerMac(1) = &quot;aa:bb:cc:dd:ee:ff&quot;
' playerMac(2) = &quot;77:88:99:00:aa:bb&quot;
' ------------------------------------------------------------------------------------------------

' Create top row
headString = &quot; &quot; &amp; headString &amp; &quot; &quot;
headPadding = &quot;&quot;
For i = 0 to (Round((maxLengthHead-Len(headString)) / 2))
	headPadding = headPadding &amp; headPaddingChar
Next
outString = Replace(headPadding &amp; headString &amp; headPadding, &quot; &quot;, &quot;%20&quot;) &amp; &quot; &quot;

' Create row to show
if wScript.Arguments.Count &lt;&gt; 0 then
	For i = 0 to (wScript.Arguments.Count-1)
		outString = outString &amp; wScript.Arguments(i) &amp; &quot;%20&quot;
	Next
Else
	outString = outString &amp; &quot;Saknar%20parametrar%20till%20scriptet&quot;
End if

set oTelnet = CreateObject(&quot;Socket.TCP&quot;)
With oTelnet
	.DoTelnetEmulation = True
	.TelnetEmulation = &quot;TTY&quot;
	.Host = slimHost &amp; &quot;:&quot; &amp; slimPort
	.Open

	' Loop thru all players
	For i = 0 to uBound(playerMac)
		' Skickar stop-kommandot
		if sendStop then
			' Stop the music
			.SendLine playerMac(i) &amp; &quot; button stop&quot;
		end if

		' Send display-command
		.SendLine playerMac(i) &amp; &quot; display &quot; &amp; outString &amp; &quot; &quot; &amp; txtDuration

	Next

	.SendLine &quot;exit&quot;
	.Close
End With
Set oTelnet = Nothing
</pre>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/18/send-text-to-squeezecenter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic thermometer-image</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/18/dynamic-thermometer-image/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/18/dynamic-thermometer-image/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 07:42:17 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[PHP Scripts]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Thermometer]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=172</guid>
		<description><![CDATA[If you want to create a dynamic thermometer for your webpage PHP has some capability to create and modify images.
The script below can be called with http://domotica.ronnkvist.nu/temperature-scripts/termometer.php?temp=22 to create an image like this:


&#60;?php
	// Should be in even 5's (20, 25, 30 and so on)
	$maxTemp = 30;
	$minTemp = -30;

	// Where should the bar be placed?
	$barStart = [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create a dynamic thermometer for your webpage PHP has some capability to create and modify images.</p>
<p>The script below can be called with http://domotica.ronnkvist.nu/temperature-scripts/termometer.php?temp=22 to create an image like this:<br />
<img src="http://domotica.ronnkvist.nu/temperature-scripts/termometer.php?temp=22" alt="22" /></p>
<pre class="brush: php;">
&lt;?php
	// Should be in even 5's (20, 25, 30 and so on)
	$maxTemp = 30;
	$minTemp = -30;

	// Where should the bar be placed?
	$barStart = 8;
	$maxHeight = 172;
	$totalBarHeight = 164;

	// Colors and what background to use
    $tmpImg = @imagecreatefrompng(&quot;termometer.png&quot;);
	$colBar = imagecolorallocate($tmpImg, 208, 33, 33);
	$colBlack = imagecolorallocate($tmpImg, 0, 0, 0);

	// Temperature-lines
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 0), 22, $barStart+(($totalBarHeight/6) * 0), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 1), 22, $barStart+(($totalBarHeight/6) * 1), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 2), 22, $barStart+(($totalBarHeight/6) * 2), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 3), 22, $barStart+(($totalBarHeight/6) * 3), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 4), 22, $barStart+(($totalBarHeight/6) * 4), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 5), 22, $barStart+(($totalBarHeight/6) * 5), $colBlack);
	imageline($tmpImg, 1, $barStart+(($totalBarHeight/6) * 6), 22, $barStart+(($totalBarHeight/6) * 6), $colBlack);

	// Text-strings by the lines
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 0)-4, &quot; 30&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 1)-4, &quot; 20&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 2)-4, &quot; 10&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 3)-4, &quot;  0&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 4)-4, &quot;-10&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 5)-4, &quot;-20&quot;, $colBlack);
	imagestring($tmpImg, 1, 25, $barStart+(($totalBarHeight/6) * 6)-4, &quot;-30&quot;, $colBlack);

	$temperature = trim($_GET['temp']);
	if ($temperature == &quot;&quot;) {
		$temperature = 0;
	}

	// Calculate the bar-height
	$tempSpan = (0 - $minTemp) + $maxTemp;
	if ($temperature == 0) {
		$barHeight = ($totalBarHeight / 2);
	} elseif ($temperature &gt; 0) {
		if ($temperature &gt;= $maxTemp) {
			$barHeight = $totalBarHeight;
		} else {
			$barHeight = ($totalBarHeight / 2) + (($temperature / $maxTemp) * ($totalBarHeight / 2));
		}
	} else {
		if ($temperature &lt;= $minTemp) {
			$barHeight = 0;
		} else {
			$barHeight = ($totalBarHeight / 2) - (($totalBarHeight / 2) * ((0-$temperature) / (0-$minTemp)));
		}
	}

	// Temperature-bar
	imagefilledrectangle($tmpImg, 7, $barStart+($totalBarHeight-$barHeight), 13, 172, $colBar);

	// Create the image
	header( &quot;Content-type: image/png&quot; );
	imagepng($tmpImg );
?&gt;
</pre>
<p>The background image is found at <a href="http://domotica.ronnkvist.nu/temperature-scripts/termometer.png">http://domotica.ronnkvist.nu/temperature-scripts/termometer.png</a></p>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/18/dynamic-thermometer-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Log diskspace</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/18/log-diskspace/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/18/log-diskspace/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 06:08:19 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[VBScripts]]></category>
		<category><![CDATA[Diskspace]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=161</guid>
		<description><![CDATA[If you want to log the usage of diskspace on a computer it&#8217;s not that hard.. you just need some place to store the data and a script that runs at given intervals.
I have a table in my SQL Server.

CREATE TABLE Diskspace(
	index bigint IDENTITY(1,1) NOT NULL,
	TimeStamp datetime NOT NULL,
	FreePercent decimal(18, 3) NOT NULL,
	DriveLetter char(1) NOT [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to log the usage of diskspace on a computer it&#8217;s not that hard.. you just need some place to store the data and a script that runs at given intervals.</p>
<p>I have a table in my SQL Server.</p>
<pre class="brush: sql;">
CREATE TABLE Diskspace(
	index bigint IDENTITY(1,1) NOT NULL,
	TimeStamp datetime NOT NULL,
	FreePercent decimal(18, 3) NOT NULL,
	DriveLetter char(1) NOT NULL,
 CONSTRAINT PK__Diskspace__49C3F6B7 PRIMARY KEY CLUSTERED
(
	index ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON PRIMARY
) ON PRIMARY
</pre>
<p>Then I have a VBScript that runs every five minutes (via Eventghost). You need to change databasename, user and password.</p>
<pre class="brush: vb;">
Set oDb = createobject(&quot;ADODB.Connection&quot;)
oDb.ConnectionString = &quot;DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=TheDatabaseName;UID=MyUserName;PWD=SomePassword; OPTION=3&quot;
oDb.Open

Set oWmiService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2&quot;)
Set oDisks = oWmiService.ExecQuery(&quot;Select * from Win32_LogicalDisk Where DriveType = 3&quot;)

For Each oDisk In oDisks
    sPercent = Replace(Round((oDisk.FreeSpace / oDisk.Size)*100, 1), &quot;,&quot;, &quot;.&quot;)
    sDisk = uCase(Replace(oDisk.DeviceID, &quot;:&quot;, &quot;&quot;))

	sSql = &quot;INSERT INTO diskspace (TimeStamp, FreePercent, DriveLetter) VALUES (GETDATE(), '&quot; &amp; sPercent &amp; &quot;', '&quot; &amp; sDisk &amp; &quot;')&quot;
	WScript.Echo sSql
	oDb.Execute(sSql)
Next

oDb.Close
</pre>
<p>As easy as that&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/18/log-diskspace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create event in EventGhost</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/13/create-event-in-eventghost/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/13/create-event-in-eventghost/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 06:27:40 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[CMD Scripts]]></category>
		<category><![CDATA[VBScripts]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Eventghost]]></category>
		<category><![CDATA[Trigger]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=158</guid>
		<description><![CDATA[There are two easy ways of creating events in EventGhost.
First by commandline:

C:\Program Files\EventGhost\EventGhost.exe -E MyTestEventFromCmd
C:\Program Files\EventGhost\EventGhost.exe -E MyTestEventFromCmd WithPayload

And then via VBScript

Dim oEventGhost
Set oEventGhost = CreateObject(&#34;EventGhost&#34;)
oEventGhost.TriggerEvent &#34;MyTestEvent&#34;
oEventGhost.TriggerEvent &#34;AndSomeOtherEvent&#34;, &#34;WithPayload&#34;
Set oEventGhost = Nothing

With that you can get EventGhost to react on loads of stuff&#8230; why not react on incoming phonecalls?

]]></description>
			<content:encoded><![CDATA[<p>There are two easy ways of creating events in EventGhost.</p>
<p>First by commandline:</p>
<pre class="brush: plain;">
C:\Program Files\EventGhost\EventGhost.exe -E MyTestEventFromCmd
C:\Program Files\EventGhost\EventGhost.exe -E MyTestEventFromCmd WithPayload
</pre>
<p>And then via VBScript</p>
<pre class="brush: vb;">
Dim oEventGhost
Set oEventGhost = CreateObject(&quot;EventGhost&quot;)
oEventGhost.TriggerEvent &quot;MyTestEvent&quot;
oEventGhost.TriggerEvent &quot;AndSomeOtherEvent&quot;, &quot;WithPayload&quot;
Set oEventGhost = Nothing
</pre>
<p>With that you can get EventGhost to react on loads of stuff&#8230; why not react on incoming phonecalls?<br />
<img src="http://domotica.ronnkvist.nu/wp/wp-content/uploads/eventghostevents.png" alt="eventghostevents" title="eventghostevents" class="alignnone size-full wp-image-159" /></p>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/13/create-event-in-eventghost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last temperature reading</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/13/last-temperature-reading/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/13/last-temperature-reading/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 05:49:18 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[MSure]]></category>
		<category><![CDATA[Temperature]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=154</guid>
		<description><![CDATA[If you want to create a webpage or something similar you might want to show off the latest temperature reading.
This script will give you last reading in every table, if you want to exclude / include specific tables look at the &#8220;AND Name NOT LIKE&#8221; lines.

IF EXISTS(SELECT TABLE_NAME FROM TEMPDB.INFORMATION_SCHEMA.TABLES
      [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create a webpage or something similar you might want to show off the latest temperature reading.</p>
<p>This script will give you last reading in every table, if you want to exclude / include specific tables look at the &#8220;AND Name NOT LIKE&#8221; lines.</p>
<pre class="brush: sql;">
IF EXISTS(SELECT TABLE_NAME FROM TEMPDB.INFORMATION_SCHEMA.TABLES
      WHERE TABLE_NAME LIKE '#TemperatureLast%')
   DROP TABLE #TemperatureLast
GO

CREATE TABLE #TemperatureLast (
   MSureName SYSNAME NOT NULL,
   TimeStamp DATETIME NOT NULL,
   Temperature DECIMAL(18, 3) NOT NULL,
)

DECLARE
   @query VARCHAR(2000),
   @currTable SYSNAME

DECLARE tablesCurr CURSOR
	FOR
	SELECT Name as TableName
		FROM  sysobjects
		WHERE xtype = 'U'
			AND Name NOT LIKE '%space%'
			-- AND Name NOT LIKE '%something%'
			-- AND Name LIKE 'Temperature%'
		ORDER BY TableName
	FOR READ ONLY

OPEN tablesCurr
   FETCH NEXT FROM tablesCurr INTO @currTable
   WHILE (@@FETCH_STATUS &lt;&gt; -1) BEGIN

		SET @Query = 'SELECT TOP 1 ''' + @currTable + ''', TimeStamp, Temperature FROM ' + @currTable + ' ORDER BY TimeStamp DESC'
		INSERT #TemperatureLast EXEC (@query)

      FETCH NEXT FROM tablesCurr INTO @currTable
   END
CLOSE tablesCurr
DEALLOCATE tablesCurr

SELECT * FROM #TemperatureLast
DROP TABLE #TemperatureLast
</pre>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/13/last-temperature-reading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring and autumn</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/13/spring-and-autumn/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/13/spring-and-autumn/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 05:44:26 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[Autumn]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=151</guid>
		<description><![CDATA[According to SMHI autumn is when the average temperature of the day is falling and is between 0 and 10 degrees. And spring is when it&#8217;s rising and between 0 and 10 degrees.
Reference: http://www.smhi.se/cmp/jsp/polopoly.jsp?d=5938&#038;l=sv
This &#8220;little&#8221; script will give you a resulting table with average temperature on UtomhusNorr calculated with the last five days.

IF EXISTS(SELECT TABLE_NAME [...]]]></description>
			<content:encoded><![CDATA[<p>According to SMHI autumn is when the average temperature of the day is falling and is between 0 and 10 degrees. And spring is when it&#8217;s rising and between 0 and 10 degrees.</p>
<p>Reference: <a href="http://www.smhi.se/cmp/jsp/polopoly.jsp?d=5938&#038;l=sv">http://www.smhi.se/cmp/jsp/polopoly.jsp?d=5938&#038;l=sv</a></p>
<p>This &#8220;little&#8221; script will give you a resulting table with average temperature on UtomhusNorr calculated with the last five days.</p>
<pre class="brush: sql;">
IF EXISTS(SELECT TABLE_NAME FROM TEMPDB.INFORMATION_SCHEMA.TABLES
      WHERE TABLE_NAME LIKE '#TemperatureAvg%')
   DROP TABLE #TemperatureAvg
GO

CREATE TABLE #TemperatureAvg (
   TimeStamp DATETIME NOT NULL,
   Temperature DECIMAL(18, 3) NOT NULL,
)

DECLARE
   @query VARCHAR(2000),
   @currDate DATETIME

DECLARE dateCurr CURSOR
   FOR
   SELECT DISTINCT CAST(CONVERT(CHAR(10),TimeStamp,20) AS DATETIME) as TempDates
   FROM UtomhusNorr
   WHERE TimeStamp &amp;gt; DATEADD(month, -1, GETDATE())
   ORDER BY TempDates DESC
   FOR READ ONLY

OPEN dateCurr
   FETCH NEXT FROM dateCurr INTO @currDate
   WHILE (@@FETCH_STATUS &amp;lt;&amp;gt; -1) BEGIN
      SET @Query = 'SELECT MAX(TimeStamp) AS TimeStamp, AVG(Temperature) as Temperature FROM UtomhusNorr WHERE TimeStamp &amp;gt; DATEADD(day, -5, ''' + CONVERT(NVARCHAR(32), @currDate) + ''') AND TimeStamp &amp;lt; ''' + CONVERT(NVARCHAR(32), @currDate) + ''''
      INSERT #TemperatureAvg EXEC (@query)

      FETCH NEXT FROM dateCurr INTO @currDate
   END
CLOSE dateCurr
DEALLOCATE dateCurr

SELECT TimeStamp, Temperature AS AvgTemp5daysBack FROM #TemperatureAvg
DROP TABLE #TemperatureAvg
</pre>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/13/spring-and-autumn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrate data from MySQL to SQL Server</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/13/migrate-data-from-mysql-to-sql-server/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/13/migrate-data-from-mysql-to-sql-server/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 05:37:19 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[SQL Scripts]]></category>
		<category><![CDATA[VBScripts]]></category>
		<category><![CDATA[Migrate]]></category>
		<category><![CDATA[MSure]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=149</guid>
		<description><![CDATA[Since I work with MS SQL Server (and have done for the last 10 years) I converted the MySQL-databases in MSure to MS SQL.
This script will copy 4 tables, easy to add more.
Remember to change the ConnectionString&#8217;s to your settings. (server, database, user and password)

Set oMySQL = createobject(&#34;ADODB.Connection&#34;)
oMySQL.ConnectionString = &#34;DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=msure;UID=msure;PWD=abc123; OPTION=3&#34;
oMySQL.Open

Set oSql [...]]]></description>
			<content:encoded><![CDATA[<p>Since I work with MS SQL Server (and have done for the last 10 years) I converted the MySQL-databases in MSure to MS SQL.<br />
This script will copy 4 tables, easy to add more.<br />
Remember to change the ConnectionString&#8217;s to your settings. (server, database, user and password)</p>
<pre class="brush: vb;">
Set oMySQL = createobject(&quot;ADODB.Connection&quot;)
oMySQL.ConnectionString = &quot;DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=msure;UID=msure;PWD=abc123; OPTION=3&quot;
oMySQL.Open

Set oSql = createobject(&quot;ADODB.Connection&quot;)
oSql.ConnectionString = &quot;DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=msure;UID=MSure;PWD=abc123; OPTION=3&quot;
oSql.Open

CopyTable &quot;UtomhusNorr&quot;
CopyTable &quot;UtomhusOster&quot;
CopyTable &quot;UtomhusSoder&quot;
CopyTable &quot;UtomhusVaster&quot;

sub CopyTable(sTable)
  set oSource = oMySQL.Execute(&quot;SELECT * FROM &quot; &amp; sTable)
  do while not oSource.Eof

    sSql = &quot;INSERT INTO &quot; &amp; sTable &amp; &quot; (TimeStamp, Temperature) VALUES ('&quot; &amp; oSource(&quot;TimeStamp&quot;) &amp; &quot;', '&quot; &amp; Replace(oSource(&quot;Temperature&quot;),&quot;,&quot;, &quot;.&quot;) &amp; &quot;')&quot;

    wscript.echo sSql
    oSql.Execute sSql

    oSource.MoveNext
  Loop
End Sub

oMySQL.Close
oSql.Close
</pre>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/13/migrate-data-from-mysql-to-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated web-visit</title>
		<link>http://domotica.ronnkvist.nu/blog/2009/09/13/automated-web-visit/</link>
		<comments>http://domotica.ronnkvist.nu/blog/2009/09/13/automated-web-visit/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 05:04:59 +0000</pubDate>
		<dc:creator>riro</dc:creator>
				<category><![CDATA[VBScripts]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://domotica.ronnkvist.nu/?p=147</guid>
		<description><![CDATA[If you have a webpage that you need to visit every xx minutes/hours to get some scripts to work, you can visit it via a VBScript&#8230;

On Error Resume Next
Dim oXml
Const cURL = &#34;http://www.something.com/path/automate.php&#34;

Set oXml = CreateObject(&#34;Microsoft.XMLHTTP&#34;)
oXml.Open &#34;GET&#34;, cURL, False
oXml.Send &#34;&#34;

]]></description>
			<content:encoded><![CDATA[<p>If you have a webpage that you need to visit every xx minutes/hours to get some scripts to work, you can visit it via a VBScript&#8230;</p>
<pre class="brush: vb;">
On Error Resume Next
Dim oXml
Const cURL = &quot;http://www.something.com/path/automate.php&quot;

Set oXml = CreateObject(&quot;Microsoft.XMLHTTP&quot;)
oXml.Open &quot;GET&quot;, cURL, False
oXml.Send &quot;&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://domotica.ronnkvist.nu/blog/2009/09/13/automated-web-visit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
