Announcement

Collapse
No announcement yet.

Script errors after conversion from Windows to Linux

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

    Script errors after conversion from Windows to Linux

    Hello all,

    I have been trying to figure this out for a while but I cannot get any further. After moving a working script from Windows to Linux i'm getting all sorts of errors. I read through the forum and was able to fix some of the common errors (implicit declarations etc) but i'm still stuck with these errors and I have no clue what they mean
    Apr-13 9:21:53 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: CHANGEME
    Apr-13 9:21:53 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: 42021
    Apr-13 9:21:53 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: 42021
    Apr-13 9:21:53 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: The import 'System.Core' could not be found.
    My script reads some data from a furnace and creates a HTML email with some status information. The same code is used in another script to update HS objects but I haven't yet had the time to go and fix that script (similar errors). I believe the errors are caused by the return values from the functions (I marked the error point with **HERE** below) as even if I comment out all lines in the function Geo_Read i still get the same errors. Can anyone spot what I am missing?



    ------SCRIPT------
    Sub Main(ByVal parm As String)


    Dim x As Double
    Dim Geo1 As String
    Dim Geo2 As String
    ' Dim Geo1(100) As String
    ' Dim Geo2(100) As String
    Dim Geo_Error(100) As String

    Geo_Error(1)="E1 - Input Error"
    Geo_Error(2)="E2 - High Pressure"
    Geo_Error(3)="E3 - Low Pressure"
    Geo_Error(4)="E4 - Frze Detect FP2"
    Geo_Error(5)="E5 - Frze Detect FP1"
    Geo_Error(7)="E7 - Condensate"
    Geo_Error(8)="E8 - O/U Voltage"
    Geo_Error(11)="E11 - FP1/2 Snr Err"
    Geo_Error(13)="E13 - NCritAxbSnrErr"
    Geo_Error(15)="E15 - Hot Water Limit"
    Geo_Error(16)="E16 - VS Pump Error"
    Geo_Error(18)="E18 - NCritComm Error"
    Geo_Error(19)="E19 - Crit Comm Error"
    Geo_Error(21)="E21 - Low Loop Press"
    Geo_Error(23)="E23 - HAGeneralAlarm"
    Geo_Error(24)="E24 - HAGeneralAlarm"
    Geo_Error(41)="E41 - Hi Drive Temp"
    Geo_Error(42)="E42 - Hi Dischrg Temp"
    Geo_Error(43)="E43 - Lo Suct Press"
    Geo_Error(44)="E44 - Lo Cond Press"
    Geo_Error(45)="E45 - Hi Cond Press"
    Geo_Error(46)="E46 - Output Pwr Lmt"
    Geo_Error(47)="E47 - EEV ID Comm Err"
    Geo_Error(48)="E48 - EEV OD Comm Err"
    Geo_Error(49)="E49 - Cabinet Tmp Snr"
    Geo_Error(51)="E51 - Dischrg Tmp Snr"
    Geo_Error(52)="E52 - Suct Press Snr"
    Geo_Error(53)="E53 - Cond Press Snr"
    Geo_Error(54)="E54 - Lo Supply Volt"
    Geo_Error(55)="E55 - Out of Envelope"
    Geo_Error(56)="E56 - Drv Over Current"
    Geo_Error(57)="E57 - Drive O/U Volt"
    Geo_Error(58)="E58 - Hi Drive Temp"
    Geo_Error(59)="E59 - Int Drive Error"
    Geo_Error(61)="E61 - Multiple SafeMd"
    Geo_Error(71)="E71 - Loss of Charge"
    Geo_Error(72)="E72 - Suct Temp Snr"
    Geo_Error(73)="E73 - LvgAir Temp Snr"
    Geo_Error(74)="E74 - Max Op Pressure"
    Geo_Error(99)="E99"



    **HERE** Geo1 = Geo_Read("IP_ADDR1")
    **HERE** Geo2 = Geo_Read("IP_ADDR2")

    Dim objReader As System.IO.StreamWriter
    Dim FullPath as String = hs.getapppath & "/scripts/wf-errors.html"
    objReader = New System.IO.StreamWriter(FullPath)


    objReader.Write("<head><meta http-equiv="&chr(34)&"refresh"&chr(34)& " content="&chr(34)&"180"&chr(34)&"></head>")
    objReader.Write("<body bgcolor="&chr(34)&"#0000e6"&chr(34)&">")
    objReader.Write("<table border=" & chr(34) &"1" & chr(34) & " style=" & chr(34) & "color:white" & chr(34) & "><tr><td>Error Name</td><td>Unit1</td><td>Unit2</td><tr>")
    for x = 0 to Ubound(Geo1)-1
    if(Geo1(x)<>"65535") Then
    objReader.Write("<tr><td>")
    objReader.Write(Geo_Error(x+1))
    objReader.Write("</td><td>")
    objReader.Write(Geo1(x))
    objReader.Write("</td><td>")
    objReader.Write(Geo2(x))
    objReader.Write("</td></tr>")
    End If
    Next

    Dim lastreset As String
    lastreset = My.Computer.FileSystem.ReadAllText(hs.getapppath & "/scripts/wf-errors-reset.html")

    objReader.Write("</tr><tr><td colspan=" & chr(34) & "5" & chr(34) & ">" & "Last Update: " & Now & "</td></tr></td></tr>")
    objReader.Write("</tr><tr><td colspan=" & chr(34) & "5" & chr(34) & ">" & "Last Reset: " & lastreset & "</td></tr></td></tr>")
    objReader.Write("</table></font>")

    objReader.Close()

    hs.writelog("Info","Unit1: " & Geo1(7))
    hs.writelog("Info","Unit2: " & Geo2(7))

    Send_results()

    End Sub

    Function Send_results()

    Dim fileReader As String
    fileReader = My.Computer.FileSystem.ReadAllText(hs.getapppath & "/scripts/wf-errors.html")
    ' filereader = "This is a string from VWS: " & filereader
    ' hs.writelog("Email Send", filereader)
    hs.sendemail("myemail", "fromemail", "", "", "WaterFurnace Errors", filereader, "")
    End Function



    Function Geo_Read(ip As String)

    Dim strBody, strWork, URLpath As String
    Dim x,y As Double
    Dim strSplit() As String

    URLpath="/request.cgi?cmd=getregs&id=4&set=1&addr=2&regs=601,99;"

    strBody = hs.GetURLEx("http://" & ip, URLpath, "", "80", "TRUE", "FALSE", "")
    hs.writelog("Info", ip & ": " & strBody)
    y = Instr(1,strBody,"Unauthorized",1)

    if (y=0) then
    x = Instr(1,strBody,"values=",1)
    strWork = Mid(strBody,x+7)
    strSplit = Split(strWork, ",")
    Geo_Read=strSplit

    Else
    hs.writelog("Info","Unit2: Not Authorized")
    strBody = hs.GetURLEx("http://" & ip,"/request.cgi?cmd=auth&id=1&set=1&addr=247&passcode=1234", "", "80", "TRUE", "FALSE", "")
    Geo_Read="0"
    End If



    End Function

    #2
    Your Geo_read function is returning an array in some cases. I have found that mono-vbnc has a hard time with some aspects of array handling.

    See https://forums.homeseer.com/forum/de...bnc-deprecated

    Unfortunately, while mono-vbnc is deprecated, the scripting mechanism that HS uses hasn't been updated by the mono developers to use the more modern vbc compiler.

    A possible workaround is to patch mono to call vbc instead of vbnc. Here's how to do that from the Linux command line

    Code:
    sudo mv /usr/bin/vbnc /usr/bin/vbnc-orig
    sudo cp -a /usr/bin/vbc /usr/bin/vbnc

    Comment


      #3
      OK I made the changes you suggested but now I get different errors. Any thoughts?
      Apr-14 2:21:57 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: Function 'Send_results' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
      Apr-14 2:21:57 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: Value of type 'String' cannot be converted to 'Array'.
      Apr-14 2:21:57 PM Error Compiling script /opt/HomeSeer/scripts/waterfurnace-errors.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

      Comment


        #4
        The 1st & 3rd message are just warnings; the 2nd is a real error. It's because your Geo_Read function returns an array of strings,

        Dim strSplit() As String
        ...
        Geo_Read=strSplit

        But the call expects a simple string

        Dim Geo1 As String
        Dim Geo2 As String
        ...
        **HERE** Geo1 = Geo_Read("IP_ADDR1")
        **HERE** Geo2 = Geo_Read("IP_ADDR2")

        I don't know what the data format looks like, but just guessing you want just the first entry of a comma separated list, change the line

        Geo_Read=strSplit
        to
        Geo_Read=strSplit(0)

        Comment


          #5
          strSplit is an array of values that are pulled from the furnace. Array positions 0-100 have values in that represent the counts of particular errors.

          Within the function Geo_Read I connect to the furnace and then populate the array strSplit. The line Geo_Read=strSplit returns the values in the array back to the array Geo1 or Geo2 which is then used to create a combined report.

          So to answer the question I don't just want strSplit(0) but strSplit(0) to the of the array

          I really appreciate your help here. Any additional thoughts?

          Comment


            #6
            In that case, you'll need to change back the declarations of Geo1 & Geo2

            from

            Dim Geo1 As String
            Dim Geo2 As String
            ' Dim Geo1(100) As String
            ' Dim Geo2(100) As String

            to

            'Dim Geo1 As String
            'Dim Geo2 As String
            Dim Geo1(100) As String
            Dim Geo2(100) As String

            Comment


              #7
              That worked! - Thank you so much. You solved all of my issues!

              Comment


                #8
                Originally posted by zwolfpack View Post
                Your Geo_read function is returning an array in some cases. I have found that mono-vbnc has a hard time with some aspects of array handling.

                See https://forums.homeseer.com/forum/de...bnc-deprecated

                Unfortunately, while mono-vbnc is deprecated, the scripting mechanism that HS uses hasn't been updated by the mono developers to use the more modern vbc compiler.

                A possible workaround is to patch mono to call vbc instead of vbnc. Here's how to do that from the Linux command line

                Code:
                sudo mv /usr/bin/vbnc /usr/bin/vbnc-orig
                sudo cp -a /usr/bin/vbc /usr/bin/vbnc
                I had to rebuild my linux machine and copied over homeseer but now I don't seem to have a /usr/bin/vbc

                # ls /usr/bin/vbc*
                ls: cannot access '/usr/bin/vbc*': No such file or directory

                I have vbnc (and vbnc2)

                # ls /usr/bin/vbnc*
                /usr/bin/vbnc /usr/bin/vbnc2

                Any thoughts? I don't remember doing anyhing special to get /usr/bin/vbc to appear

                Comment


                  #9
                  I seem to remember having to download from the mono project site direct:

                  https://www.mono-project.com/downloa.../#download-lin
                  Jon

                  Comment


                    #10
                    That is actually the version i am using

                    mono-complete is already the newest version (6.8.0.105+dfsg-2)

                    Comment


                      #11
                      Ah - the UBUNTU:LATEST tag seems to have been elevated to focal (20.04). I set back to bionic (18.04) and all is good again.

                      Comment

                      Working...
                      X