Announcement

Collapse
No announcement yet.

vb script to read/parse file for Raspberry Pi/HS3

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

    vb script to read/parse file for Raspberry Pi/HS3

    I'm attempting to write a script for my RPi2/HS3 system to read a two-line csv file from Weather Display, grab the second line, and parse out the values.

    The code below is one of many I've tried - this has thrown the fewest errors. lol

    The errors I'm getting are:

    Compiling script /home/pi/HomeSeer/scripts/HS3weatherdisplay.vb: Cannot convert from 'String' to 'System.String[]'.

    Jul-20 10:59:07 AM Error Compiling script /home/pi/HomeSeer/scripts/HS3weatherdisplay.vb: The import 'System.Core' could not be found.

    Would anybody be willing to help me through this?

    Code:
    Imports System.IO
    
    Sub Main(ByVal Parm As Object)
    
    Dim SplitStr() As String
    Dim Counter As String = System.IO.File.ReadAllLines("././././mnt/logfiles/scriptlog.txt") (1)
    
    SplitStr = Counter
    SplitStr = Split(Parm, ",")
    
    hs.writelog("0", SplitStr(0)) 'year
    hs.writelog("1", SplitStr(1)) 'month
    hs.writelog("2", SplitStr(2)) 'day
    hs.writelog("3", SplitStr(3)) 'hour
    hs.writelog("4", SplitStr(4)) 'minute
    hs.writelog("5", SplitStr(5)) 'wind
    hs.writelog("6", SplitStr(6)) 'gust
    
    
    End sub
    P.S. I know that Jon00 offers a script to do just this (with the clientraw file) but I'm not able to get his script to work on my system. I also figured this would give me an opportunity to learn some new skills as I continue to move my HS2 system to HS3.

    #2
    What happens with this;

    Code:
    Imports System.IO
    
    Sub Main(ByVal Parm As Object)
    
    Dim SplitLine() As String = System.IO.File.ReadAllLines("././././mnt/logfiles/scriptlog.txt")
    
    Dim SplitChars() As String = SplitLine(1).Split(",")
    
    hs.writelog("0", SplitChars(0)) 'year
    hs.writelog("1", SplitChars(1)) 'month
    hs.writelog("2", SplitChars(2)) 'day
    hs.writelog("3", SplitChars(3)) 'hour
    hs.writelog("4", SplitChars(4)) 'minute
    hs.writelog("5", SplitChars(5)) 'wind
    hs.writelog("6", SplitChars(6)) 'gust
    
    
    End sub
    Without knowing the file structure these can be difficult sometimes, if that does not work are you able to post an example of the text file...

    Comment


      #3
      Thanks a lot for your help. Unfortunately, that didn't work either. The errors are posted below:

      Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: Split (System.String[], System.Int32, System.StringSplitOptions)
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: Split (System.String[], System.StringSplitOptions)
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: Split (System.Char[], System.Int32, System.StringSplitOptions)
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: Split (System.Char[], System.StringSplitOptions)
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: Split (System.Char[], System.Int32)
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: Split (ParamArray System.Char[])
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: '(System.String)' of 6 initial candidates
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: After removing narrowing (except object) candidates for method 'Split', nothing was found
      Jul-20 11:22:08 AM Error Compiling script /home/pi/HomeSeer/scripts/happyWeather.vb: The import 'System.Core' could not be found.

      One thing I'm noticing, both with my attempted script, your revision, and Jon00's script, I'm seeing the same initial error: The import 'System.Core' could not be found. I'm really starting to suspect I have a different issue that's affecting these scripts.

      This is a "homemade" system - not one that I bought from HST. I had the Rpi2 and I had an HS3 license, so I followed some instructions in a thread on here. I'm wondering if I missed an important step along the way. :-)

      Attached is the data file I'm trying to read/parse.

      Thank you!!

      Brian
      Attached Files

      Comment


        #4
        Mono is not my strong point certainly because there are occasional nuances with the way it looks for stuff compared with windows, something this common that should not happen though. You can try adding Imports System.Core to the top of the script before/after Imports System.IO

        It could also be that one of the VB Mono libraries are missing but I would have thought that you would not be able to run any script if that was missing - do any other scripts work OK? Even simple stuff like the startup script.

        Comment


          #5
          I added the Imports System.Core to the beginning of the text. Now I get two errors about not being able to find it. Oops! :-) Forgive my ignorance - is it as "simple" as finding a dll file and moving it into the root HS3 directory, or am I way off base?

          I am able to run other basic scripts just fine. I've ported over five or so scripts from my HS2 system and they run fine. It's beginning to seem like any script that needs to do file system work fails for me and produces this error.

          Comment


            #6
            I went ahead and copied the system.core.dll file to the HS3 directory but it didn't help.

            Comment


              #7
              Does a very simple script like this work, this should just print true to the HS log but it at least checks that the file exists.

              Code:
               Sub Main(parm as object)
              
              hs.writelog("",System.IO.File.Exists(hs.getapppath & "/HSConsole.exe"))
              
              End Sub

              Comment


                #8
                I ran into the same problem on the Zee 2. I was trying to compile a script that changes the led colors on a sensor. The script works fine on a Windows computer but I was never able to solve the System.Core issue on the RPi2. I researched for days about Mono and support .dlls and I requested help on this forum, but no luck. I even sent Rich an email but no answer. The script was for "others" and I did not continue to pursue the issue. If you find a solution, please post.

                Bob

                Comment


                  #9
                  It must be either a libraries issue or a directory issue, I have put the scriptlog.txt file in my HS root directory and run this which has put the right values in the HS log. Perhaps something for you to try...

                  Code:
                  Sub Main(ByVal Parm As Object)
                  
                  Dim SplitLine() As String = System.IO.File.ReadAllLines(hs.getapppath & "/scriptlog.txt")
                  
                  Dim SplitChars() As String = SplitLine(1).Split(",")
                  
                  hs.writelog("0", SplitChars(0)) 'year
                  hs.writelog("1", SplitChars(1)) 'month
                  hs.writelog("2", SplitChars(2)) 'day
                  hs.writelog("3", SplitChars(3)) 'hour
                  hs.writelog("4", SplitChars(4)) 'minute
                  hs.writelog("5", SplitChars(5)) 'wind
                  hs.writelog("6", SplitChars(6)) 'gust
                  
                  
                  End sub
                  Last edited by mrhappy; August 2, 2015, 04:51 AM.

                  Comment


                    #10
                    Originally posted by mrhappy View Post
                    Does a very simple script like this work, this should just print true to the HS log but it at least checks that the file exists.

                    Code:
                     Sub Main(parm as object)
                    
                    hs.writelog("",System.IO.File.Exists(hs.getapppath & "/HSConsole.exe"))
                    
                    End Sub


                    I just ran the script and it prints "True" to the log.

                    Comment


                      #11
                      Dang, I just knew it was going to work, but alas, not so much.

                      Please know I very much appreciate all your efforts here.
                      Attached Files

                      Comment


                        #12
                        I'm probably reaching the limits of my Linux knowledge really - the file system is a complete mystery to me at the best of times, have you tried putting the test file in the HS root directory like my example just to rule out any permissions type issues? If the file is in the same place and it is still giving that error then I am guessing but I wonder if there are some parts of Mono missing - unfortunately I would be guessing at what bits really. If you are still trying to point at some remote directory then perhaps some sort of permissions need to be set but I don't know about that at all.

                        Comment


                          #13
                          Yeah, I'm sorry - I should've mentioned that in my previous post. I did place the scriptlog.txt file in the root HS directory. I can't thank you enough for trying to help me through this. I'll keep searching forums/wikis/etc in hopes of turning up something.

                          Thank you again!!

                          Brian

                          Comment


                            #14
                            So I don't really know what I'm doing other than trying this and that. I thought I'd post what I've run across:

                            I replaced the system.core.dll file that was in my HomeSeer directory with the version 3.5 file. When I started up HS again, the Sonos plugin couldn't initialize and started throwing errors like crazy:

                            Missing method System.Linq.Enumerable::Where<[1]>(IEnumerble'1<!!0>,Func`2<!!0, bool>) in assembly /home/pi/HomeSeer/System.Core.dll, reference in assembly /home/pi/HomeSeer/HSPI_Sonos.exe

                            This was repeated in my log over and over.

                            That's all for now.

                            Comment


                              #15
                              Maybe a step closer?

                              So I ran across this thread that Rob Mason created a couple of years ago:

                              Code:
                              Imports System.IO 
                              
                              ''ZeeTemperature.vb - Rob Mason - 10/23/2013 - Free to use/modify. 
                              
                              Sub Main(parm as object) 
                                 dim FTemp,CTemp as Double 
                                 dim lin as String 
                                 dim sr as StreamReader 
                                 dim dref as Integer = 671     'use your own device reference 
                              
                                 Try 
                                    sr = new StreamReader("/sys/class/thermal/thermal_zone0/temp") 
                                    lin=sr.ReadLine() 
                              
                                    CTemp = CDbl(lin)/1000.0 
                                    FTemp = getFarenheit(CTemp) 
                              ''hs.WriteLog("ZeeTemperature","lin=" & lin & "-- CTemp=" & CTemp & "  FTemp=" & FTemp) 
                              
                              ''update device here - use CTemp or FTemp as needed 
                                    hs.SetDeviceValueByRef(dref, FTemp, True) 
                                    hs.SetDeviceString(dref, "Current Temp: " & FTemp.ToString("0.#") & "&deg F", True) 
                              
                                 Catch ex as Exception 
                                    hs.WriteLog("ZeeTemperature",ex.Message) 
                                 Finally 
                                    if(not sr is Nothing) then sr.close() 
                                 End Try 
                              End Sub 
                              
                              Public Function getFarenheit(ByVal c as Double) as Double 
                                 dim d as Double 
                                 d = c*9/5+32 
                                 return d 
                              End Function
                              This works for me - I'm going to see if I can convert it over to parse my scriptlog file.

                              Fingers crossed!

                              Brian

                              Comment

                              Working...
                              X