Announcement

Collapse
No announcement yet.

Simple webserver scrape script

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

  • manxam
    replied
    If you want a pre-built plugin, try Jon00's Data Scraper.. It's built for this specific reason.

    Leave a comment:


  • will40
    replied
    Thanks Mr. H. I will pick away at it.

    Leave a comment:


  • mrhappy
    replied
    This might be somewhere to start, I've written it very quickly and there is quite probably a much better solution out there. I cant absolutely test it either because I don't have the page available to me.

    A personal suggestion having done similar stuff in the past is that if you have access to the arduino code then just return a line of data separated by a comma, that is much easier to work with than messing around with HTML.

    What I am doing with this is;

    1) Splitting the data (minus the HTML tags) on the basis of 'analog input' which will remove that bit from the string and then return an array of how many of splits it has done.
    2) Run through each row and then split on the space between '3 is 123', '4 is 456' etc. Pick out '3' for sensor 3, pick out 456 for the value.
    3) Set the device value for each device in turn, you would need to change the first parameter to your devices.

    This is not the best because of the lack of error checking but if you can adjust the arduino code as I say you can make it easier for yourself and prevent some problems.

    Code:
    Sub Main(ByVal Parms As Object)
    
        Try
            Dim DataRaw As String = hs.GetURL("192.168.1.64", "/", True, 80)
    
            Dim RowSplit() As String = Split(DataRaw, "analog input")
            Dim LineSplit() As String
    
            hs.writelog("", "Rows: " & RowSplit.GetUpperBound(0))
    
            For i As Byte = 1 To RowSplit.GetUpperBound(0)
    
                hs.writelog("", RowSplit(i))
                LineSplit = Split(RowSplit(i), " ")
    
                For k As Byte = 1 To LineSplit.GetUpperBound(0)
                    hs.writelog("", "--> " & LineSplit(k))
                Next
    
                Select Case LineSplit(0)
                    Case 1 : hs.setdevicevaluebyref(1234, LineSplit(2), True)
                    Case 2 : hs.setdevicevaluebyref(5678, LineSplit(2), True)
                    Case 3 : hs.setdevicevaluebyref(9101, LineSplit(2), True)
                End Select
    
            Next
        Catch ex As Exception : hs.writelog("", "Exception: " & ex.message)
        End Try
    
    End Sub

    Leave a comment:


  • will40
    started a topic Simple webserver scrape script

    Simple webserver scrape script

    I installed an Arduino board with a wifi shield in my detached shed and powered it from stored energy charged by a small solar panel I put on the roof of the shed.

    I would like to monitor temperature, door, and window contacts for starters.

    I used a wifiwebserver sketch and successfully I can poll the webserver at http://192.168.1.64 for the status of a few analog inputs.

    Ideally I would like to parse the data from the inputs into HS3 devices but I don't have a clue how to script and could use your help to point me in the right direction.

    I attached screen shot of the current data received when sketch is refreshed.

    I will eventually edit the sketch as I learn more how to write sketches to gather and possibly control the Arduino.

    Thanks much for any help.
    Attached Files
Working...
X