Announcement

Collapse
No announcement yet.

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

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

  • bpm32
    replied
    Success!

    Holy cow, I got it working!

    I had to go a different route, but it works! This is a heavily modified version of Rob Mason's example. I'm sure there are ways to make what I've done much more efficient, but I'm happy with it for now! I never did figure out why the other method wouldn't work, so Bob, I'm hoping this has helped you in some way at least.


    Code:
    Imports System.IO 
    
    ''Heavily modified from Rob Mason's ZeeTemperature.vb - Thanks Rob!
    ''ZeeTemperature.vb - Rob Mason - 10/23/2013 - Free to use/modify. 
    
    Sub Main(parm as object) 
    
       dim sr as StreamReader 
       dim wxdata as String 
       dim lin as String 
       dim SplitStr() As String
       
       Try 
    	sr = new StreamReader("/mnt/wxlogs/scriptlog.txt") 'directed to my weather server
    
    	wxdata = sr.ReadToEnd	'read the entire file (it's only two lines)
    	lin = Split(wxdata, VBCrLf)(1) 'read the second line of text
    
    	SplitStr = Split(lin, ",") 'grab each value between the commas
    
    	hs.writelog("Year", SplitStr(0)) '1st value
    	hs.writelog("Month", SplitStr(1)) '2nd value
    	hs.writelog("Day", SplitStr(2)) '3rd value
    	hs.writelog("Hour", SplitStr(3)) '4th value
    	hs.writelog("Minute", SplitStr(4)) '5th value
    	hs.writelog("Wind", SplitStr(5)) '6th value
    	hs.writelog("Gust", SplitStr(6)) '7th value
    	'etc 
    	'these values can now be assigned to virtual devices
    
       Catch ex as Exception 
          hs.WriteLog("WD",ex.Message) 
       Finally 
          if(not sr is Nothing) then sr.close() 
       End Try 
    End Sub

    Leave a comment:


  • bpm32
    replied
    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

    Leave a comment:


  • bpm32
    replied
    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.

    Leave a comment:


  • bpm32
    replied
    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

    Leave a comment:


  • mrhappy
    replied
    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.

    Leave a comment:


  • bpm32
    replied
    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

    Leave a comment:


  • bpm32
    replied
    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.

    Leave a comment:


  • mrhappy
    replied
    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.

    Leave a comment:


  • Bob_Linux_User
    replied
    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

    Leave a comment:


  • mrhappy
    replied
    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

    Leave a comment:


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

    Leave a comment:


  • bpm32
    replied
    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.

    Leave a comment:


  • mrhappy
    replied
    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.

    Leave a comment:


  • bpm32
    replied
    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

    Leave a comment:


  • mrhappy
    replied
    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...

    Leave a comment:

Working...
X