Posts Tagged ‘.net’

So after weeks of playing,printing, and busting buttons  I think what I ended up is with some acceptable buttons, here are the layout of my first KeyPad Linc

These were done using a InkJet, I still need to try using a Color Laser to see.  Since I got this one off of ebay it was only the 6 key’s which I got the conversion kit off of SmartHome for $5 to 8 bottons.

The Etched buttons do look better but a bit costly.  Here is the breakdown

8 Button Keypadlinc

Color Kit, which changes the color of the LED behind the button

6 to 8 Button Conversion kit or new buttons if you break one. 🙂

Here is the low down,

1st  – Controls the load on the switch which is in my hallway

2nd – The Kitchen Main light

3rd – The Lights inside the Garage

4th – A group which controls all outside lights, (Garage, flood lights, back lights, entrance etc.)

5th- Not linked to any device but when pressed the PC will turn off all the lights in 2 min’s and set the house state to off, which includes bumping up the thermostat to 80 Degrees.

6th- Linked to my I/O Link to open/monitor the garage.

7th -My Children s room both have a main light and a night light switch, this button is linked to both of them, only thing is the Main Switch has a on – level of  0 which causes only the night light to turn on. The best way for this is to link them manually then go back the the program for Smarthomenet’s and change the turn on code to 0.

8th -Linked to my T1700 Thermostat.  Its linked by setting your thermostat to the desiered state then link like any other switch.  Very simple and clean.  I also link this button back to my PLC so I know its been pressed.

As promised here are some new screen shots of the Client.  Its totally revamped and I think in a cleaner format.  Its a combination of VB2008 / Flash Action Script 2.0

Sample Screens – Jan 2009

Comments and feedback is appreciated!

One of the questions ive been asked is how to I put my flash script to grab data from the SQL database and provide updates if the device is on or off etc.

Well the awnser is, I dont. Like mentioned before to have your flash talk directly to a sql database you will need additional components which I dont want to install $$$, such as cold fusion or some advanced Flash stuff.  Again I want speed and functionality, especially if its only for a few users.

