HTTP Get to local device

Hello – I have built an app that interfaces with the Rainwise IP-100. The IP-100 is a net device that gets data from my rainwise weather station and posts that information to thier rainwise.net site. I can access this data directly from the site or direclty from the IP-100. In either case I get to the data via an IP address.
If I am on my local net at home, I use the IP address of the rainwise device – 192.168.0.252/status.xml …
If I am away from home I use the rainwise.net address – https://rainwise.net/data/mystationmac

I use httpsocket.get(ipaddress) to get the data. This works perfect for the mac version, both for the local lan and the rainwise.net.

On windows this approach does not work when I am on the local lan. I can put the address in a browser and get the info. This is what I expect:

1065 2014/05/08 11:10:58 7.3 0090C2EA0CEE 192.168.0.252 255.255.255.0 192.168.0.200 1 English mph 68.2 68.3 56.1 78 98 78 30.19 30.19 30.11 0.00 1.0 360 2.0 360 75.0 77.0 74.0 699 3965338 5.6 5.6

Here is the code where I call the httpsocket.get function (in my case it is tcpsocket1 (the super is HTTPSocket)). It is in a sub called webwake:

statusxml = SpecialFolder.Documents.child("jpweather").child("statusnet.xml")  // not really needed at this point
  
TCPSocket1.Get(TextFieldIP)  // textfieldIP is input on a configuration page

Here is the code in the TCPSocket PageReceived:

  Dim t As TextOutputStream
  
  statusxml = SpecialFolder.Documents.child("jpweather").child("statusnet.xml")
  
  content = content.DefineEncoding(Encodings.UTF8)
  
  TextArea1.Text = content
  
  t = TextOutputStream.create(statusxml)
  t.Write(TextArea1.Text)     // used to confirm data is there when troubleshooting
  t.Close
  
  If statusxml.Length <= 1450 then    
    statusxml.Delete
   else
    If statusxml.Length > 1450 then
      Parsexml
      If val(dataArray(1)) > 0 then
        Webdata
      else
      end
      else
    end
  end

This works perfect for Mac and works on windows going to the raniwise.net site. Going direct to the ranwise device on the local lan does not work on windows.

Any hints would be greatly appreciated.

Thanks
JP

I forgot to mention that when I try to connect locally to the rainwise IP-100 device on windows I get no data at all. Not even a hint of what is going on. On the mac when connecting locally the data comes right in. I first thought this might be a firewall issue on windows, but turning off the firewall did not solve the problem. Also, I can put the address in a browser and connect just fine to the rainwise IP-100. I’m sure it is something simple …

JP

Can’t help with the windows problem, BUT.

I have a Mac only application that get information from a modem. As best I can remember I was having problems with the HTTPSocket get and the PageReceived event. So I made a window with an HTML viewer and used that to make sure I could get the data from the modem to look at. I ended up using the following code:

[quote] Dim http As new HTTPSocket
Dim Data,s,fap As String
http.Yield=true
’ get the fap info from the Hughes Modem
Data = http.Get( “192.168.0.1/fap_meter/” ,5)
http.Close

TextArea1.text = Data
Window1.HTMLViewer1.LoadURL “Http://192.168.0.1/fap_meter/
Window1.show[/quote]

Good luck.

JIm – interesting tip. It comes right into an HTML Viewer, but not the text area. OK – at least I know I am getting into the rainwise device just fine. I may have to do something special for the windows version. Appreciate the idea.

JP

Hmmm – I can’t figure it out, but how do I save the HTMLViewer content to a file?

JP

And while I’m at it I don’t understand why the http.get does not work in windows, but the html viewer does …

request headers ?
that’d be one very basic difference

maybe your http.get needs to set a user agent on windows

Thanks Norman – I’m not sure what to do with user agent on windows. Do you have a pointer?

JP

what web browser does it work in on windows ?
the find that user agent string - there’s a web site that lists them http://www.useragentstring.com
go there with the browser that works on windows & copy the user agent string
then try your code after adding in something like

TCPSocket.SetRequestHeader(“User-Agent:”, “PUT THE STRING FROM USER AGENT STRING.COM HERE”
TCPSocket1.Get(TextFieldIP) // textfieldIP is input on a configuration page

Thanks Norman – I’ll give that a try tomorrow and let you know.

JP

Thanks for the tip Norman. It did not work. I use firefox on windows. So I put in the string displayed from useragentstring.com using firefox. I even used the string displayed from useragentstring.com using the xojo htmlviewer. That did not work either.

JP

Have another application that has a PageReceived event after a Post using a HTTPSocket. Your code, below, have you tried it with the first line shown removed? I do not use any thing like that. I did a test using Windows 7 running on Mac using VM and it works ok.

Thanks Jim – I needed the define encoding to solve some xml format issues. I only use the TextArea1.text as a means to verify data is coming in – which it does on the mac. Removing the first line does not help, as I jsut tried it again to be sure.

Just did a little more testing on windows. It appears that I am connecting to the rainwise device with tcpsocket1.get however I am not getting anything in the tcpsocket1.PageReceived.

A little frustrating. I wish I could figure out how to save the page from the HTMLViewer … at least that comes in on Windows …

Well – I figured out a way to work it. It is ugly, but it is working. I am capturing the data via the tcpsocket1.ReceiveProgress event. So I let that happen, then let the tcpsocket1.PageReceived event take it from there. Of course I had to make sure it was for windows only and some choices for serial vs IP connections, but it is working. The code:

TCPSocket1.ReceiveProgress:

  #If TargetMacOS=True then
    
  #Else
    If ConnectionState = "IP" then
      TextArea1.Text = TextArea1.Text + TCPSocket1.ReadAll
    else
      
    end
  #Endif

and the relevant TCPSpocket1.PageeReceived code:

  Dim t As TextOutputStream
  
  statusxml = SpecialFolder.Documents.Child("jpweather").child("statuswgt.xml")
  
  #If TargetMacOS=True then
    content = content.DefineEncoding(Encodings.UTF8)
    
    TextArea1.Text = content
  #Else
    
    If ConnectionState = "Serial" then
      
      content = content.DefineEncoding(Encodings.UTF8)
      
      TextArea1.Text = content
    Else
    end
    
  #Endif
  
  t = TextOutputStream.create(statusxml)
  t.Write(TextArea1.Text)
  t.Close

  If statusxml.Length <= 1450 then
    statusxml.Delete
    'xcount = xcount + 1
    'TextField6.Text = str(xcount)
  else
    If statusxml.Length > 1450 then
      
      Parsexml
      
      If val(dataArray(1)) > 0 then
        Webdata
      else
      end
      
    else
    end
  end
  
  TextArea1.Text = ""