From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Access PHP-website using Labview 8

Solved!
Go to solution

Hi folks,

 

I'm trying to write a LV8 vi to grab some data from a website. The first website I played with just had text output so a simple:

 - OpenTCPConnection (to "www.hpc.ncep.noaa.gov")

 - WriteTCP:

 - line 1: "GET /heat_index_MEAN/hitable_east.txt" <CR><LF>

- line 2: "Host: www.hpc.ncep.noaa.gov<CR><LF>

- line 3: <CR><LF>

 - ReadTCP

This worked perfectly fine.

 

But, that's not really the data that I want. I want the data that shows up on the website:

http://forecast.weather.gov/MapClick.php?w0=t&w1=td&w2=hi&w3=sfcwind&w3u=1&w4=sky&w5=pop&w6=rh&w7=th...96&textField2=-77.48167&site=all&unit=0&dd=0&bw=0 

 

But, when I try the same calls I get error messages like:

HTTP/1.0 400 Bad Request Server: AkamaiGHost Mime-Version: 1.0 Content-Type: text/html Content-Length: 216 Expires: Sun, 12 Aug 2012 17:40:25 GMT Date: Sun, 12 Aug 2012 17:40:25 GMT Connection: close <HTML><HEAD> <TITLE>Bad Request</TITLE> </HEAD><BODY> <H1>Bad Request</H1> Your browser sent a request that this server could not understand.<P> Reference&#32;&#35;7&#46;9f931160&#46;1344793225&#46;0 </BODY> </HTML>

 

I don't know enough about HTML or PHP to tell if I have an HTML or PHP problem; and what I have to figure out to proceed. Specifically:

 - can you tell if this is a PHP or HTML problem in my code?

 - if so, which?

 - can I access a website (that uses PHP) from Labview?

 - do I have to learn more about PHP to proceed?

 - I tried sending an HTML "OPTIONS" command, but I got very similar eror messages (not a quesstion)

 - the website has an XML option that displays data in XML/text, but it seems to also use PHP access, so I get the same errors with my code (not a question)

 - any ideas on how to use labview to read the data from this website?

 

thanks, in advance...

0 Kudos
Message 1 of 15
(5,191 Views)

PHP is server side so there shouldn't be any need to learn PHP for what you want to do.

The main thing is getting the arguments to work (the ?blah=sdfs&blah2=sds bit).

I can't access my labview install right now, but when I can I'll try and find a way to get it going.

0 Kudos
Message 2 of 15
(5,180 Views)

You don't see the PHP code.

What you see when you go to a website running PHP scripts is the HTML code.

 

0 Kudos
Message 3 of 15
(5,175 Views)

Thanks H.R and nyc,

 

So, I figured out that with HTML I needed to send a "GET" command in order to read/retrieve the .txt file (which worked fine). I was thinking that the URL in my browser contained the fully formed command to the PHP server (all of the arguments). But I'm guessing that you don't proceed the "/MapClick.php" with the same "GET". I'm thinking that I need to get to the PHP server somehow (probably not a "GET", and somehow tell the PHP server to MapClick.php&blah/blah/blah... am I looking at this right?

0 Kudos
Message 4 of 15
(5,173 Views)

I'm trying to paste the full URL (to the website data that I want) into this reply (it didn't work in my original post... it got cut/split)... let's see if this works:

 

http://forecast.weather.gov/MapClick.php?w0=t&w1=td&w2=hi&w3=sfcwind&w3u=1&w4=sky&w5=pop&w6=rh&w7=th...

 

0 Kudos
Message 5 of 15
(5,171 Views)

Hi,

 

What specific data are you trying to pull from that website?  One way that I have grabbed data in the past and may work for you is to use an HTTP get on the URL you posted and then parse through the data in LabVIEW.  The website you posted does not have a lot of text on the page source so that parsing should not be very resource heavy.

 

Regards,

 

Greg H. 

Applications Engineer
National Instruments
0 Kudos
Message 6 of 15
(5,143 Views)

Hi Greg,

 

Thanks for the reply. I'm trying to get the tabular weather data that is displayed at that web site. Your suggestion of the "get" is (I think) exactly what I tried (but from labview), but I got nothing but errors back from the website. Here is the specific commands I sent to the TCP OPEN/WRITE/READs (remember, I'm using LV8):

 

OpenTCP: ("forecast.weather.gov"), port 80

WriteTCP:

 - line 1: "GET /MapClick.php?w0=t&w1=td&w2=hi&w3=sfcwind&w3u=1&w4=sky&w5=pop&w6=rh&w7=thunder&w8=rain&AheadHour=0&Submit=Submit&FcstType=digital&textField1=39.04796&textField2=-77.48167&site=all&unit=0&dd=0&bw=0

 - line 2: "Host: forecast.weather.gov"<CR><LF>

 - line 3: <CR><LF>

ReadTCP

 

I get the following response from the website:

HTTP/1.0 400 Bad Request Server: AkamaiGHost Mime-Version: 1.0 Content-Type: text/html Content-Length: 216 Expires: Mon, 13 Aug 2012 01:55:10 GMT Date: Mon, 13 Aug 2012 01:55:10 GMT Connection: close <HTML><HEAD> <TITLE>Bad Request</TITLE> </HEAD><BODY> <H1>Bad Request</H1> Your browser sent a request that this server could not understand.<P> Reference&#32;&#35;7&#46;94f64317&#46;1344822910&#46;0 </BODY> </HTML>

 

Were you able to get some actual data back from the website?

0 Kudos
Message 7 of 15
(5,140 Views)

Hi,

 

The website appears to be down currently.  I will continue looking into this when the website is back up.

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
0 Kudos
Message 8 of 15
(5,128 Views)

Oh, Bummer... you're right.... first time I've seen it down over the past three days... what timing! Thanks for pursuing this Greg.

 

I've been studying and trying different things also... no luck yet:

 - I turned on my browser (Chrome) "developer" view option to see if I could find out what the browser is sending. I can't see the exact syntax or message traffic. But it seems like it is sending a HTTP GET command and getting "MapCLick.php" back. And it looks like the contents of MapClick.php has XML code which I'm sure I could decipher (and has all of the data that I want). But, I still can't get LV8 (btw: on Mac OSX 10.6.8) to return anything but the error msg from the web site. I'm also a bit puzzled by this because I would have thought that a ".php" file was probably a PHP source code file (again, I've never played with PHP, so I might be looking at this wrong).

 

 - I see that the National Weather Service (NWS) has a Web Services (SOAP) means of accessing their data. But, I haven't gotten this to work yet either. And, it doesn't look like this is really giving me the same data that MapClick.php is providing.

 

 - LV2011 on PC has a Web Services Import WIzzard; and NWS has the definition file. But, LV2011 just reported errors when I tried to import that file (right now, I'd rather not use this approach anyway, unless I REALLY have to... and I don't want to use PC unless I REALLY have to).

0 Kudos
Message 9 of 15
(5,124 Views)

Hi,

 

Well if you did use the PC with LV2011, I think it would be much simpler.  You could use the HTTP Get to pull in all of the data from the website and then parse the data to extract the information you want.  Please see my attached VI for a reference.

 

I will continue to look into the issue with TCP commands (not using the http get function).

 

Regards,

 

Greg H.

Applications Engineer
National Instruments
Message 10 of 15
(5,110 Views)