My 'Wall-E' system - Temperature Capture

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • jaffab
    Automated Home Sr Member
    • Dec 2008
    • 94

    My 'Wall-E' system - Temperature Capture

    As part of my home automation system, I wanted the ability to monitor temperatures around my house. I wanted this partially so I could know how hot/cold it was outside before I left the house, partially so that I could automate things like A/C and central heating based on temperatures (either via programs or via the net) but mostly because I am an information freak.

    After a lot of research, I found there are lots of temperature monitors available, but most of them are major money. I wanted something which was as cheap as chips, and easy to use.

    I opted for a pre-built DS18S20 Computer Serial Temperature Data Logger from Quaser Electronics (they supplied a kit PCB for those happy with a soldering iron) - http://www.quasarelectronics.com/314...ata-logger.htm.



    The PCB plugs into my computer via a USB cable, and can run upto 4 temperate sensors – I am running three – 2 through this device and then I get a reading from my current cost device. The PCB, drivers and 3 temperature sensors cost me about £38. I now receive temperature data from three locations in my house; Outside (A small hold drilled through the wall and a temperature sensor outside, away from direct sunlight), my lounge and my office. In time, I will add a final one to my bedroom.

    Now, the temperature sensor works as a com port device (via USB), and sends every second, the temperature data as a string such as…

    1 0021.18 <crl/lf> 2 0022.17 <cr/lf>

    the number (1 or 2) for each line is the sensor number, and the value that follows (21.18 or 22.17) is the temperature for the sensor. I log the data into a main home server running SQL Server, in a temperature table as follows:

    CREATE TABLE [dbo].[Temperature](
    [SampleDate] [datetime] NOT NULL,
    [location] [varchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [temp] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [done] [varchar](1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
    ) ON [PRIMARY]


    Now because it sends the data every second, and that’s far, far too much data my home app, I wrote a small VB program (VB6 or Visual Studio) which opens the Com port for the device, and takes a reading every 10 seconds, and writes them away to the temperature file. My code is as follows:


    Sub Form_Load()

    TempComPort.PortOpen = True ' Open the port
    LastTempDate = Now()

    End Sub


    Private Sub Timer1_Timer()
    '
    ' +-------------------------------------------------------------------------+
    ' | |
    ' | The Main PRocessing Subroutine - this is the timer event that proceses |
    ' | all the inputs, and calls all the data capture routines. |
    ' | |
    ' +-------------------------------------------------------------------------+
    '
    '
    If incycle = "Y" Then Exit Sub
    '
    ' Read in the Temperature Readings
    '
    Dim loc(3, 2)
    loc(1, 1) = "L"
    loc(2, 1) = "W"
    thistext = TempComPort.Input
    If thistext <> "" Then
    If DateDiff("s", LastTempDate, Now()) > 10 Then
    If thistext <> "" Then
    Dim f2, fs2
    Set fs2 = CreateObject("Scripting.FileSystemObject")
    Set f2 = fs2.OpenTextFile("c:\Nyumbani\" & Format(DateTime.Now, "ddMMyy") & "-TEMP.log", 8, -2)
    f2.Write ("<%" & CStr(DateTime.Now) & "%>" & thistext)
    f2.Close
    End If
    LastTempDate = Now()
    Dim conn2 As New ADODB.Connection
    conn2.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=electric;Initial Catalog=Nyumbani;Data Source=" & server_name
    conn2.CursorLocation = adUseClient
    conn2.Open
    Dim Temprs2 As New ADODB.Recordset

    Temprs2.Open "Temperature", conn2, adOpenKeyset, adLockOptimistic
    '
    ' Loop for each line
    '
    thistext = thistext & Chr(13)
    thisline = ""
    For x = 1 To Len(thistext)
    thischar = Mid$(thistext, x, 1)
    If thischar = Chr(10) Then
    Else
    If thischar = Chr(13) Then
    portno = 0
    If Left$(thisline, 2) = "1 " Then portno = 1
    If Left$(thisline, 2) = "2 " Then portno = 2
    If Left$(thisline, 2) = "3 " Then portno = 3
    If loc(portno, 2) < 1 And portno > 0 Then
    If (Val(Mid$(thisline, 3, 99)) + 0) > 0 Then
    loc(portno, 2) = (Val(Mid$(thisline, 3, 99)) + 0)
    End If
    End If

    thisline = ""
    Else
    thisline = thisline & thischar
    End If
    End If
    Next x


    '
    ' Check everything is ok
    '
    If lastloungetemp <> "" Then
    If loc(1, 2) > lastloungetemp Then
    If (loc(1, 2) - Val(lastloungetemp)) > 3 Then
    GoTo baddata
    End If

    Else
    If (Val(lastloungetemp) - loc(1, 2)) > 3 Then
    GoTo baddata
    End If
    End If
    lastloungetemp = loc(1, 2)
    End If


    For x = 1 To 3
    If loc(x, 2) <> "" Then
    Temprs2.AddNew
    Temprs2![SampleDate] = Format(Now(), "dd mmm yy hh:mm:ss")
    Temprs2![Location] = loc(x, 1) ' for the office
    Temprs2![temp] = Trim(loc(x, 2))
    Temprs2.Update
    End If
    Next x
    Temprs2.Close
    conn2.Close


    End If


    End If

    '
    ' And Exit routine
    '
    incycle = "N"
    Exit Sub
    baddata:
    x10Timer.Enabled = False
    Timer1.Enabled = False
    Call SendMail("X10 problem getting temp", "The x10 com receiver has seen a temp change of over 3 degrees in one cycle, and the program has therefore been restarted")
    If Timer1.Enabled = True Then
    CurrentCostComPort.PortOpen = False ' Open the port
    TempComPort.PortOpen = False ' Open the port
    End If
    t% = Shell("F:\Program Files\Touchstone Systems Ltd\My Product Name\NyumbaniService.exe", vbNormalFocus)
    End
    End Sub


    The result is the data is logged, and part of my home application (which I will cover later on and provide the database/source code/installation – if anybody wants a copy) can display this information from a web page, or on my wall mounted PC.

    __________________________________________________ _______________________
    My life is Home Automation, and my PS3 clan friends at http://www.ps3crowd.com
  • Yanson
    Automated Home Lurker
    • Jun 2009
    • 1

    #2
    I got one of these, it's pretty cool.

    I cloned the HDD temperature template in cacti to graph it, but there are a few issues such as not going negative.

    Anyone got a cacti template for this? One that overlays all the temps on the same graph would be cool.

    Comment

    Working...
    X