So what I did was use a internal web server which is installed with VB 2008, to do all the talking for me, more like a middle man.  for example my flash program talks to this web page using the ‘load’ function which sends data using the POST commands (example http://192.168.0.101/finddata.aspx&IN=14) and the code runs and returns the values needed in a specific variable in this case ‘VALUE’. you can also use the LoadVariables command which explain that in this article.

Flash:Loading Variables from files into Flash

So here is a high level of what is being done in the background.

All all times the Insteon Server is updating the SQL Server with the status of the devices as they are turned on or off, so we dont need to connect there. Also note that the Local .net, SQL database and insteon server are all on the same box!

For example lets say I want to pull the status of device #14. (Fan in master bedroom)  This is what I would do from the Flash Program

Example in FLASH CLIENT;

Prepare: In Flash you will need to create a empty movie clip called ‘fan_master’.  Also have images already in your webpage in the location mentioned below. I call it right of the same page you can use your local library if you like.

Here are my images I use in my Flash program,  you may use them if you like (Just right click on them and use SAVE AS)

Light_bulb_off.png

Light_bulb_on.png

Off Button (small_button_on.png)

On Button (small_button_off.png)

In my actionScript, I would put on one of the frames;

//--------------------- SETUP A NEW VARIABLE TO GRAB MY DATA THIS FUNCTION WILL RUN WHEN THE BELOW SITE IS OPENED
var mfan:LoadVars = new LoadVars();
    mfan.onLoad = function() {

//------ Here I check the return value that is returned back as 'value' if its is ON then replace the fan_master 'movie' to the bulb on image
          if (mfan.value=="ON"){
            loadMovie("http://192.168.0.101/images/small_button_on.png", fan_master);
        } else {
            loadMovie("http://192.168.0.101/images/small_button_off.png", fan_master);
        }
    };
//---------------- do the actual opening of the webpage and pass the variable IN and the device im asking for
mfan.load("http://192.168.0.101/finddata.aspx?in=14");
stop();

BLUE BOX (SERVER .NET SIDE)

A description of my Devices Database is found here

‘————————— VB 2008 / WEBPAGE filename finddata.aspx

On my Server side I would grab the value on “IN” using the

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      '------- Device will hold the value of in 'IN' which is #14
      device = Context.Request.Params("IN")
      value = Lg_Get_Device_Status(device)
      Response.Write("value=" + value)
 End Sub

This will return to my program the following text
“value=ON” or “value=OFF”

‘——– Function to grab the device data by the device #

    Public Function Lg_Get_Device_Status(ByVal Marker As String) As String

        Dim sqlConnection10 As New System.Data.SqlClient.SqlConnection(ConnectionSTring) ' Set your connectionstring accordingly.
        Dim Cmd10 As New System.Data.SqlClient.SqlCommand

        '-------- We'll use the SqlDataReader to get the values of the table 
        Dim Reader As SqlClient.SqlDataReader

        Cmd10.CommandText = "SELECT * FROM Devices where Marker= '" + Marker + "'"
        Cmd10.Connection = sqlConnection10
        sqlConnection10.Open()
        Reader = Cmd10.ExecuteReader()

        ' check for data, if not return 'FALSE'
        If Reader.HasRows = False Then
            Lg_Get_Device_Status = False
            Exit Function
        End If
        Reader.Read()
        '-------- RETURN THE VALUE FROM THE DATABASE SUCH AS ON OR OFF OF %
        Lg_Get_Device_Status = Reader.Item("status")
        sqlConnection10.Close()

    End Function

And there you have it, I do use the same file (finddata.aspx) for other stuff and you can easily query what is being passed and eventually act on it like this,

For example if I pass(showall=1) it would run another function, but that is another article.

        '------------------- SHOW ALL DEVICES
        If Context.Request.Params("showall") <> "" Then Show_insteon_devices() : Exit Sub

        '------------------- SHOW ALL DEVICES by MAC address
        If Context.Request.Params("showmacs") <> "" Then Show_insteon_devices_mac() : Exit Sub

        '------------------- SHOW ALL CONFIGS
        If Context.Request.Params("show_all_configs") <> "" Then Show_all_configs() : Exit Sub

The following is a example of how I setup to control my garage door using simple X10 devices.  When budget permits I’ll bump up to the Insteon (sniff, sniff)), For this device to work I was lucky the circuit the garage door opener is on is close to my insteon/x10 PLC so I get a good 95% hit rate (Which is OK for me..)

For this to work, basically what I am doing is closing two of the three connectors of my garage door opener, this is the same thing the button on the wall button does. Red is the power going out, the white is the common ground and the grey or black is the motion sensor which will stop the door if the infrared device is passed.  I used some simple cat 5 wiring.

To do this I used a X10, Universal Module which is very cheap (Some under $15 off ebay). Picture below,

To simulate the button, this device will close a circuit momentary (2 seconds actually), you can even set it to sound when activated.
Basically sending a X10 “ON” code it will close the circuit and open or close the garage.  I’ll post another entry on how to check if the garage door is open or closed but we will be using another device.

Setup

So I set the Unit code to something not accessible thru the outside, same as the House code, the the first switch to Momentary, and Relay only. Here is how it looks

So thry my code using the SDM module , VB code I send the Open command (Lets say G16),  The system wont give you a status if it opened it or not, also only “ON” command will work.

Sm.SendX10("G16,GON")

To setup the SDM in the VB 2005 environment you need to check out my previous article. Basically here im just using the SDM COM object to send a X10 command.

That article can be found here
Software:Get X10 data to your PC using a Insteon PLC

Pros: Simple cheap

Cons: No way to know if the garage is open or not, this just simulated pressing the button

Here is everything hooked up,

Here is another picture, of my attempt to make it look better.