Announcement

Collapse
No announcement yet.

How to modify a script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to modify a script

    I would like to modify the following script so that it will display the Linksys "on" icon when it sends the wanip.htm to the staus column.


    '*********************************************************** *************************
    ' PostWanIP.txt
    '
    ' Purpose: Retrieves WAN IP from a LinkSys router. Once the IP is retrieved,
    ' script will set the virtual device specified in strIpDevice to this
    ' address. A web page will then be created and FTP'd to the location
    ' specified by strFtpHost.
    '
    ' Author: Brian Raynor (hraynor@sc.rr.com)
    '
    ' Version: 1 for HomeSeer 1.5
    '
    ' Usage: Create a recurring event (say, every 5 minutes) to execute an event
    ' that runs this macro. It will ensure that your IP is updated to both
    ' HomeSeer (in the virtual device) and an external web page.
    '
    ' Note: Please modify the string constants below to your needs
    '
    '*********************************************************** *************************

    const strIpDevice = "r38" ' X10 virtual device for IP address

    ' LinkSys router settings - must be modified to suite your router
    ' Please note that in general, the LinkSys does not have a username to log in with, only a password

    const strRouterPage ="xxx.xxx.xxx.xxx/Status.htm" ' Page to retrieve info from. This is the factory default
    const strRouterPassword = "xxxxxxxx" ' Password to login to switch

    ' Settings for FTPing a web page with desired information.

    const strFtpHost = "web url.com" ' FTP site to place web page on
    const strFtpUser = "xxxxxx" ' FTP user name
    const strFtpPassword = "xxxxxxx" ' FTP password
    const strFtpLocalFile = "C:\program files\homeseer\html\WanIP.htm" ' Local file to create for web page
    const strFtpRemoteFile = "ip.htm" ' Destination file on web server

    ' Set the HomeSeer port below for the web page

    const strHomeSeerWebPort = "##" ' Change this to your port, default is 80

    const cStatusAllOff = 0
    const cStatusOn = 2
    const cStatusOff = 3
    const cStatusDim = 4

    Dim strBuffer
    Dim strFullRouterUrl
    Dim strWanIp

    Sub Main()
    strFullRouterUrl = "http://"""":" + strRouterPassword + "@" & strRouterPage

    strBuffer = ""

    strBuffer = hs.GetURL( strFullRouterUrl, "", True, 80 )

    if strBuffer = "" then
    ' If page was empty, set Status to OFF as a flag
    hs.SetDeviceStatus strIpDevice, cStatusOff
    else
    strBuffer = hs.StringItem( strBuffer, 3, "IP Address:" )

    ' Get the WAN IP address
    strWanIp = hs.StringItem( strBuffer, 1, ";" )

    hs.SetDeviceStatus strIpDevice, cStatusOn
    hs.SetDeviceString strIpDevice, strWanIp
    FtpIpWebPage( strWanIp )
    end if

    End Sub

    Sub FtpIpWebPage( strIp )
    Dim strPage

    strpage = "<HTML><BR>WAN IP Address: " + strWanIP + "<BR><BR>" _
    + "<A HREF=""http://" + strIp + ":" + strHomeSeerWebPort + "/" _
    + """>Connect to HomeSeer</A></HTML>"
    FtpText strPage
    End Sub

    Sub FtpText( strText )
    Dim Folder
    Dim TextStream
    Dim strReturn

    Set Folder = CreateObject( "Scripting.FileSystemObject" )
    Set TextStream = Folder.CreateTextFile( strFtpLocalFile, True )

    TextStream.Write strText
    TextStream.Close

    strReturn = hs.ftp( strFtpHost, _
    strFtpUser, _
    strFtpPassword, _
    "PUT", _
    "", _
    strFtpLocalFile, _
    strFtpRemoteFile )

    if strReturn <> "" then hs.WriteLog "FTP IP Error", strReturn
    End Sub

    [This message was edited by Alfonso on Wed, 13 August 2003 at 05:09 PM.]

    [This message was edited by Alfonso on Wed, 13 August 2003 at 05:11 PM.]
    Attached Files
Working...
X